extern "C" int APIENTRY DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /* lpReserved */) { #ifdef _DEBUG // if no debugger is present, then don't load the dll. // this prevents other apps from loading the dll and locking // it. bool bInShellTest = false; TCHAR buf[MAX_PATH + 1]; // MAX_PATH ok, the test really is for debugging anyway. DWORD pathLength = GetModuleFileName(NULL, buf, MAX_PATH); if(pathLength >= 14) { if ((_tcsicmp(&buf[pathLength-14], _T("\\ShellTest.exe"))) == 0) { bInShellTest = true; } if ((_tcsicmp(&buf[pathLength-13], _T("\\verclsid.exe"))) == 0) { bInShellTest = true; } } if (!::IsDebuggerPresent() && !bInShellTest) { ATLTRACE("In debug load preventer\n"); return FALSE; } #endif // NOTE: Do *NOT* call apr_initialize() or apr_terminate() here in DllMain(), // because those functions call LoadLibrary() indirectly through malloc(). // And LoadLibrary() inside DllMain() is not allowed and can lead to unexpected // behavior and even may create dependency loops in the dll load order. if (dwReason == DLL_PROCESS_ATTACH) { if (g_hmodThisDll == NULL) { g_csGlobalCOMGuard.Init(); } // Extension DLL one-time initialization g_hmodThisDll = hInstance; } else if (dwReason == DLL_PROCESS_DETACH) { // do not clean up memory here: // if an application doesn't release all COM objects // but still unloads the dll, cleaning up ourselves // will lead to crashes. // better to leak some memory than to crash other apps. // sometimes an application doesn't release all COM objects // but still unloads the dll. // in that case, we do it ourselves g_csGlobalCOMGuard.Term(); } return 1; // ok }
void WMIService::TermStaticState() { csSinkThreads.Term(); }
void WMIService::InitStaticState() { csSinkThreads.Init(); }