我試圖做一個接口,實現我的類的IUnknown接口使用,但我不斷收到上述錯誤:c2259:無法實例化抽象類。我試圖從IUnknown實現所有3種方法,但唉,我仍然得到錯誤。實現IUnknown接口獲取錯誤c2259:無法實例化抽象類
下面你可以看到我使用的代碼。這個環節是我的主要resource
我的接口類:
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;
};
我的處理程序類:
#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;
}
我的包裝類:
#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;
}
我的類定義是這樣的:
public class RotateWrapper : public IClientWrapper
我一直在這裏呆了太久,需要在這個項目上移動。任何幫助表示讚賞。
編輯1
我Wrapper.h頭
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();
};
好了,我的壞傢伙...我猜視覺工作室2010只吮吸,因爲錯誤的仍然很多。它花了大約2打版本,因爲它意識到我已經添加了所有的實現...大聲笑
感謝大家的幫助!非常感激。
請幫忙!我只是需要一個關於如何更正確地實現IUnknown的簡短例子... –
也許DECLARE_IUNKNOWN會使生活變得更容易一些? (搜索) – jglouie