Search in sources :

Example 1 with LCID

use of com.sun.jna.platform.win32.WinDef.LCID in project jna by java-native-access.

the class ITypeLibTest method loadShellTypeLib.

private ITypeLib loadShellTypeLib() {
    CLSID.ByReference clsid = new CLSID.ByReference();
    // get CLSID from string
    HRESULT hr = Ole32.INSTANCE.CLSIDFromString(new WString(SHELL_CLSID), clsid);
    assertTrue(COMUtils.SUCCEEDED(hr));
    // get user default lcid
    LCID lcid = Kernel32.INSTANCE.GetUserDefaultLCID();
    PointerByReference pShellTypeLib = new PointerByReference();
    // load typelib
    hr = OleAuto.INSTANCE.LoadRegTypeLib(clsid, SHELL_MAJOR, SHELL_MINOR, lcid, pShellTypeLib);
    assertTrue(COMUtils.SUCCEEDED(hr));
    return new TypeLib(pShellTypeLib.getValue());
}
Also used : WString(com.sun.jna.WString) LCID(com.sun.jna.platform.win32.WinDef.LCID) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) CLSID(com.sun.jna.platform.win32.Guid.CLSID) PointerByReference(com.sun.jna.ptr.PointerByReference) PointerByReference(com.sun.jna.ptr.PointerByReference) USHORTByReference(com.sun.jna.platform.win32.WinDef.USHORTByReference)

Example 2 with LCID

use of com.sun.jna.platform.win32.WinDef.LCID 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 3 with LCID

use of com.sun.jna.platform.win32.WinDef.LCID in project jna by java-native-access.

the class OleAutoTest method testLoadRegTypeLib.

public void testLoadRegTypeLib() {
    CLSID.ByReference clsid = new CLSID.ByReference();
    // get CLSID from string, Microsoft Scripting Engine
    HRESULT hr = Ole32.INSTANCE.CLSIDFromString(new WString("{420B2830-E718-11CF-893D-00A0C9054228}"), clsid);
    COMUtils.checkRC(hr);
    assertEquals(0, hr.intValue());
    // get user default lcid
    LCID lcid = Kernel32.INSTANCE.GetUserDefaultLCID();
    PointerByReference pWordTypeLib = new PointerByReference();
    // get typelib version 1.0
    hr = OleAuto.INSTANCE.LoadRegTypeLib(clsid, 1, 0, lcid, pWordTypeLib);
    COMUtils.checkRC(hr);
    assertEquals(0, hr.intValue());
}
Also used : WString(com.sun.jna.WString) LCID(com.sun.jna.platform.win32.WinDef.LCID) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) CLSID(com.sun.jna.platform.win32.Guid.CLSID) PointerByReference(com.sun.jna.ptr.PointerByReference) PointerByReference(com.sun.jna.ptr.PointerByReference)

Example 4 with LCID

use of com.sun.jna.platform.win32.WinDef.LCID in project jna by java-native-access.

the class ConfigurateLCID_Test method before.

@Before
public void before() {
    Ole32.INSTANCE.CoInitializeEx(Pointer.NULL, Ole32.COINIT_MULTITHREADED);
    this.factory = new Factory();
    // switch to english locale (the test is only valid if office is
    // installed in a non-english locale
    this.factory.setLCID(new LCID(0x0409));
}
Also used : LCID(com.sun.jna.platform.win32.WinDef.LCID) Before(org.junit.Before)

Example 5 with LCID

use of com.sun.jna.platform.win32.WinDef.LCID in project jna by java-native-access.

the class CallbackProxy method invokeOnThread.

void invokeOnThread(final DISPID dispIdMember, final REFIID riid, LCID lcid, WORD wFlags, final DISPPARAMS.ByReference pDispParams) {
    VARIANT[] arguments = pDispParams.getArgs();
    final Method eventMethod = CallbackProxy.this.dsipIdMap.get(dispIdMember);
    if (eventMethod == null) {
        CallbackProxy.this.comEventCallbackListener.errorReceivingCallbackEvent("No method found with dispId = " + dispIdMember, null);
        return;
    }
    /**
             * DISPPARAMs provides two different ways to pass arguments.
             *
             * Arguments can be passed as a linear list with all arguments
             * specified to a certain position (positional) or the position of
             * an argument can be passed via the rgdispidNamedArgs array
             * (named).
             *
             * pDispParams.rgvarg (length in pDispParams.cArgs) contains all
             * arguments (named + position based)
             *
             * pDispParams.rgdispidNamedArgs (length in pDispParams.cNamedArgs)
             * contains the named parameters as DISPIDs - the DISPIDs are the
             * target index in the method signature (zero based).
             *
             * Each entry in pDispParams.rgvarg is either position based or name
             * based and the position bases arguments are passed in reverse
             * order, so getting this:
             *
             * rgvarg = ["arg1", "arg2", "arg3", "arg4", "arg5"]
             * rgdispidNamedArgs = [3, 4]
             *
             * Would lead to this paramater array in the handler:
             *
             * ["arg5", "arg4", "arg3", "arg1", "arg2"]
             *
             * See also:
             * https://msdn.microsoft.com/de-de/library/windows/desktop/ms221653%28v=vs.85%29.aspx
             */
    // Arguments are converted to the JAVA side and IDispatch Interfaces
    // are wrapped into an ProxyObject if so requested.
    //
    // Out-Parameter need to be specified as VARIANT, VARIANT args are
    // not converted, so COM memory allocation rules apply.
    DISPID[] positionMap = pDispParams.getRgdispidNamedArgs();
    final Class<?>[] paramTypes = eventMethod.getParameterTypes();
    final Object[] params = new Object[paramTypes.length];
    // Handle position based parameters first
    for (int i = 0; i < params.length && (arguments.length - positionMap.length - i) > 0; i++) {
        Class targetClass = paramTypes[i];
        Variant.VARIANT varg = arguments[arguments.length - i - 1];
        params[i] = Convert.toJavaObject(varg, targetClass, factory, true, false);
    }
    for (int i = 0; i < positionMap.length; i++) {
        int targetPosition = positionMap[i].intValue();
        if (targetPosition >= params.length) {
            // If less parameters are mapped then supplied, ignore
            continue;
        }
        Class targetClass = paramTypes[targetPosition];
        Variant.VARIANT varg = arguments[i];
        params[targetPosition] = Convert.toJavaObject(varg, targetClass, factory, true, false);
    }
    // exception occurs while doing the call into the target method
    for (int i = 0; i < params.length; i++) {
        if (params[i] == null && paramTypes[i].isPrimitive()) {
            if (paramTypes[i].equals(boolean.class)) {
                params[i] = DEFAULT_BOOLEAN;
            } else if (paramTypes[i].equals(byte.class)) {
                params[i] = DEFAULT_BYTE;
            } else if (paramTypes[i].equals(short.class)) {
                params[i] = DEFAULT_SHORT;
            } else if (paramTypes[i].equals(int.class)) {
                params[i] = DEFAULT_INT;
            } else if (paramTypes[i].equals(long.class)) {
                params[i] = DEFAULT_LONG;
            } else if (paramTypes[i].equals(float.class)) {
                params[i] = DEFAULT_FLOAT;
            } else if (paramTypes[i].equals(double.class)) {
                params[i] = DEFAULT_DOUBLE;
            } else {
                throw new IllegalArgumentException("Class type " + paramTypes[i].getName() + " not mapped to primitive default value.");
            }
        }
    }
    try {
        eventMethod.invoke(comEventCallbackListener, params);
    } catch (Exception e) {
        List<String> decodedClassNames = new ArrayList<String>(params.length);
        for (Object o : params) {
            if (o == null) {
                decodedClassNames.add("NULL");
            } else {
                decodedClassNames.add(o.getClass().getName());
            }
        }
        CallbackProxy.this.comEventCallbackListener.errorReceivingCallbackEvent("Exception invoking method " + eventMethod + " supplied: " + decodedClassNames.toString(), e);
    }
}
Also used : DISPID(com.sun.jna.platform.win32.OaIdl.DISPID) Method(java.lang.reflect.Method) WString(com.sun.jna.WString) VARIANT(com.sun.jna.platform.win32.Variant.VARIANT) COMException(com.sun.jna.platform.win32.COM.COMException) VARIANT(com.sun.jna.platform.win32.Variant.VARIANT) Variant(com.sun.jna.platform.win32.Variant) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

WString (com.sun.jna.WString)5 HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)5 PointerByReference (com.sun.jna.ptr.PointerByReference)5 VARIANT (com.sun.jna.platform.win32.Variant.VARIANT)4 LCID (com.sun.jna.platform.win32.WinDef.LCID)4 CLSID (com.sun.jna.platform.win32.Guid.CLSID)2 REFIID (com.sun.jna.platform.win32.Guid.REFIID)2 DISPIDByReference (com.sun.jna.platform.win32.OaIdl.DISPIDByReference)2 EXCEPINFO (com.sun.jna.platform.win32.OaIdl.EXCEPINFO)2 VARIANT_BOOLByReference (com.sun.jna.platform.win32.OaIdl.VARIANT_BOOLByReference)2 DISPPARAMS (com.sun.jna.platform.win32.OleAuto.DISPPARAMS)2 DWORDByReference (com.sun.jna.platform.win32.WinDef.DWORDByReference)2 UINTByReference (com.sun.jna.platform.win32.WinDef.UINTByReference)2 IntByReference (com.sun.jna.ptr.IntByReference)2 Before (org.junit.Before)2 COMException (com.sun.jna.platform.win32.COM.COMException)1 Factory (com.sun.jna.platform.win32.COM.util.Factory)1 ComExcel_Application (com.sun.jna.platform.win32.COM.util.office.excel.ComExcel_Application)1 ComIApplication (com.sun.jna.platform.win32.COM.util.office.excel.ComIApplication)1 ComIWorkbook (com.sun.jna.platform.win32.COM.util.office.excel.ComIWorkbook)1