use of com.sun.jna.platform.win32.COM.Moniker 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.Moniker in project jna by java-native-access.
the class EnumMoniker method cacheNext.
protected void cacheNext() {
assert COMUtils.comIsInitialized() : "COM not initialized";
final PointerByReference rgelt = new PointerByReference();
final WinDef.ULONGByReference pceltFetched = new WinDef.ULONGByReference();
WinNT.HRESULT hr = this.raw.Next(new WinDef.ULONG(1), rgelt, pceltFetched);
if (WinNT.S_OK.equals(hr) && pceltFetched.getValue().intValue() > 0) {
this.rawNext = new Moniker(rgelt.getValue());
} else {
if (!WinNT.S_FALSE.equals(hr)) {
COMUtils.checkRC(hr);
}
this.rawNext = null;
}
}
use of com.sun.jna.platform.win32.COM.Moniker in project jna by java-native-access.
the class RunningObjectTable_Test method GetObject.
@Test
public void GetObject() {
PointerByReference pprot = new PointerByReference();
HRESULT hr = Ole32.INSTANCE.GetRunningObjectTable(new DWORD(0), pprot);
COMUtils.checkRC(hr);
IRunningObjectTable rot = new RunningObjectTable(pprot.getValue());
PointerByReference ppenumMoniker = new PointerByReference();
hr = rot.EnumRunning(ppenumMoniker);
COMUtils.checkRC(hr);
IEnumMoniker iterator = new EnumMoniker(ppenumMoniker.getValue());
iterator.Reset();
PointerByReference rgelt = new PointerByReference();
ULONGByReference pceltFetched = new ULONGByReference();
hr = iterator.Next(new ULONG(1), rgelt, pceltFetched);
while (WinNT.S_OK.equals(hr) && pceltFetched.getValue().intValue() > 0) {
Moniker moniker = new Moniker(rgelt.getValue());
PointerByReference ppbc = new PointerByReference();
Ole32.INSTANCE.CreateBindCtx(new DWORD(), ppbc);
String name = moniker.GetDisplayName(ppbc.getValue(), moniker.getPointer());
PointerByReference ppunkObject = new PointerByReference();
hr = rot.GetObject(moniker.getPointer(), ppunkObject);
COMUtils.checkRC(hr);
IUnknown unk = new Unknown(ppunkObject.getValue());
PointerByReference ppvObject = new PointerByReference();
hr = unk.QueryInterface(new REFIID(IUnknown.IID_IUNKNOWN), ppvObject);
assertEquals(0, hr.intValue());
assertNotNull(ppvObject.getValue());
moniker.Release();
hr = iterator.Next(new ULONG(1), rgelt, pceltFetched);
}
}
Aggregations