DLL_PROCESS_ATTACH failing to execute on Windows 7 C++

前端 未结 2 412
野性不改
野性不改 2021-01-03 12:49

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

相关标签:
2条回答
  • 2021-01-03 13:13

    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.

    0 讨论(0)
  • 2021-01-03 13:27

    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

    0 讨论(0)
提交回复
热议问题