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.
views:
398answers:
3Get 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);
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.
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.