Search in sources :

Example 16 with Variant

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));
}
Also used : VARIANT_BOOL(com.sun.jna.platform.win32.OaIdl.VARIANT_BOOL) BOOL(com.sun.jna.platform.win32.WinDef.BOOL) VARIANT_BOOL(com.sun.jna.platform.win32.OaIdl.VARIANT_BOOL) ComObject(com.sun.jna.platform.win32.COM.util.annotation.ComObject) VARIANT(com.sun.jna.platform.win32.Variant.VARIANT) Test(org.junit.Test)

Example 17 with Variant

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));
}
Also used : DATE(com.sun.jna.platform.win32.OaIdl.DATE) ComObject(com.sun.jna.platform.win32.COM.util.annotation.ComObject) VARIANT(com.sun.jna.platform.win32.Variant.VARIANT) Date(java.util.Date) Test(org.junit.Test)

Example 18 with Variant

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));
}
Also used : ComObject(com.sun.jna.platform.win32.COM.util.annotation.ComObject) VARIANT(com.sun.jna.platform.win32.Variant.VARIANT) Test(org.junit.Test)

Example 19 with Variant

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());
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) WORD(com.sun.jna.platform.win32.WinDef.WORD) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) DISPID(com.sun.jna.platform.win32.OaIdl.DISPID) Dispatch(com.sun.jna.platform.win32.COM.Dispatch) REFIID(com.sun.jna.platform.win32.Guid.REFIID) PointerByReference(com.sun.jna.ptr.PointerByReference) IntByReference(com.sun.jna.ptr.IntByReference) VARIANT(com.sun.jna.platform.win32.Variant.VARIANT) Variant(com.sun.jna.platform.win32.Variant) OleAuto(com.sun.jna.platform.win32.OleAuto) PointerByReference(com.sun.jna.ptr.PointerByReference) WinDef(com.sun.jna.platform.win32.WinDef) OaIdl(com.sun.jna.platform.win32.OaIdl)

Example 20 with Variant

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);
}
Also used : Variant(com.sun.jna.platform.win32.Variant) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) WinNT(com.sun.jna.platform.win32.WinNT) VARIANT(com.sun.jna.platform.win32.Variant.VARIANT) WinNT(com.sun.jna.platform.win32.WinNT) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) VARIANT(com.sun.jna.platform.win32.Variant.VARIANT) DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) DISPIDByReference(com.sun.jna.platform.win32.OaIdl.DISPIDByReference) PointerByReference(com.sun.jna.ptr.PointerByReference) IntByReference(com.sun.jna.ptr.IntByReference) ConnectionPoint(com.sun.jna.platform.win32.COM.ConnectionPoint)

Aggregations

VARIANT (com.sun.jna.platform.win32.Variant.VARIANT)37 HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)12 ComObject (com.sun.jna.platform.win32.COM.util.annotation.ComObject)10 Test (org.junit.Test)10 DISPIDByReference (com.sun.jna.platform.win32.OaIdl.DISPIDByReference)6 SAFEARRAY (com.sun.jna.platform.win32.OaIdl.SAFEARRAY)6 IntByReference (com.sun.jna.ptr.IntByReference)6 PointerByReference (com.sun.jna.ptr.PointerByReference)6 REFIID (com.sun.jna.platform.win32.Guid.REFIID)5 DATE (com.sun.jna.platform.win32.OaIdl.DATE)5 BSTR (com.sun.jna.platform.win32.WTypes.BSTR)5 SHORT (com.sun.jna.platform.win32.WinDef.SHORT)5 IConnectionPoint (com.sun.jna.platform.win32.COM.util.IConnectionPoint)4 Variant (com.sun.jna.platform.win32.Variant)4 VT_VARIANT (com.sun.jna.platform.win32.Variant.VT_VARIANT)4 WinDef (com.sun.jna.platform.win32.WinDef)4 Pointer (com.sun.jna.Pointer)3 WString (com.sun.jna.WString)3 COMException (com.sun.jna.platform.win32.COM.COMException)3 ConnectionPoint (com.sun.jna.platform.win32.COM.ConnectionPoint)3