user1881587 user1881587 - 1 year ago 113
C++ Question

Can you get the caller DLL or executable module from the callee

I only want to allow specific DLLs to execute code I have written on a function I hooked. short of performing a stack trace how do you get the module name of your caller?

Answer Source

Get a stack trace to find the return address of your function, for instance with CaptureStackBackTrace.

And then call GetModuleHandleEx passing GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS to obtain the module handle containing that code.

Finally, call GetModuleFileName to find the filename associated with that module.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download