Exe and dll initialization problem in using the Madchook

c++ / delphi package - dll injection and api hooking
Post Reply
psy2391
Posts: 7
Joined: Thu Feb 11, 2016 3:16 am

Exe and dll initialization problem in using the Madchook

Post by psy2391 »

If I use the functions in MadChook in exe and dll respectively, and I want to load the dll in the exe.
InitializeMadCHook and FinalizeMadCHook Where should I run ?

My English isn't that good . Sorry.
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: Exe and dll initialization problem in using the Madchook

Post by madshi »

Initialize/FinalizeMadCHook() should only be used by MSVC++ and GCC++ users, not by Delphi or BCB users.

If you're a MSVC++ user, then you should call Initialize/FinalizeMadCHook in all those modules (dlls or exes) which link in the madCodeHook static lib. If your dll links in the madCodeHook static lib, call Initialize/FinalizeMadCHook in DllMain in the PROCESS_ATTACH and PROCESS_DETACH events. If your exe links in the madCodeHook static lib, call InitializeMadCHook somewhere in the initialization. The exact place isn't important, as long as you call it before you call any madCodeHook APIs. Call FinalizeMadCHook when your exe shuts down. Again, the exact place/time isn't important, but make sure you don't call any further madCodeHook APIs after you've called FinalizeMadCHook.

If your dll doesn't link in the madCodeHook static lib, don't call Initialize/FinalizeMadCHook in your dll.

If your exe doesn't link in the madCodeHook static lib, don't call Initialize/FinalizeMadCHook in your exe.

You can also look at the demo projects to see how they're doing it.
psy2391
Posts: 7
Joined: Thu Feb 11, 2016 3:16 am

Re: Exe and dll initialization problem in using the Madchook

Post by psy2391 »

It became apparent. Thanks for answers
Post Reply