use of com.sun.jna.platform.win32.COM.Dispatch in project jna by java-native-access.
the class ProxyObject method fetchRawConnectionPoint.
// ---------------------- IConnectionPoint ----------------------
private ConnectionPoint fetchRawConnectionPoint(IID iid) throws InterruptedException, ExecutionException, TimeoutException {
assert COMUtils.comIsInitialized() : "COM not initialized";
// query for ConnectionPointContainer
IConnectionPointContainer cpc = this.queryInterface(IConnectionPointContainer.class);
Dispatch rawCpcDispatch = (Dispatch) cpc.getRawDispatch();
final ConnectionPointContainer rawCpc = new ConnectionPointContainer(rawCpcDispatch.getPointer());
// find connection point for comEventCallback interface
final REFIID adviseRiid = new REFIID(iid.getPointer());
final PointerByReference ppCp = new PointerByReference();
HRESULT hr = rawCpc.FindConnectionPoint(adviseRiid, ppCp);
COMUtils.checkRC(hr);
final ConnectionPoint rawCp = new ConnectionPoint(ppCp.getValue());
return rawCp;
}
use of com.sun.jna.platform.win32.COM.Dispatch in project jna by java-native-access.
the class ProxyObject method getUnknownId.
private long getUnknownId() {
assert COMUtils.comIsInitialized() : "COM not initialized";
if (-1 == this.unknownId) {
try {
final PointerByReference ppvObject = new PointerByReference();
Thread current = Thread.currentThread();
String tn = current.getName();
IID iid = com.sun.jna.platform.win32.COM.IUnknown.IID_IUNKNOWN;
HRESULT hr = ProxyObject.this.getRawDispatch().QueryInterface(new REFIID(iid), ppvObject);
if (WinNT.S_OK.equals(hr)) {
Dispatch dispatch = new Dispatch(ppvObject.getValue());
this.unknownId = Pointer.nativeValue(dispatch.getPointer());
// QueryInterface returns a COM object pointer with a +1
// reference, we must drop one,
// Note: createProxy adds one;
int n = dispatch.Release();
} else {
String formatMessageFromHR = Kernel32Util.formatMessage(hr);
throw new COMException("getUnknownId: " + formatMessageFromHR);
}
} catch (Exception e) {
throw new COMException("Error occured when trying get Unknown Id ", e);
}
}
return this.unknownId;
}
use of com.sun.jna.platform.win32.COM.Dispatch in project jna by java-native-access.
the class EnumMoniker method iterator.
@Override
public Iterator<IDispatch> iterator() {
return new Iterator<IDispatch>() {
@Override
public boolean hasNext() {
return null != EnumMoniker.this.rawNext;
}
@Override
public IDispatch next() {
assert COMUtils.comIsInitialized() : "COM not initialized";
final Moniker moniker = EnumMoniker.this.rawNext;
final PointerByReference ppunkObject = new PointerByReference();
WinNT.HRESULT hr = EnumMoniker.this.rawRot.GetObject(moniker.getPointer(), ppunkObject);
COMUtils.checkRC(hr);
// To assist debug, can use the following code
// PointerByReference ppbc = new
// PointerByReference();
// Ole32.INSTANCE.CreateBindCtx(new DWORD(), ppbc);
//
// BSTRByReference ppszDisplayName = new
// BSTRByReference();
// hr = moniker.GetDisplayName(ppbc.getValue(),
// moniker.getPointer(), ppszDisplayName);
// COMUtils.checkRC(hr);
// String name = ppszDisplayName.getString();
// Ole32.INSTANCE.CoTaskMemFree(ppszDisplayName.getPointer().getPointer(0));
// TODO: Can we assume that the object is an
// IDispatch ?
// Unknown unk = new
// Unknown(ppunkObject.getValue());
Dispatch dispatch = new Dispatch(ppunkObject.getValue());
EnumMoniker.this.cacheNext();
IDispatch d = EnumMoniker.this.factory.createProxy(IDispatch.class, dispatch);
//must release a COM Ref, GetObject returns a pointer with +1
int n = dispatch.Release();
return d;
}
@Override
public void remove() {
throw new UnsupportedOperationException("remove");
}
};
}
use of com.sun.jna.platform.win32.COM.Dispatch in project jna by java-native-access.
the class Factory method createProxy.
@Override
public <T> T createProxy(Class<T> comInterface, IDispatch dispatch) {
T result = super.createProxy(comInterface, dispatch);
ProxyObject2 po2 = new ProxyObject2(result);
Object proxy = Proxy.newProxyInstance(comInterface.getClassLoader(), new Class<?>[] { comInterface }, po2);
return (T) proxy;
}
use of com.sun.jna.platform.win32.COM.Dispatch in project jna by java-native-access.
the class ComEventCallbacksObjectFactory_Test method testComEventCallback.
@Test
public void testComEventCallback() {
DWebBrowserEvents2_Listener listener = new DWebBrowserEvents2_Listener();
CallbackProxy proxy = new CallbackProxy(factory, DWebBrowserEvents2.class, listener);
REFIID refiid = new REFIID(new IID(DWebBrowserEvents2.IID));
// precondition: the structures for the listenedToRiid and
// refiid have to be different (else the PointerType#equals would
// be enough
assertFalse(proxy.listenedToRiid.getPointer().equals(refiid.getPointer()));
// Neverthe less, the QueryInterface method has to return the
// correct pointer (the IID is relevant, not its wrapper
PointerByReference interfacePointer = new PointerByReference();
// Check the "business" interface
HRESULT hr = proxy.QueryInterface(refiid, interfacePointer);
assertTrue(COMUtils.SUCCEEDED(hr));
assertEquals(interfacePointer.getValue(), proxy.getPointer());
// IUnknown must be implemented
hr = proxy.QueryInterface(new REFIID(IID_IUNKNOWN), interfacePointer);
assertTrue(COMUtils.SUCCEEDED(hr));
assertEquals(interfacePointer.getValue(), proxy.getPointer());
// Currently only Dispatch based callbacks are supported,
// so this interface must be present to
hr = proxy.QueryInterface(new REFIID(IID_IDISPATCH), interfacePointer);
assertTrue(COMUtils.SUCCEEDED(hr));
assertEquals(interfacePointer.getValue(), proxy.getPointer());
// Negative check -- this has to fail, the IID should not be
// assigned
hr = proxy.QueryInterface(new REFIID(new IID("{00000000-0000-0000-C000-000000000000}")), interfacePointer);
assertTrue(COMUtils.FAILED(hr));
}
Aggregations