我正在尝试实现IUnknown。我严格按照说明进行,但它却不能正常工作。当我尝试编译时,出现以下错误:
Error 2 error C2695: 'testInterfaceImplementation::AddRef': overriding virtual function differs from 'IUnknown::AddRef' only by calling convention c:\users\seanm\desktop\test\test\source.cpp 6 1 test
Error 3 error C2695: 'testInterfaceImplementation::QueryInterface': overriding virtual function differs from 'IUnknown::QueryInterface' only by calling convention c:\users\seanm\desktop\test\test\source.cpp 14 1 test
Error 4 error C2695: 'testInterfaceImplementation::Release': overriding virtual function differs from 'IUnknown::Release' only by calling convention c:\users\seanm\desktop\test\test\source.cpp 22 1 test
从这段代码开始:
#include <Windows.h>
#include <tchar.h>
class testInterfaceImplementation : public IUnknown {
protected:
ULONG AddRef()
{
MessageBox(NULL,
_T("TEST1"),
_T("TEST1"),
NULL);
return 0;
}
HRESULT QueryInterface(IN REFIID riid, OUT void **ppvObject)
{
MessageBox(NULL,
_T("TEST2"),
_T("TEST2"),
NULL);
return S_OK;
}
ULONG Release() {
MessageBox(NULL,
_T("TEST3"),
_T("TEST3"),
NULL);
return 0;
}
};
QI()
实现中返回S_OK
- 像E_FAIL
这样的东西会更好。 - sharptooth