Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a COM interface given a HWND of an ActiveX control?

I'm trying to write a little C (C++ is fine, too) utility for spying ActiveX controls. Given some HWND handle of a window I'd like to print

  1. which properties and which methods are exposed by the ActiveX control for this HWND
  2. optionally, what interfaces does the control implement

For testing purposes, I'm embedding random ActiveX controls (like, the Microsoft Slider control) into the ActiveX Control Test Container so that I know that the HWND of the control is indeed the window of an ActiveX control. Furthermore, I know what properties/methods the control exposes, so I can test my tool.

My current solution for (1) is to use the AccessibleObjectFromWindow function on the HWND to get an IDispatch. It works, but it seems you really always only get an accessible interface back (the IDispatch which is returned is just the IDispatch part of the IAccessible interface). I tried passing the actual CLSID of my sample control as the third argument to AccessibleObjectFromWindow but that didn't help either. Seems that function really lives up to it's name - you always only get the accessibility interface. :-)

Does anybody know whether such an "ActiveX spy" is possible at all? If so, how?

like image 380
Frerich Raabe Avatar asked Apr 05 '11 09:04

Frerich Raabe


People also ask

What is ActiveX interface?

Basically an ActiveX control is a software component that executes common tasks and can integrate into the user interface of an application that provides the necessary ActiveX control host functionality.

What are the properties exposed by ActiveX controls?

Properties are data members of the ActiveX control that are exposed to any container. Properties provide an interface for applications that contain ActiveX controls, such as Automation clients and ActiveX control containers. Properties are also called attributes.

What is ActiveX control example?

ActiveX controls are small program building blocks that can be used to create distributed applications that work over the Internet through web browsers. Examples include customized applications for gathering data, viewing certain kinds of files, and displaying animation.


1 Answers

You don't

If you have access to the implementation of the activex control (e.g. in ATL) you can use a lookup table to get back at the control owning the HWND; you could use this in conjunction with the global instance table

like image 106
sehe Avatar answered Sep 27 '22 22:09

sehe