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());
}
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);
}
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());
}
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));
}
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);
}
}
Aggregations