Skip to content

Commit

Permalink
Merge pull request #616 from matthiasblaesing/c.s.j.p.w.COM.util_acce…
Browse files Browse the repository at this point in the history
…ss_IDispatch

Allow access to base interfaces via ProxyObject and improve binding
  • Loading branch information
dblock committed Mar 26, 2016
2 parents 290859e + a1bee93 commit 2c6d9e8
Show file tree
Hide file tree
Showing 7 changed files with 920 additions and 667 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Features
* [#608](https://github.com/java-native-access/jna/pull/608): Mavenize the build process - change parent and native pom artifactId/name to differentiate in IDE and build tools. [@bhamail](https://github.com/bhamail)
* [#613](https://github.com/java-native-access/jna/pull/613): Make Win32Exception extend LastErrorException [@lgoldstein](https://github.com/lgoldstein).
* [#613](https://github.com/java-native-access/jna/pull/614): Added standard 'Kernel32Util#closeHandle' method that throws a Win32Exception if failed to close the handle [@lgoldstein](https://github.com/lgoldstein).
* [#616](https://github.com/java-native-access/jna/pull/616): Allow access to base interfaces (most important IDispatch) via ProxyObject and improve binding by allowing to use dispId for the call - [@matthiasblaesing](https://github.com/matthiasblaesing).

Bug Fixes
---------
Expand All @@ -55,7 +56,7 @@ Bug Fixes
* [#593](https://github.com/java-native-access/jna/pull/593): Improve binding of TypeLib bindings - [@matthiasblaesing](https://github.com/matthiasblaesing).
* [#578](https://github.com/java-native-access/jna/pull/578): Fix COM CallbackHandlers, allow usage of VARIANTs directly in c.s.j.p.w.COM.util.ProxyObject and fix native memory leak in c.s.j.p.w.COM.util.ProxyObject - [@matthiasblaesing](https://github.com/matthiasblaesing)
* [#601](https://github.com/java-native-access/jna/pull/601): Remove COMThread and COM initialization from objects and require callers to initialize COM themselves. Asserts are added to guard correct usage. - [@matthiasblaesing](https://github.com/matthiasblaesing).
* [#602] https://github.com/java-native-access/jna/pull/602): Make sure SID related memory is properly released once no longer required [@lgoldstein](https://github.com/lgoldstein).
* [#602](https://github.com/java-native-access/jna/pull/602): Make sure SID related memory is properly released once no longer required [@lgoldstein](https://github.com/lgoldstein).
* [#610](https://github.com/java-native-access/jna/pull/610): Fixed issue #604: Kernel32#GetLastError() always returns ERROR_SUCCESS [@lgoldstein](https://github.com/lgoldstein).

Release 4.2.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ void invokeOnThread(final DISPID dispIdMember, final REFIID riid, LCID lcid, WOR
PointerByReference ppvObject = new PointerByReference();
IID iid = com.sun.jna.platform.win32.COM.IUnknown.IID_IUNKNOWN;
dispatch.QueryInterface(new REFIID(iid), ppvObject);
Unknown rawUnk = new Unknown(ppvObject.getValue());
long unknownId = Pointer.nativeValue( rawUnk.getPointer() );
IUnknown unk = CallbackProxy.this.factory.createProxy(IUnknown.class, unknownId, dispatch);
IUnknown unk = CallbackProxy.this.factory.createProxy(IUnknown.class, dispatch);
if(targetClass.getAnnotation(ComInterface.class) != null) {
rjargs.add(unk.queryInterface(targetClass));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@
import java.util.List;

public class Factory {

/**
* Creates a utility COM Factory and a ComThread on which all COM calls are executed.
* NOTE: Remember to call factory.getComThread().terminate() at some appropriate point.
*
* Factory keeps track of COM objects - all objects created with this
* factory can be disposed by calling {@link Factory#disposeAll() }.
*/
public Factory() {
assert COMUtils.comIsInitialized() : "COM not initialized";
Expand Down Expand Up @@ -90,22 +88,6 @@ public <T> T createProxy(Class<T> comInterface, IDispatch dispatch) {
T result = comInterface.cast(proxy);
return result;
}

/** only for use when creating ProxyObjects from Callbacks
*
* @param comInterface
* @param unknownId
* @param dispatch
* @return proxy object
*/
<T> T createProxy(Class<T> comInterface, long unknownId, IDispatch dispatch) {
assert COMUtils.comIsInitialized() : "COM not initialized";

ProxyObject jop = new ProxyObject(comInterface, unknownId, dispatch, this);
Object proxy = Proxy.newProxyInstance(comInterface.getClassLoader(), new Class<?>[] { comInterface }, jop);
T result = comInterface.cast(proxy);
return result;
}

/**
* Creates a new COM object (CoCreateInstance) for the given progId and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
*/
package com.sun.jna.platform.win32.COM.util;

import com.sun.jna.platform.win32.OaIdl.DISPID;

/**
* Java friendly version of {@link com.sun.jna.platform.win32.COM.IDispatch}.
*
*/
public interface IDispatch extends IUnknown {

<T> void setProperty(String name, T value);
<T> T getProperty(Class<T> returnType, String name, Object... args);
<T> T invokeMethod(Class<T> returnType, String name, Object... args);
<T> void setProperty(DISPID dispid, T value);
<T> T getProperty(Class<T> returnType, DISPID dispid, Object... args);
<T> T invokeMethod(Class<T> returnType, DISPID dispid, Object... args);
}
Loading

0 comments on commit 2c6d9e8

Please sign in to comment.