I am trying to load a .dll
file and have it display a message box when loaded. From my understanding, once a .dll
is loaded, it makes a call to
Raymond Chen has something to say about this in his blog entry titled Some reasons not to do anything scary in your DllMain:
And absolutely under no circumstances should you be doing anything as crazy as creating a window inside your DLL_PROCESS_ATTACH. In addition to the thread affinity issues, there's the problem of global hooks. Hooks running inside the loader lock are a recipe for disaster. Don't be surprised if your machine deadlocks.
In addition to the blog post Greg links to there are several other informative posts about the loader lock and things you should not do in DllMain.
In general you should only call functions in kernel32 that don't create threads/windows, use COM or calls LoadLibrary (or other functions involving the loader lock).
A reasonable list of safe things IMHO would be: DisableThreadLibraryCalls, Tls*, InitializeCriticalSection and in your case (for debugging purposes); OutputDebugString