Skip to content

Commit 5b11de5

Browse files
Merge pull request #913 from matthiasblaesing/iid_connectionpoint
Add @cominterface anntation to IConnectionPoint
2 parents c333527 + 7ab49ce commit 5b11de5

File tree

4 files changed

+138
-1
lines changed

4 files changed

+138
-1
lines changed

CHANGES.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ Features
99
--------
1010
* [#903](https://github.com/java-native-access/jna/pull/903): Carry `HRESULT` in `c.s.j.p.win32.COM.COMException`, introduce `c.s.j.p.win32.COM.COMInvokeException` as subclass of `COMException` for exception as the result of a `IDispatch#Invoke`. The `EXECPINFO` is unwrapped into fields in the `COMInvokeException` and correctly freed. - [@matthiasblaesing](https://github.com/matthiasblaesing).
1111
* [#822](https://github.com/java-native-access/jna/issues/822): `Native#loadLibrary` requires that the interface class passed in is an instance of Library. The runtime check can be enhanced by using a constraint generic. This breaks binary compatibility (see notes below) - [@d-noll](https://github.com/d-noll).
12-
* [#889](https://github.com/java-native-access/jna/issues/889): The `Structure#newInstance` receive the target type as a parameter. This adds a limited generic type, so that the return type ist the target type and not a generic structure, removing the necessity to do an explizit cast - [@matthiasblaesing](https://github.com/matthiasblaesing).
12+
* [#889](https://github.com/java-native-access/jna/issues/889): The `Structure#newInstance` receive the target type as a parameter. This adds a limited generic type, so that the return type ist the target type and not a generic structure, removing the necessity to do an explizit cast - [@matthiasblaesing](https://github.com/matthiasblaesing).
13+
* [#913](https://github.com/java-native-access/jna/issues/913): Add `@ComInterface` annotation to `com.sun.jna.platform.win32.COM.util.IConnectionPoint` to make it possible to retrieve it via `IUnknown#queryInterface` - [@matthiasblaesing](https://github.com/matthiasblaesing).
1314

1415
Bug Fixes
1516
---------

contrib/platform/src/com/sun/jna/platform/win32/COM/util/IConnectionPoint.java

+2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
package com.sun.jna.platform.win32.COM.util;
2525

2626
import com.sun.jna.platform.win32.COM.COMException;
27+
import com.sun.jna.platform.win32.COM.util.annotation.ComInterface;
2728

29+
@ComInterface(iid="{B196B284-BAB4-101A-B69C-00AA00341D07}")
2830
public interface IConnectionPoint {
2931

3032
/**

contrib/platform/test/com/sun/jna/platform/win32/COM/util/ComEventCallbacksFactory_Test.java

+67
Original file line numberDiff line numberDiff line change
@@ -295,4 +295,71 @@ public void testComEventCallback() {
295295
hr = proxy.QueryInterface(new REFIID(new IID("{00000000-0000-0000-C000-000000000000}")), interfacePointer);
296296
assertTrue(COMUtils.FAILED(hr));
297297
}
298+
299+
// This tests, that the IConnectionPoint interface can be queried
300+
// via queryInterface and does not require the primary interface
301+
// to extends IConnectionPoint
302+
303+
@ComObject(progId="Internet.Explorer.1", clsId = "{0002DF01-0000-0000-C000-000000000046}")
304+
interface ComInternetExplorerWithoutConnectionPoint extends ComIWebBrowser2WithoutConnectionPoint {
305+
}
306+
307+
@ComInterface(iid="{D30C1661-CDAF-11D0-8A3E-00C04FC9E26E}")
308+
interface ComIWebBrowser2WithoutConnectionPoint extends IUnknown {
309+
@ComProperty
310+
boolean getVisible();
311+
312+
@ComProperty
313+
void setVisible(boolean value);
314+
315+
@ComMethod
316+
void Quit();
317+
318+
@ComMethod
319+
/**
320+
* navOpenInNewWindow = 1
321+
* navNoHistory = 2
322+
* navNoReadFromCache = 4
323+
* navNoWriteToCache = 8
324+
* navAllowAutosearch = 16
325+
* navBrowserBar = 32
326+
* navHyperlink = 64
327+
* navEnforceRestricted = 128
328+
* navNewWindowsManaged = 256
329+
* navUntrustedForDownload = 512
330+
* navTrustedForActiveX = 1024
331+
* navOpenInNewTab = 2048
332+
* navOpenInBackgroundTab = 4096
333+
* navKeepWordWheelText = 8192
334+
* navVirtualTab = 16384
335+
* navBlockRedirectsXDomain = 32768
336+
* navOpenNewForegroundTab = 65536
337+
*/
338+
void Navigate(String url, long flags, String targetFrameName, VARIANT postData, String headers);
339+
}
340+
341+
@Test
342+
public void adviseNavigateComplete2WithoutConnectionPoint() throws InterruptedException {
343+
ComInternetExplorerWithoutConnectionPoint ieApp = factory.createObject(ComInternetExplorerWithoutConnectionPoint.class);
344+
ComIWebBrowser2WithoutConnectionPoint iWebBrowser2 = ieApp.queryInterface(ComIWebBrowser2WithoutConnectionPoint.class);
345+
iWebBrowser2.setVisible(true);
346+
347+
DWebBrowserEvents2_Listener listener = new DWebBrowserEvents2_Listener();
348+
IComEventCallbackCookie cookie = iWebBrowser2.queryInterface(IConnectionPoint.class).advise(DWebBrowserEvents2.class, listener);
349+
350+
iWebBrowser2.Navigate("https://github.com/java-native-access/jna", 0, null, null, null);
351+
352+
for(int i = 0; i < 10; i++) {
353+
if(listener.navigateComplete2Called) {
354+
break;
355+
}
356+
Thread.sleep(1000);
357+
}
358+
359+
iWebBrowser2.Quit();
360+
361+
Assert.assertTrue("NavigateComplete was not called", listener.navigateComplete2Called);
362+
Assert.assertNotNull("URL passed to NavigateComplete2 was NULL", listener.navigateComplete2URL);
363+
Assert.assertThat(listener.navigateComplete2URL, CoreMatchers.startsWith("https://github.com/java-native-access/jna"));
364+
}
298365
}

contrib/platform/test/com/sun/jna/platform/win32/COM/util/ComEventCallbacksObjectFactory_Test.java

+67
Original file line numberDiff line numberDiff line change
@@ -291,4 +291,71 @@ public void testComEventCallback() {
291291
hr = proxy.QueryInterface(new REFIID(new IID("{00000000-0000-0000-C000-000000000000}")), interfacePointer);
292292
assertTrue(COMUtils.FAILED(hr));
293293
}
294+
295+
// This tests, that the IConnectionPoint interface can be queried
296+
// via queryInterface and does not require the primary interface
297+
// to extends IConnectionPoint
298+
299+
@ComObject(progId="Internet.Explorer.1", clsId = "{0002DF01-0000-0000-C000-000000000046}")
300+
interface ComInternetExplorerWithoutConnectionPoint extends ComIWebBrowser2WithoutConnectionPoint {
301+
}
302+
303+
@ComInterface(iid="{D30C1661-CDAF-11D0-8A3E-00C04FC9E26E}")
304+
interface ComIWebBrowser2WithoutConnectionPoint extends IUnknown {
305+
@ComProperty
306+
boolean getVisible();
307+
308+
@ComProperty
309+
void setVisible(boolean value);
310+
311+
@ComMethod
312+
void Quit();
313+
314+
@ComMethod
315+
/**
316+
* navOpenInNewWindow = 1
317+
* navNoHistory = 2
318+
* navNoReadFromCache = 4
319+
* navNoWriteToCache = 8
320+
* navAllowAutosearch = 16
321+
* navBrowserBar = 32
322+
* navHyperlink = 64
323+
* navEnforceRestricted = 128
324+
* navNewWindowsManaged = 256
325+
* navUntrustedForDownload = 512
326+
* navTrustedForActiveX = 1024
327+
* navOpenInNewTab = 2048
328+
* navOpenInBackgroundTab = 4096
329+
* navKeepWordWheelText = 8192
330+
* navVirtualTab = 16384
331+
* navBlockRedirectsXDomain = 32768
332+
* navOpenNewForegroundTab = 65536
333+
*/
334+
void Navigate(String url, long flags, String targetFrameName, VARIANT postData, String headers);
335+
}
336+
337+
@Test
338+
public void adviseNavigateComplete2WithoutConnectionPoint() throws InterruptedException {
339+
ComInternetExplorerWithoutConnectionPoint ieApp = factory.createObject(ComInternetExplorerWithoutConnectionPoint.class);
340+
ComIWebBrowser2WithoutConnectionPoint iWebBrowser2 = ieApp.queryInterface(ComIWebBrowser2WithoutConnectionPoint.class);
341+
iWebBrowser2.setVisible(true);
342+
343+
DWebBrowserEvents2_Listener listener = new DWebBrowserEvents2_Listener();
344+
IComEventCallbackCookie cookie = iWebBrowser2.queryInterface(IConnectionPoint.class).advise(DWebBrowserEvents2.class, listener);
345+
346+
iWebBrowser2.Navigate("https://github.com/java-native-access/jna", 0, null, null, null);
347+
348+
for(int i = 0; i < 10; i++) {
349+
if(listener.navigateComplete2Called) {
350+
break;
351+
}
352+
Thread.sleep(1000);
353+
}
354+
355+
iWebBrowser2.Quit();
356+
357+
Assert.assertTrue("NavigateComplete was not called", listener.navigateComplete2Called);
358+
Assert.assertNotNull("URL passed to NavigateComplete2 was NULL", listener.navigateComplete2URL);
359+
Assert.assertThat(listener.navigateComplete2URL, CoreMatchers.startsWith("https://github.com/java-native-access/jna"));
360+
}
294361
}

0 commit comments

Comments
 (0)