Error c2259 implementing interface class from IUnknown
I'm trying to add a c++ project to my c# code and I'm trying to implement the IUnknown interface. I keep getting an error about c2259: cannot instantiate abstract class.
I've tried to play with some things like making the class a ref class and changing the implementation but nothing seems to work. Below is some of the code I am using.
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 **pClientWrappe开发者_StackOverflowr)
{
*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);
}
Any help is appreciated.
My class definition goes like this:
public class RotateWrapper : public IClientWrapper
You need to implement the methods inherited from IUnknown
: QueryInterface
, AddRef
, and Release
. Failure to do that means your class still has pure virtual methods, and the compiler is correct to forbid you from instantiating such a class.
精彩评论