Search in sources :

Example 81 with HRESULT

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

the class TypeInfoUtil method getIDsOfNames.

/**
     * Gets the i ds of names.
     * 
     * @param rgszNames
     *            the rgsz names
     * @param cNames
     *            the c names
     * @return the i ds of names
     */
public MEMBERID[] getIDsOfNames(LPOLESTR[] rgszNames, int cNames) {
    MEMBERID[] pMemId = new MEMBERID[cNames];
    HRESULT hr = this.typeInfo.GetIDsOfNames(rgszNames, new UINT(cNames), pMemId);
    COMUtils.checkRC(hr);
    return pMemId;
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) MEMBERID(com.sun.jna.platform.win32.OaIdl.MEMBERID) UINT(com.sun.jna.platform.win32.WinDef.UINT)

Example 82 with HRESULT

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

the class TypeInfoUtil method getNames.

/**
     * Gets the names.
     * 
     * @param memid
     *            the memid
     * @param maxNames
     *            the max names
     * @return the names
     */
public String[] getNames(MEMBERID memid, int maxNames) {
    BSTR[] rgBstrNames = new BSTR[maxNames];
    UINTByReference pcNames = new UINTByReference();
    HRESULT hr = this.typeInfo.GetNames(memid, rgBstrNames, new UINT(maxNames), pcNames);
    COMUtils.checkRC(hr);
    int cNames = pcNames.getValue().intValue();
    String[] result = new String[cNames];
    for (int i = 0; i < result.length; i++) {
        result[i] = rgBstrNames[i].getValue();
        OLEAUTO.SysFreeString(rgBstrNames[i]);
    }
    return result;
}
Also used : BSTR(com.sun.jna.platform.win32.WTypes.BSTR) UINTByReference(com.sun.jna.platform.win32.WinDef.UINTByReference) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) UINT(com.sun.jna.platform.win32.WinDef.UINT)

Example 83 with HRESULT

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

the class Ole32Util method getGUIDFromString.

/**
	 * Convert a string to a GUID.
	 * @param guidString
	 *  String representation of a GUID, including { }.
	 * @return
	 *  A GUID.
	 */
public static GUID getGUIDFromString(String guidString) {
    GUID lpiid = new GUID();
    HRESULT hr = Ole32.INSTANCE.IIDFromString(guidString, lpiid);
    if (!hr.equals(W32Errors.S_OK)) {
        throw new RuntimeException(hr.toString());
    }
    return lpiid;
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) GUID(com.sun.jna.platform.win32.Guid.GUID)

Example 84 with HRESULT

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

the class Ole32Util method generateGUID.

/**
	 * Generate a new GUID.
	 * @return
	 *  New GUID.
	 */
public static GUID generateGUID() {
    GUID pguid = new GUID();
    HRESULT hr = Ole32.INSTANCE.CoCreateGuid(pguid);
    if (!hr.equals(W32Errors.S_OK)) {
        throw new RuntimeException(hr.toString());
    }
    return pguid;
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) GUID(com.sun.jna.platform.win32.Guid.GUID)

Example 85 with HRESULT

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

the class ComEventCallbacks_Test method testComEventCallback.

@Test
public void testComEventCallback() throws InterruptedException {
    VARIANT.ByReference pVarResult = new VARIANT.ByReference();
    IntByReference puArgErr = new IntByReference();
    EXCEPINFO.ByReference pExcepInfo = new EXCEPINFO.ByReference();
    HRESULT hr;
    DISPPARAMS.ByReference pDispParams;
    pDispParams = new DISPPARAMS.ByReference();
    pDispParams.setArgs(new VARIANT[] { new VARIANT(true) });
    pDispParams.setRgdispidNamedArgs(new DISPID[] { OaIdl.DISPID_PROPERTYPUT });
    // Visible-Prioperty
    hr = ieDispatch.Invoke(dispIdVisible.getValue(), niid, lcid, propertyPutFlags, pDispParams, null, null, null);
    COMUtils.checkRC(hr);
    // query for ConnectionPointContainer
    Unknown unk = new Unknown(ieApp.getValue());
    PointerByReference ppCpc = new PointerByReference();
    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);
    final ConnectionPoint cp = new ConnectionPoint(ppCp.getValue());
    IID cp_iid = new IID();
    hr = cp.GetConnectionInterface(cp_iid);
    COMUtils.checkRC(hr);
    final DWebBrowserEvents2_Listener listener = new DWebBrowserEvents2_Listener();
    final DWORDByReference pdwCookie = new DWORDByReference();
    HRESULT hr1 = cp.Advise(listener, pdwCookie);
    COMUtils.checkRC(hr1);
    // Advise make several callbacks into the object passed in - at this
    // point QueryInterface must have be called multiple times
    Assert.assertTrue(listener.QueryInterface_called);
    // Call Navigate with URL https://github.com/java-native-access/jna
    String navigateURL = "https://github.com/java-native-access/jna";
    String blockedURL = "http://www.google.de";
    VARIANT[] arguments = new VARIANT[] { new VARIANT(navigateURL) };
    pDispParams = new DISPPARAMS.ByReference();
    pDispParams.setArgs(arguments);
    hr = ieDispatch.Invoke(dispIdNavigate.getValue(), niid, lcid, methodFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
    COMUtils.checkRC(hr, pExcepInfo, puArgErr);
    for (int i = 0; i < 10; i++) {
        if (listener.navigateComplete2Called) {
            break;
        }
        Thread.sleep(1000);
    }
    // At this point the call to Navigate before should be complete
    Assert.assertTrue(listener.navigateComplete2Called);
    // Navidate complete should have brought us to github
    Assert.assertEquals(navigateURL, listener.navigateComplete2String);
    listener.navigateComplete2Called = false;
    listener.navigateComplete2String = null;
    listener.blockNavigation = true;
    arguments = new VARIANT[] { new VARIANT(blockedURL) };
    pDispParams = new DISPPARAMS.ByReference();
    pDispParams.setArgs(arguments);
    hr = ieDispatch.Invoke(dispIdNavigate.getValue(), niid, lcid, methodFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
    COMUtils.checkRC(hr, pExcepInfo, puArgErr);
    // wait 10 seconds to ensure navigation won't happen
    for (int i = 0; i < 10; i++) {
        if (listener.navigateComplete2Called) {
            break;
        }
        Thread.sleep(1000);
    }
    // Naviation will be blocked - so NavigateComplete can't be called
    Assert.assertFalse("NavigateComplete Handler was called although it should be blocked", listener.navigateComplete2Called);
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) IID(com.sun.jna.platform.win32.Guid.IID) REFIID(com.sun.jna.platform.win32.Guid.REFIID) DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) EXCEPINFO(com.sun.jna.platform.win32.OaIdl.EXCEPINFO) REFIID(com.sun.jna.platform.win32.Guid.REFIID) WString(com.sun.jna.WString) DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) DISPIDByReference(com.sun.jna.platform.win32.OaIdl.DISPIDByReference) VARIANT_BOOLByReference(com.sun.jna.platform.win32.OaIdl.VARIANT_BOOLByReference) UINTByReference(com.sun.jna.platform.win32.WinDef.UINTByReference) PointerByReference(com.sun.jna.ptr.PointerByReference) IntByReference(com.sun.jna.ptr.IntByReference) VARIANT(com.sun.jna.platform.win32.Variant.VARIANT) PointerByReference(com.sun.jna.ptr.PointerByReference) DISPPARAMS(com.sun.jna.platform.win32.OleAuto.DISPPARAMS) 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