Search in sources :

Example 11 with HRESULT

use of com.sun.jna.platform.win32.WinNT.HRESULT in project jna by java-native-access.

the class RunningObjectTable_Test method EnumRunning.

@Test
public void EnumRunning() {
    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);
    assertNotNull(ppenumMoniker.getValue());
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) PointerByReference(com.sun.jna.ptr.PointerByReference) DWORD(com.sun.jna.platform.win32.WinDef.DWORD) Test(org.junit.Test)

Example 12 with HRESULT

use of com.sun.jna.platform.win32.WinNT.HRESULT in project jna by java-native-access.

the class TypeLibUtilTest method testFindName.

public void testFindName() {
    // Test is modelled after ITypeLibTest#testFindName
    TypeLibUtil shellTypeLib = loadShellTypeLib();
    String memberValue = "count";
    String memberValueOk = "Count";
    FindName result = shellTypeLib.FindName(memberValue, 0, (short) 100);
    // 2 matches come from manual tests
    assertEquals(2, result.getFound());
    // Check that function return corrected member name (Count) - see uppercase C
    assertEquals(memberValueOk, result.getNameBuf());
    // There have to be as many pointers as reported by pcFound
    ITypeInfo[] typelib = result.getTInfo();
    assertEquals(2, typelib.length);
    assertNotNull(typelib[0]);
    assertNotNull(typelib[1]);
    PointerByReference pbr = new PointerByReference();
    HRESULT hr = typelib[1].GetTypeAttr(pbr);
    assertTrue(COMUtils.SUCCEEDED(hr));
    OaIdl.TYPEATTR pTypeAttr = new OaIdl.TYPEATTR(pbr.getValue());
    // Either interface FolderItemVerbs ({1F8352C0-50B0-11CF-960C-0080C7F4EE85})
    // or FolderItems ({744129E0-CBE5-11CE-8350-444553540000})
    String typeGUID = pTypeAttr.guid.toGuidString();
    assertTrue(typeGUID.equals("{1F8352C0-50B0-11CF-960C-0080C7F4EE85}") || typeGUID.equals("{744129E0-CBE5-11CE-8350-444553540000}"));
    typelib[1].ReleaseTypeAttr(pTypeAttr);
}
Also used : TYPEATTR(com.sun.jna.platform.win32.OaIdl.TYPEATTR) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) PointerByReference(com.sun.jna.ptr.PointerByReference) TYPEATTR(com.sun.jna.platform.win32.OaIdl.TYPEATTR) OaIdl(com.sun.jna.platform.win32.OaIdl) FindName(com.sun.jna.platform.win32.COM.TypeLibUtil.FindName)

Example 13 with HRESULT

use of com.sun.jna.platform.win32.WinNT.HRESULT in project jna by java-native-access.

the class ComEventCallbacksFactory_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));
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) IID(com.sun.jna.platform.win32.Guid.IID) REFIID(com.sun.jna.platform.win32.Guid.REFIID) PointerByReference(com.sun.jna.ptr.PointerByReference) REFIID(com.sun.jna.platform.win32.Guid.REFIID) Test(org.junit.Test)

Example 14 with HRESULT

use of com.sun.jna.platform.win32.WinNT.HRESULT in project jna by java-native-access.

the class ComEventCallbacks_Test method before.

@Before
public void before() {
    AbstractWin32TestSupport.killProcessByName("iexplore.exe");
    try {
        Thread.sleep(5 * 1000);
    } catch (InterruptedException ex) {
    }
    HRESULT hr = Ole32.INSTANCE.CoInitializeEx(null, Ole32.COINIT_MULTITHREADED);
    COMUtils.checkRC(hr);
    // Create InternetExplorer object
    ieApp = new PointerByReference();
    hr = Ole32.INSTANCE.CoCreateInstance(CLSID_InternetExplorer, null, WTypes.CLSCTX_SERVER, IDispatch.IID_IDISPATCH, ieApp);
    COMUtils.checkRC(hr);
    ieDispatch = new Dispatch(ieApp.getValue());
    ieDispatch.AddRef();
    hr = ieDispatch.GetIDsOfNames(new REFIID(Guid.IID_NULL), new WString[] { new WString("Quit") }, 1, lcid, dispIdQuit);
    COMUtils.checkRC(hr);
    hr = ieDispatch.GetIDsOfNames(new REFIID(Guid.IID_NULL), new WString[] { new WString("Visible") }, 1, lcid, dispIdVisible);
    COMUtils.checkRC(hr);
    hr = ieDispatch.GetIDsOfNames(new REFIID(Guid.IID_NULL), new WString[] { new WString("Navigate") }, 1, lcid, dispIdNavigate);
    COMUtils.checkRC(hr);
}
Also used : WString(com.sun.jna.WString) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) PointerByReference(com.sun.jna.ptr.PointerByReference) REFIID(com.sun.jna.platform.win32.Guid.REFIID) Before(org.junit.Before)

Example 15 with HRESULT

use of com.sun.jna.platform.win32.WinNT.HRESULT in project jna by java-native-access.

the class ComEventCallbacks_Test method FindConnectionPoint.

@Test
public void FindConnectionPoint() {
    // query for ConnectionPointContainer
    Unknown unk = new Unknown(ieApp.getValue());
    PointerByReference ppCpc = new PointerByReference();
    HRESULT hr = unk.QueryInterface(new REFIID(IID_IConnectionPointContainer), ppCpc);
    COMUtils.checkRC(hr);
    ConnectionPointContainer cpc = new ConnectionPointContainer(ppCpc.getValue());
    // find connection point for DWebBrowserEvents2
    REFIID riid = new REFIID(IID_DWebBrowserEvents2);
    PointerByReference ppCp = new PointerByReference();
    hr = cpc.FindConnectionPoint(riid, ppCp);
    COMUtils.checkRC(hr);
    // On success the returned pointer must not be null
    Assert.assertNotNull(ppCpc.getPointer());
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) PointerByReference(com.sun.jna.ptr.PointerByReference) REFIID(com.sun.jna.platform.win32.Guid.REFIID) Test(org.junit.Test)

Aggregations

HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)102 PointerByReference (com.sun.jna.ptr.PointerByReference)57 Test (org.junit.Test)26 REFIID (com.sun.jna.platform.win32.Guid.REFIID)20 UINT (com.sun.jna.platform.win32.WinDef.UINT)15 WString (com.sun.jna.WString)12 DWORD (com.sun.jna.platform.win32.WinDef.DWORD)12 WinNT (com.sun.jna.platform.win32.WinNT)12 DWORDByReference (com.sun.jna.platform.win32.WinDef.DWORDByReference)11 VARIANT (com.sun.jna.platform.win32.Variant.VARIANT)10 MEMBERID (com.sun.jna.platform.win32.OaIdl.MEMBERID)9 BSTRByReference (com.sun.jna.platform.win32.WTypes.BSTRByReference)9 ULONG (com.sun.jna.platform.win32.WinDef.ULONG)9 IID (com.sun.jna.platform.win32.Guid.IID)8 DISPIDByReference (com.sun.jna.platform.win32.OaIdl.DISPIDByReference)8 IntByReference (com.sun.jna.ptr.IntByReference)8 UINTByReference (com.sun.jna.platform.win32.WinDef.UINTByReference)7 COMException (com.sun.jna.platform.win32.COM.COMException)6 ConnectionPoint (com.sun.jna.platform.win32.COM.ConnectionPoint)6 Pointer (com.sun.jna.Pointer)5