Access hooked instance from inside hook handler

Sep 3, 2010 at 5:09 PM

I'm hooking an object method and I'm trying to discover if there is a way to get a pointer or other reference to the calling object from within the hook handler. 

For example:

static int MyHookHandlerForFoo_Bar(int someParam)
      // Do hook stuff
      Main This = (Main)HookRuntimeInfo.Callback;

      // Call original API
      Foo callingInstance = GetCallingObject() as Foo;

Here I'm intercepting a call to the Bar method by an instance of Foo. My question is what can I do to get some type of reference (or even a pointer) to the calling instance of Foo (Where the fake GetCallingObject function is), so that I can call the original API?

If it matters, Foo happens to be a COM object in my case. 

Sep 18, 2010 at 7:19 PM

I posted my changes to EasyHook here (in form of a question):

There, I am hooking a COM object as well.