I am having trouble creating a COM DLL. My implementation of IClassFactory is as follows:
include <windows.h> #include <ObjBase.h> #include "AddObj.h" #include "AddObjFactory.h" HRESULT __stdcall CAddFactory::CreateInstance(IUnknown* pUnknownOuter, const IID& iid, void** ppv) { if (pUnknownOuter) { return CLASS_E_NOAGGREGATION; } CAddObj* pObject = new CAddObj(); if (pObject == NULL) { return E_OUTOFMEMORY; } return pObject->QueryInterface(iid, ppv); } HRESULT __stdcall CAddFactory::LockServer(BOOL bLock) { return E_NOTIMPL; }
My problem is that Visual Studio always says "error C2143: syntax error: missing"; to "__stdcall" on line 6 (and a few more lines). I already googled, I realized that I have to enable windows.h. But this does not solve my problem ... does anyone know what is wrong with my code or what should I include to solve the problem? I get the same error while compiling the header file:
#include <Windows.h> #include <ObjBase.h> class CAddFactory : public IClassFactory { public: HRESULT __stdcall QueryInterface(REFIID riid, void **ppObj); ULONG __stdcall AddRef(); ULONG __stdcall Release(); HRESULT __stdcall CreateInstance(IUnknown* pUnknownOuter, const IID& iid, void** ppv); HRESULT __stdcall LockServer(BOOL bLock); private: long m_nRefCount; }
By the way, the code is based on a tutorial from codeguru.
source share