进程内组件编写需要手动添加的函数:组件注册函数、组件注销函数、类厂对象创建函数、组件生存与否函数
extern "C" HRESULT __stdcall DllGetClassObject(const CLSID& clsid, const IID& iid, void **ppv)
{
if (clsid == CLSID_Dictionary ) {
CDictionaryFactory *pFactory = new CDictionaryFactory;
if (pFactory == NULL) {
return E_OUTOFMEMORY ;
}
HRESULT result = pFactory->QueryInterface(iid, ppv);
return result;
} else {
return CLASS_E_CLASSNOTAVAILABLE;
}
}
extern "C" HRESULT __stdcall DllCanUnloadNow(void)
{
if ((g_DictionaryNumber == 0) && (g_LockNumber == 0))
return S_OK;
else
return S_FALSE;
}
//
// Server registration
//
extern "C" HRESULT __stdcall DllRegisterServer()
{
char szModule[1024];
DWORD dwResult = ::GetModuleFileName((HMODULE)g_hModule, szModule, 1024);
if (dwResult == 0)
return SELFREG_E_CLASS;
return RegisterServer(CLSID_Dictionary,
szModule,
"Dictionary.Object",
"Dictionary Component",
NULL);
}
//
// Server unregistration
//
extern "C" HRESULT __stdcall DllUnregisterServer()
{
return UnregisterServer(CLSID_Dictionary,
"Dictionary.Object",NULL);
}