DllMain in an exe?

后端 未结 3 621
庸人自扰
庸人自扰 2021-01-21 08:22

Is it possible to receive DllMain like notifications about thread attach/detach in stand-alone exe without using any extra dlls?

Edit: This is just a th

3条回答
  •  醉酒成梦
    2021-01-21 08:48

    Interesting question. I don't know of anything built into Win32 - I think you might have to to whip up a DLL that has an API that signaled events or posted messages when it got the various attach/detach messages.

    An alternative that would not require a separate DLL but would require some hack trickery is to use the debugging API (WaitForDebugEvent() specifically). If your application has a special 'test' mode (maybe indicated by a command line option) that does nothing but relaunch the exe using CreateProcess() with the DEBUG_ONLY_THIS_PROCESS flag, the parent ('debugger') process can call WaitForDebugEvent() to get notification of the thread start and end events as well as a bunch of other interesting events. The parent process can pass them on to the child as messages or by signaling events (if that's what you want) or perform its own logging if thats all you need.

    By no means a simple thing, but it would work and would not require a separate DLL or image, just a special mode for when you want to perform these tests.

提交回复
热议问题