STDAPI DllRegisterServer() { HRESULT hr = S_OK; LPCTSTR prodPrefix = NULL; LPCTSTR compPrefix = NULL; TCHAR szModulePath[MAX_PATH]; COMServer::GetModuleFileName(szModulePath,sizeof(szModulePath)/sizeof(szModulePath[0])); VersionInfo verInfo(szModulePath); prodPrefix = (LPCTSTR)verInfo.GetStringInfo(_T("ProductPrefix")); compPrefix = (LPCTSTR)verInfo.GetStringInfo(_T("ComponentPrefix")); try { Registry registry; RegistryUtil::RegisterComObjectsInTypeLibrary(registry,szModulePath,RegistryUtil::AUTO); if( registry.Prepare() ) registry.Commit(); /* as marker for registration of multiple typelibs RegistryUtil::RegisterTypeLib(LIBID_BVR20983_1_SC,LANG_SYSTEM_DEFAULT,_T("1"),1,0,szModulePath,szWindowsDir); RegistryUtil::RegisterTypeLib(LIBID_BVR20983_1_SC,MAKELCID(MAKELANGID(LANG_GERMAN, SUBLANG_NEUTRAL), SORT_DEFAULT),_T("2"),1,0,szModulePath,szWindowsDir); */ } catch(BVR20983Exception e) { LOGGER_ERROR<<e<<endl; hr = SELFREG_E_CLASS; } catch(exception& e) { LOGGER_ERROR<<"Exception "<<typeid(e).name()<<":"<<e.what()<<endl; hr = SELFREG_E_CLASS; } catch(...) { LOGGER_ERROR<<_T("Exception")<<endl; hr = SELFREG_E_CLASS; } EvtLogInstall(NULL!=prodPrefix ? prodPrefix : _T("unknown"),NULL!=compPrefix ? compPrefix : _T("unknown"),TRUE,hr); return hr; } // of DllRegisterServer()
STDAPI DllUnregisterServer() { HRESULT hr = S_OK; LPCTSTR prodPrefix = NULL; LPCTSTR compPrefix = NULL; TCHAR szModulePath[MAX_PATH]; COMServer::GetModuleFileName(szModulePath,sizeof(szModulePath)/sizeof(szModulePath[0])); VersionInfo verInfo(szModulePath); prodPrefix = (LPCTSTR)verInfo.GetStringInfo(_T("ProductPrefix")); compPrefix = (LPCTSTR)verInfo.GetStringInfo(_T("ComponentPrefix")); try { Registry registry; RegistryUtil::RegisterComObjectsInTypeLibrary(registry,szModulePath,RegistryUtil::AUTO); registry.DeleteKeys(); if( registry.Prepare() ) registry.Commit(); } catch(BVR20983Exception e) { LOGGER_ERROR<<e<<endl; hr = SELFREG_E_CLASS; } catch(exception& e) { LOGGER_ERROR<<"Exception "<<typeid(e).name()<<":"<<e.what()<<endl; hr = SELFREG_E_CLASS; } catch(...) { LOGGER_ERROR<<_T("Exception")<<endl; hr = SELFREG_E_CLASS; } EvtLogInstall(NULL!=prodPrefix ? prodPrefix : _T("unknown"),NULL!=compPrefix ? compPrefix : _T("unknown"),FALSE,hr); return hr; } // of DllUnregisterServer()