When the DLL's DllMain is called during a FreeLibrary the
DLL_PROCESS_DETACH code sets an event in the thread and then waits for
that thread to exit.
The thread releases the interface object and then calls
CoUninitialize(). Which hangs after calling the COM module's
DllCanUnloadNow() function. DllCanUnloadNow() does return TRUE.
As a test I added code so that the thread shutdown is initiated outside
of DLL_PROCESS_DETACH to see what would happen. The CoUninitialize()
does not hang.
Why would CoUninitialize() in one thread hang if the DLL is also
processing DLL_PROCESS_DETACH?
Tim
Must be a threading issue. Calls to DllMain are serialized. Apparently, your
call to CoUninitialize causes COM to attempt to shut down a notification
thread or something, which in turn attempts to notify your DLL. You may be
able to get around it by calling DisableThreadLibraryCalls in response to
DLL_PROCESS_ATTACH. If that doesn't help you need to rethink your threading
settings.
- Per
"Tim Stotelmeyer" <ti...@attachmate.com> wrote in message
news:3B096069...@attachmate.com...
Jason
"Tim Stotelmeyer" <ti...@attachmate.com> wrote in message
news:3B096069...@attachmate.com...
On your tip I tried DisableThreadLibraryCall. Unfortunately it did not help.
It was worth a try.
What's strange is that another DLL which uses a similar threading scheme and
uses the same COM interface object has no problem.
Tim
So far I've only tested my problem with Windows 2000.
I have seen GPFs from the last CoUninitialize() when one of my other threads
forgot to call CoUninitialize() before it exited.
Tim
Michael
"Tim Stotelmeyer" <ti...@attachmate.com> wrote in message
news:3B09917A...@attachmate.com...
I can duplicate the hang by starting only one thread. The CoUninitialize() is
the third to the last line in the thread's function so the thread is not in a
wait state by then. The second to the last line is a flag that I set that says
the thread is no longer running. The code in DLL_PROCESS_DETACH polls this flag
every 250 milliseconds. I supposed I could poll on GetExitCodeThread() instead
of using the flag.
Michael
"Tim Stotelmeyer" <ti...@attachmate.com> wrote in message
news:3B0A7B69...@attachmate.com...
I did finally figure out why one of my DLLs was not hanging and the other one
was. The non-hanging DLL called CoInitializeEx in DLL_PROCESS_ATTACH and
CoUninitialize in DLL_PROCESS_DETACH. Where as the hanging DLL did not make
these calls. Once I added them in my hanging DLL stopped hanging.
It took me a week to figure this out. Ugh.
Tim