I am learning COM. I wrote a simple COM component in the DLL and registered it in the registry. Then I created a simple client and tried to use my COM component. But I don't understand the DllMain
behaviour (I read this also).
extern "C" BOOL WINAPI DllMain(
_In_ HINSTANCE hinstDLL,
_In_ DWORD fdwReason,
_In_ LPVOID lpvReserved){
pDll = hinstDLL;
if (DLL_PROCESS_ATTACH == fdwReason){
trace("DllMain(): DLL_PROCESS_ATTACH");
}
else if (DLL_THREAD_ATTACH == fdwReason){
trace("DllMain(): DLL_THREAD_ATTACH");
}
else if (DLL_PROCESS_DETACH == fdwReason){
trace("DllMain(): DLL_PROCESS_DETACH");
}
else if (DLL_THREAD_DETACH == fdwReason){
trace("DllMain(): DLL_THREAD_DETACH");
}
else{
trace("DllMain(): unknown variant...");
}
return TRUE;
}
I expected for each DLL_PROCESS_ATTACH
one DLL_PROCESS_DETACH
to be called and for each DLL_THREAD_ATTACH
one DLL_THREAD_DETACH
to be called (if the exception doesn't happen).
But I see for a single DLL_PROCESS_ATTACH
there are two DLL_THREAD_DETACH
:
Why does it happen?