in my last posting, I reported the issue with register a non-COM dll. now I got more details about the issue now.
we I have 2 dll. A.dll uses B.dll. both are normal dll with static linking being useb y some applications. In our customer, a policy is to register all dlls in a directory at window login. so we can't skip these dlls.
Now the regsvr32 will call the following functions on the dll
1 2 3
>LoadLibraryEx
>GetProcAddress
>FreeLibrary
When in LoadLibraryEx, the following steps are carried out
1 2 3
1. B.dll is loaded.
2. call DllMain of A.dll with DLL_PROCESS_ATTACH
3. call DllMain of A.dll with DLL_THREAD_ATTACH
Then call to FreeLibrary 4. call DllMain of A.dll with DLL_PROCESS_DETACH.
But since there is a DLL_THREAD_ATTACH and not corresponding DETACH, the A.dll is blocked and FreeLibrary never exits. So does regsvr32.
is there any guru having a idea why this happen ? I am puzzled with why there is a DLL_THREAD_ATTACH process..
Summary in the context of what I said: If a thread calling LoadLibrary() produces the call with DLL_PROCESS_ATTACH, but nothing else. DLL_THREAD_ATTACH is only called by additional threads.
The document also states that DLL_THREAD_DETACH is only called by thread that cleanly exit. I therefore conclude that a DLL should not expect the thread count to go back to zero (meaning there's a detach for every attach) before getting DLL_PROCESS_DETACH.
the issue is a global variable which create a thread. When the DllMain is called, this variable is created which spawns a thread. However this thread can't be terminated in DLL_PROCESS_DETACH.
so I have to change this gloable variable to a static local. then it is solved.