use of com.sun.jna.ptr.PointerByReference 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.ptr.PointerByReference in project jna by java-native-access.
the class RunningObjectTable method enumRunning.
@Override
public Iterable<IDispatch> enumRunning() {
assert COMUtils.comIsInitialized() : "COM not initialized";
final PointerByReference ppenumMoniker = new PointerByReference();
WinNT.HRESULT hr = this.raw.EnumRunning(ppenumMoniker);
COMUtils.checkRC(hr);
com.sun.jna.platform.win32.COM.EnumMoniker raw = new com.sun.jna.platform.win32.COM.EnumMoniker(ppenumMoniker.getValue());
return new EnumMoniker(raw, this.raw, this.factory);
}
use of com.sun.jna.ptr.PointerByReference 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.ptr.PointerByReference in project jna by java-native-access.
the class SystemBTest method testHostProcessorInfo.
public void testHostProcessorInfo() {
int machPort = SystemB.INSTANCE.mach_host_self();
assertTrue(machPort > 0);
IntByReference procCount = new IntByReference();
PointerByReference procCpuLoadInfo = new PointerByReference();
IntByReference procInfoCount = new IntByReference();
int ret = SystemB.INSTANCE.host_processor_info(machPort, SystemB.PROCESSOR_CPU_LOAD_INFO, procCount, procCpuLoadInfo, procInfoCount);
assertEquals(ret, 0);
assertTrue(procCount.getValue() > 0);
assertEquals(procCpuLoadInfo.getValue().getIntArray(0, procInfoCount.getValue()).length, procInfoCount.getValue());
}
use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.
the class X11Test method testXFetchName.
public void testXFetchName() {
PointerByReference pref = new PointerByReference();
int status = X11.INSTANCE.XFetchName(display, root, pref);
try {
assertEquals("Bad status for XFetchName", 0, status);
} finally {
if (pref.getValue() != null) {
X11.INSTANCE.XFree(pref.getValue());
}
}
}
Aggregations