// COM.cpp : Simple DLL COM server
//
#include "stdafx.h"
#include "dave_idl_i.c"
static long glLockCount = 0; // Lock count
static CDaveClassFactory gDaveClassFactory;
extern "C" {
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
) {
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) {
if (rclsid == CLSID_DaveComponent)
return gDaveClassFactory.QueryInterface(riid, ppv);
else {
*ppv =NULL;
return CLASS_E_CLASSNOTAVAILABLE;
}
}
STDAPI DllCanUnloadNow(void){return (glLockCount == 0) ? S_OK : S_FALSE;}
// ToDo
STDAPI DllRegisterServer(void) {return S_OK;}
STDAPI DllUnregisterServer(void) {return S_OK;}
}
void CommonCount(BOOL fLock) {
if (fLock) InterlockedIncrement(&glLockCount);
else InterlockedDecrement(&glLockCount);
}