Dwane Andrews
Dwane Andrews

Reputation: 21

How to I redirect a function call and then callback to the "original" function c++

I have a situation where I can not modify code, it is compiled and I can not modify the source, but need to log some data that is being sent to it. I can link to it via DLL. I am trying to capture the function call, redirect it to a new DLL that is linked in, store the data I need, but then call the unmodified function. I can capture the call by just doing a dllimport and redefining the function in my DLL, but then at the end I can't call the original function. Since they are the same name, it is just becoming a recursive call. How do I callback and exit?

I am using VC++ under VS2005.

Upvotes: 2

Views: 1223

Answers (2)

CR.
CR.

Reputation: 354

Don't use DllImport to load the original function.

Instead use LoadLibrary(Ex) and GetProcAddress to load the original DLL and find the original function and put it in a variable. Once that is done you can call the original function via the variable.

Upvotes: 1

user541686
user541686

Reputation: 210525

Take a look at EasyHook

Upvotes: 1

Related Questions