0
我想添加一個C++項目到我的c#代碼,我試圖實現IUnknown接口。我不斷收到有關c2259的錯誤:無法實例化抽象類。錯誤c2259從IUnknown實現接口類
我試着玩一些東西,比如讓這個類變成一個類並改變實現,但似乎沒有任何工作。以下是我使用的一些代碼。
我的接口類:
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);
}
任何幫助表示讚賞。
我的類定義是這樣的:
public class RotateWrapper : public IClientWrapper
我看,我沒有實現QueryInterface。這可能是問題(我希望...大聲笑) –
感謝您的幫助Rob! –