Access hooked instance from inside hook handler

Sep 3, 2010 at 4: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;
      This.DoSomething();

      // Call original API
      Foo callingInstance = GetCallingObject() as Foo;
      callingInstance.Bar(someParam);
}

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 6:19 PM

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

http://easyhook.codeplex.com/Thread/View.aspx?ThreadId=227633

There, I am hooking a COM object as well.