Question

I'm looking to get the native Window handle of a powerpoint window using Java / JACOB. The MSDN documentation seems to suggest it should be possible to just grab the "HWND" property, so I'm attempting that like so:

app = new ActiveXComponent("PowerPoint.Application");
Dispatch presentations = app.getProperty("Presentations").toDispatch();
presentation = Dispatch.call(presentations, "Open", fileLocation).toDispatch();
EnumVariant windows = new EnumVariant(Dispatch.get(presentation, "Windows").toDispatch());
Dispatch window = windows.nextElement().toDispatch();
Dispatch.get(window, "HWND"); //Exception here

However, I don't seem to be able to get the window handle this way - I get the following error:

Exception in thread "main" com.jacob.com.ComFailException: A COM exception has been encountered:
At Invoke of: HWND
Description: 80020003 / Member not found.

at com.jacob.com.Dispatch.invokev(Native Method)
at com.jacob.com.Dispatch.invokev(Dispatch.java:625)
at com.jacob.com.Dispatch.get(Dispatch.java:788)
at tester.PowerpointSlideShowRunner.<init>(PowerpointSlideShowRunner.java:54)
at tester.PowerpointSlideShowRunner.main(PowerpointSlideShowRunner.java:154)

Is this a bug in the library, or am I doing something wrong / misunderstanding something here? The latter is quite possible as I'm entirely new to Jacob. Either way, how should I grab the HWND of the Powerpoint window using JACOB?

Was it helpful?

Solution

The MSDN documentation you have linked is for the .NET Interop assembly which wraps the PowerPoint COM object model for use by .NET managed code, rather than for the COM object model itself.

The metadata in the interop assembly shows that there is actually an undocumented HWND property present in the COM interface to a DocumentWindow, but it carries the special type library attribute FUNCFLAG_FRESTRICTED which indicates that it

is intended for system-level functions or functions that type browsers should not display.

I imagine this is the reason that your attempt to call this property by name through the DocumentWindow dispatch interface is failing.

However, the Interop assembly metadata also shows that the DISPID (dispatch identifier) for this restricted property is the value 0x7e4. I'm not very familiar with the JACOB library but I believe there is an override which allows you to get the value of a property by DISPID rather than by name:

Dispatch.get(window, 0x7e4);

I suggest you give this a try.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top