use of com.sun.jna.platform.win32.Variant in project jna by java-native-access.
the class IFileSystem3 method testConvertBoolean.
@Test
public void testConvertBoolean() {
VARIANT_BOOL testVariantBOOL = new VARIANT_BOOL(true);
VARIANT resultVariantBOOL = Convert.toVariant(testVariantBOOL);
assertEquals(true, resultVariantBOOL.booleanValue());
assertEquals(true, Convert.toJavaObject(resultVariantBOOL, Object.class, fact, false, false));
assertEquals(true, Convert.toJavaObject(resultVariantBOOL, Boolean.class, fact, false, false));
assertEquals(true, Convert.toJavaObject(resultVariantBOOL, boolean.class, fact, false, false));
BOOL testBOOL = new BOOL(true);
VARIANT resultBOOL = Convert.toVariant(testBOOL);
assertEquals(true, resultBOOL.booleanValue());
assertEquals(true, Convert.toJavaObject(resultBOOL, Object.class, fact, false, false));
assertEquals(true, Convert.toJavaObject(resultBOOL, Boolean.class, fact, false, false));
assertEquals(true, Convert.toJavaObject(resultBOOL, boolean.class, fact, false, false));
Boolean testBooleanObj = true;
VARIANT resultBooleanObj = Convert.toVariant(testBooleanObj);
boolean testBoolean = true;
VARIANT resultBoolean = Convert.toVariant(testBoolean);
assertEquals(true, resultBooleanObj.booleanValue());
assertEquals(true, resultBoolean.booleanValue());
assertEquals(true, Convert.toJavaObject(resultBooleanObj, Object.class, fact, false, false));
assertEquals(true, Convert.toJavaObject(resultBoolean, Object.class, fact, false, false));
assertEquals(true, Convert.toJavaObject(resultBooleanObj, boolean.class, fact, false, false));
assertEquals(true, Convert.toJavaObject(resultBoolean, boolean.class, fact, false, false));
assertEquals(true, Convert.toJavaObject(resultBooleanObj, Boolean.class, fact, false, false));
assertEquals(true, Convert.toJavaObject(resultBoolean, Boolean.class, fact, false, false));
}
use of com.sun.jna.platform.win32.Variant in project jna by java-native-access.
the class IFileSystem3 method testConvertDate.
@Test
public void testConvertDate() {
Date testDate = new Date(2015 - 1900, 1, 1, 9, 0, 0);
VARIANT resultDate = Convert.toVariant(testDate);
DATE testDATE = new DATE(testDate);
VARIANT resultDATE = Convert.toVariant(testDATE);
assertEquals(testDate, resultDate.dateValue());
assertEquals(testDate, resultDATE.dateValue());
assertEquals(testDate, Convert.toJavaObject(resultDate, Object.class, fact, false, false));
assertEquals(testDate, Convert.toJavaObject(resultDATE, Object.class, fact, false, false));
assertEquals(testDate, Convert.toJavaObject(resultDate, Date.class, fact, false, false));
assertEquals(testDate, Convert.toJavaObject(resultDATE, Date.class, fact, false, false));
}
use of com.sun.jna.platform.win32.Variant in project jna by java-native-access.
the class IFileSystem3 method testConvertVariant.
@Test
public void testConvertVariant() {
VARIANT testValue = new Variant.VARIANT(42);
VARIANT resultVariant = Convert.toVariant(testValue);
assertSame(testValue, resultVariant);
assertSame(testValue, Convert.toJavaObject(resultVariant, VARIANT.class, fact, false, false));
assertSame(42, Convert.toJavaObject(testValue, Object.class, fact, false, false));
}
use of com.sun.jna.platform.win32.Variant in project jna by java-native-access.
the class HybdridCOMInvocationTest method testOfficeInvocationDemonstration.
public void testOfficeInvocationDemonstration() {
// THIS IS NOT A TEST
//
// This reproduces the problem by using the dispatch directly.
PointerByReference pDispatch = new PointerByReference();
HRESULT hr = Ole32.INSTANCE.CoCreateInstance(CLSID_WORD, null, WTypes.CLSCTX_SERVER, IID_APPLICATION, pDispatch);
if (!COMUtils.SUCCEEDED(hr)) {
LOG.log(Level.INFO, "HybdridCOMInvocationTest test was not run, MS Word object could not be instantiated.");
return;
}
Dispatch dp = new Dispatch(pDispatch.getValue());
// DispID of InchesToPoints
DISPID dispId = new OaIdl.DISPID(0x00000172);
// Interface _Application of MS Word type library
WinDef.LCID LOCALE_SYSTEM_DEFAULT = Kernel32.INSTANCE.GetSystemDefaultLCID();
Variant.VARIANT.ByReference result = new Variant.VARIANT.ByReference();
OaIdl.EXCEPINFO.ByReference pExcepInfo = new OaIdl.EXCEPINFO.ByReference();
IntByReference puArgErr = new IntByReference();
WORD wFlagsMethod = new WinDef.WORD(OleAuto.DISPATCH_METHOD);
WORD wFlagsGet = new WinDef.WORD(OleAuto.DISPATCH_PROPERTYGET);
WORD wFlagsCombined = new WinDef.WORD(OleAuto.DISPATCH_METHOD | OleAuto.DISPATCH_PROPERTYGET);
OleAuto.DISPPARAMS.ByReference pDispParams = new OleAuto.DISPPARAMS.ByReference();
VARIANT[] params = new VARIANT[] { new VARIANT(1f) };
pDispParams.setArgs(params);
// Call InchesToPoints as a method
hr = dp.Invoke(dispId, new REFIID(Guid.IID_NULL), LOCALE_SYSTEM_DEFAULT, wFlagsMethod, pDispParams, result, pExcepInfo, puArgErr);
assertTrue(COMUtils.FAILED(hr));
// Call InchesToPoints as a property getter
hr = dp.Invoke(dispId, new REFIID(Guid.IID_NULL), LOCALE_SYSTEM_DEFAULT, wFlagsGet, pDispParams, result, pExcepInfo, puArgErr);
assertTrue(COMUtils.FAILED(hr));
// Call InchesToPoints as a hybrid
hr = dp.Invoke(dispId, new REFIID(Guid.IID_NULL), LOCALE_SYSTEM_DEFAULT, wFlagsCombined, pDispParams, result, pExcepInfo, puArgErr);
assertTrue(COMUtils.SUCCEEDED(hr));
assertEquals(72.0f, result.floatValue());
}
use of com.sun.jna.platform.win32.Variant in project jna by java-native-access.
the class ProxyObject method invokeMethod.
@Override
public <T> T invokeMethod(Class<T> returnType, DISPID dispID, Object... args) {
assert COMUtils.comIsInitialized() : "COM not initialized";
VARIANT[] vargs;
if (null == args) {
vargs = new VARIANT[0];
} else {
vargs = new VARIANT[args.length];
}
for (int i = 0; i < vargs.length; ++i) {
vargs[i] = Convert.toVariant(args[i]);
}
Variant.VARIANT.ByReference result = new Variant.VARIANT.ByReference();
WinNT.HRESULT hr = this.oleMethod(OleAuto.DISPATCH_METHOD, result, this.getRawDispatch(), dispID, vargs);
for (int i = 0; i < vargs.length; i++) {
// Free value allocated by Convert#toVariant
Convert.free(vargs[i], args[i]);
}
COMUtils.checkRC(hr);
return (T) Convert.toJavaObject(result, returnType, factory, false, true);
}
Aggregations