views:

93

answers:

2

I know this may be a long shot so forgive me as I don't really know that much about COM.

Basically what I am trying to do is get the pointer to the IUnknown interface for a running application, the problem is the only thing I know about the app is its main window handle.

Would this be possible?

+1  A: 

Sometimes yes, if the window is in your process (otherwise a pointer in another process is meaningless to you) and the window's writer explicitly tell you that it is expecting a message and returning an interface. Mostly no, people usually do not write hacks when there is no need to and sending messages unknown to the writer would have unpredictable behavior.

Sheng Jiang 蒋晟
+3  A: 

The "standard" way to do this is with the AccessibleObjectFromWindow Win32 API. That said, not many things actually support this, so your mileage may vary. You'd PInvoke to AccessibleObjectFromWindow, pass the HWND, then use Marshal.GetObjectForIUnknown on the IntPtr you get back.

nitzmahone