No, you are doing exactly what Raymond Chen describes in his blog entry. You are waiting for the thread in your DLL_PROCESS_DETACH. Make sure that you understand what
'DLL notifications are serialized' means.
I think I know a way to demonstrate why this is a bad idea... add some code in your sendMessageThread that calls
getenv_s, _wgetenv_s[
^]. Also add some code to your parent process to load/unload the DLL periodically. This should eventually cause your code to deadlock. The reason for the deadlock is that the CRT accesses a global _ENV_LOCK and will potentially cause a race condition. There are dozens of other scenarios that will cause a deadlock.
One possible solution is to change your architecture by adding a OnEngineStop thread message and do your waiting there.
Best Wishes,
-David Delaune