tags:

views:

398

answers:

3

In Perl, if I have HWND of a window object, how can I get access to that COM object using that handle? I looked at Win32::OLE but the closest I got was the GetActiveObject method, which expects a class.

+2  A: 

Get an HWND or location from an Accessible Object and manipulate it with the Windows API:

use Win32::GuiTest;

use a HWND

my $hwnd = $ao->WindowFromAccessibleObject();
my $name = Win32::GuiTest::GetWindowText($hwnd);
streetparade
Not exactly what I was looking for, but I think this leads me in right direction, I'll read the doc to see if I can get the pointer to the COM object. Thanks.
John
+1  A: 

There is no standard way to obtain a COM interface pointer from an HWND, because a window is not a COM object. The basic Windows API, including window handles, predates the invention of OLE and COM. The implementation of a particular window may expose some or all of its functionality through COM interfaces, but those interfaces will be application-specific.

If it is documented that the window you want to control exposes a public COM interface, the documentation for that window will also tell you how to query the window for an interface pointer. Most likely, it will require sending an application-specific window message.

Matthew Xavier
A: 

If you're looking to get the IAccessible interface from an HWND, you can try using WM_GETOBJECT (note: I assume there is someway to send window messages in Perl—it is well established that I have no Perl knowledge).

Not everyone does it this way, so make sure you handle failure somehow. For example, Internet Explorer exposes WM_HTML_GETOBJECT to get the IHTMLDocument2 pointer.

jeffamaphone