Search in sources :

Example 1 with Moniker

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");
        }
    };
}
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 2 with Moniker

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

Example 3 with Moniker

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);
    }
}
Also used : ULONG(com.sun.jna.platform.win32.WinDef.ULONG) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) DWORD(com.sun.jna.platform.win32.WinDef.DWORD) REFIID(com.sun.jna.platform.win32.Guid.REFIID) ULONGByReference(com.sun.jna.platform.win32.WinDef.ULONGByReference) PointerByReference(com.sun.jna.ptr.PointerByReference) Test(org.junit.Test)

Aggregations

PointerByReference (com.sun.jna.ptr.PointerByReference)3 IEnumMoniker (com.sun.jna.platform.win32.COM.IEnumMoniker)2 Moniker (com.sun.jna.platform.win32.COM.Moniker)2 WinNT (com.sun.jna.platform.win32.WinNT)2 Dispatch (com.sun.jna.platform.win32.COM.Dispatch)1 REFIID (com.sun.jna.platform.win32.Guid.REFIID)1 WinDef (com.sun.jna.platform.win32.WinDef)1 DWORD (com.sun.jna.platform.win32.WinDef.DWORD)1 ULONG (com.sun.jna.platform.win32.WinDef.ULONG)1 ULONGByReference (com.sun.jna.platform.win32.WinDef.ULONGByReference)1 HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)1 Iterator (java.util.Iterator)1 Test (org.junit.Test)1