Hooking exit process



As a continuation of my other thread here, I am now trying to hook
ExitProcess() so a routine up in my dll will be called at the time the exe
is unloading BEFORE the DllMain is called with DLL_PROCESS_DETACH is called.

I used the example code from

http://www.jamajm.com/e-books/cpprichter/HTML/ch22j.htm

which shows how to hook ExitProcess. I pasted that code in a test exe and
it works very nicely. MyExitProcess() code is always called when the exe
exits. Perfect so far.

So I pasted the code in to my dll and MyExitProcess() is never called. The
registering of the hook seems to work perfectly, but it never gets called.

I have tried scanning for both the exe name and the dll name, and neither
works. In both cases it finds the right entry, installs the hook, but
MyExitProcess in the dll is never called when the exe exits.

Any idea what I'm doing wrong? Why would hooking ExitProcess in this code
work in an exe but not in a dll loaded by that exe?

Bruce.


.



Relevant Pages

  • Re: Hooking exit process
    ... You better avoid hooking; these hacks ... In DLL_DETACH_PROCESS on ExitProcess you cannot do any meaningful teardown. ... ExitProcessso a routine up in my dll will be called at the time the exe ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Hooking exit process
    ... ExitProcess() so a routine up in my dll will be called at the time the exe ... So I pasted the code in to my dll and MyExitProcessis never called. ... The registering of the hook seems to work perfectly, ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Multiple instances of DLL in memory.
    ... > and .exe which uses this dll. ... > the global hook procedure is called by some process. ... shared memory. ...
    (borland.public.delphi.nativeapi)
  • Executable PE Import table missing ExitProcess?
    ... I'm figuring out executable PE Import tables for ... executable linked against the static C runtime library, it shows ExitProcess ... If I link against the DLL C runtime, why does ExitProcess disappear from the ... exe Import list for kernel32.dll? ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Multiple instances of DLL in memory.
    ... > and .exe which uses this dll. ... > the global hook procedure is called by some process. ...
    (borland.public.delphi.nativeapi)

Quantcast