I'm having some trouble creating a COM DLL. My IClassFactory-implementation looks like the following:
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 say "error C2143: syntax error : missing ';' before '__stdcall" on line 6 (and some more lines). I already googled, I figured out that I've to include windows.h. But this doesn't solve my issue... anyone know what's wrong with my code or what I've to include to solve the problem? I'm getting the same error by 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.
You must put
;
after every class and structure because they are objects likeint a;
, not functions.;
is missing from your header.