Search in sources :

Example 51 with PointerByReference

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;
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) COMException(com.sun.jna.platform.win32.COM.COMException) IID(com.sun.jna.platform.win32.Guid.IID) REFIID(com.sun.jna.platform.win32.Guid.REFIID) PointerByReference(com.sun.jna.ptr.PointerByReference) Dispatch(com.sun.jna.platform.win32.COM.Dispatch) IDispatch(com.sun.jna.platform.win32.COM.IDispatch) WString(com.sun.jna.WString) REFIID(com.sun.jna.platform.win32.Guid.REFIID) ConnectionPoint(com.sun.jna.platform.win32.COM.ConnectionPoint) TimeoutException(java.util.concurrent.TimeoutException) COMException(com.sun.jna.platform.win32.COM.COMException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ExecutionException(java.util.concurrent.ExecutionException)

Example 52 with PointerByReference

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);
}
Also used : PointerByReference(com.sun.jna.ptr.PointerByReference) WinNT(com.sun.jna.platform.win32.WinNT)

Example 53 with PointerByReference

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");
        }
    };
}
Also used : IEnumMoniker(com.sun.jna.platform.win32.COM.IEnumMoniker) Moniker(com.sun.jna.platform.win32.COM.Moniker) PointerByReference(com.sun.jna.ptr.PointerByReference) Iterator(java.util.Iterator) WinNT(com.sun.jna.platform.win32.WinNT) Dispatch(com.sun.jna.platform.win32.COM.Dispatch)

Example 54 with PointerByReference

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());
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) PointerByReference(com.sun.jna.ptr.PointerByReference)

Example 55 with PointerByReference

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());
        }
    }
}
Also used : PointerByReference(com.sun.jna.ptr.PointerByReference)

Aggregations

PointerByReference (com.sun.jna.ptr.PointerByReference)128 HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)54 IntByReference (com.sun.jna.ptr.IntByReference)35 Pointer (com.sun.jna.Pointer)20 Test (org.junit.Test)19 DWORD (com.sun.jna.platform.win32.WinDef.DWORD)18 REFIID (com.sun.jna.platform.win32.Guid.REFIID)13 File (java.io.File)13 ULONG (com.sun.jna.platform.win32.WinDef.ULONG)10 PSID (com.sun.jna.platform.win32.WinNT.PSID)10 Memory (com.sun.jna.Memory)8 WString (com.sun.jna.WString)8 Dispatch (com.sun.jna.platform.win32.COM.Dispatch)7 ULONGByReference (com.sun.jna.platform.win32.WinDef.ULONGByReference)7 WinNT (com.sun.jna.platform.win32.WinNT)7 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)7 IID (com.sun.jna.platform.win32.Guid.IID)6 ArrayList (java.util.ArrayList)6 IDispatch (com.sun.jna.platform.win32.COM.IDispatch)5 UINT (com.sun.jna.platform.win32.WinDef.UINT)5