开发者

Implementing IUnknown interface getting error c2259: cannot instantiate abstract class

I'm trying to make an interface that implements the IUnknown interface for my classes to use but I keep getting the above error: c2259: cannot instantiate abstract class. I've tried to implement all 3 methods from IUnknown but alas I still get the error.

Below you can see the code I'm using. This link is my main resource

My interface class:

interface __declspec(uuid("c78b266d-b2c0-4e9d-863b-e3f74a721d47"))
IClientWrapper : public IUnknown
{
    public:
        virtual STDMETHODIMP get_CurrentIsReadOnly(bool *pIsReadOnly) = 0;
        virtual STDMETHODIMP get_CachedIsReadOnly(bool *pIsReadOnly) = 0;
};

My handler class:

#include "RotateHandler.h"

RotateHandler::RotateHandler()
{
}

RotateHandler::~RotateHandler()
{
}

STDMETHODIMP RotateHandler::CreateClientWrapper(IUIAutomationPatternInstance *pPatternInstance, IUnknown **pClientWrapper)
{
    *pClientWrapper = new RotateWrapper(pPatternInstance);  //here is error c2259
    if (*pClientWrapper == NULL)
        return E_INVALIDARG;
    return S_OK;
}

STDMETHODIMP RotateHandler::Dispatch(IUnknown *pTarget, UINT index, const struct UIAutomationParameter *pParams, UINT cParams)
{
    switch(index)
    {
        case Rotation_GetIsReadOnly:
            return ((ICustomProvider*)pTarget)->get_IsReadOnly((bool*)pParams[0].pData);
    }
    return E_INVALIDARG;
}

And my wrapper class:

#include "RotateWrapper.h"

RotateWrapper::RotateWrapper()
{
}

RotateWrapper::RotateWrapper(IUIAutomationPatternInstance *pInstance)
    : _pInstance(pInstance)
{
    _pInstance->AddRef();
}

RotateWrapper::~RotateWrapper()
{
    _pInstance->Release();
}

STDMETHODIMP RotateWrapper::get_CurrentIsReadOnly(bool *pIsReadOnly)
{
    return _pInstance->GetProperty(0, false, UIAutomationType_Bool, pIsReadOnly);
}

STDMETHODIMP RotateWrapper::get_CachedIsReadOnly(bool *pIsReadOnly)
{
    return _pInstance->GetProperty(0, true, UIAutomationType_Bool, pIsReadOnly);
}

HRESULT __stdcall RotateWrapper::QueryInterface(const GUID riid, void **ppvObj)//riid == IID_IUIAutomationRegistrar, ppvObj == interface pointer to registrar
{
    HRESULT res;
    return res;
}

ULONG __stdcall RotateWrapper::AddRef()
{
    InterlockedIncrement(&refCount);
    return refCount;
}

ULONG __stdcall RotateWrapper::Release()
{
    ULONG ulRefCount = InterlockedDecrement(&refCount);
    if (ulRefCount == 0)
    {
        delete this;
    }
    return ulRefCount开发者_如何学Go;
}

My class definition goes like this:

public class RotateWrapper : public IClientWrapper

I've been stuck here for too long and need to get moving on this project. Any help is appreciated.

EDIT 1

My Wrapper.h header

public class RotateWrapper : public IClientWrapper
{
    public:
        RotateWrapper();
        RotateWrapper(IUIAutomationPatternInstance *pInstance);
        ~RotateWrapper();

        //IUnknown Interface
        STDMETHODIMP get_CurrentIsReadOnly(bool *pIsReadOnly);
        STDMETHODIMP get_CachedIsReadOnly(bool *pIsReadOnly);
        HRESULT __stdcall QueryInterface(REFIID riid, void **ppvObj);
        ULONG __stdcall AddRef();
        ULONG __stdcall Release();
};

Ok, my bad guys... I guess Visual Studios 2010 just sucks because lots of bugs still. It took about 2 dozens builds for it to realize that I had added all the implementation...lol

Thanks for everyone's help!! Much appreciated.


HRESULT __stdcall RotateWrapper::QueryInterface(const GUID riid, void **ppvObj)

This is not the proper signature for QueryInterface. Hint: REFIID is not the same thing as const GUID.


Ok, my bad guys... I guess Visual Studios 2010 just sucks because lots of bugs still. It took about 2 dozens builds for it to realize that I had added all the implementation...lol

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜