Search in sources :

Example 6 with BSTRByReference

use of com.sun.jna.platform.win32.WTypes.BSTRByReference in project jna by java-native-access.

the class TypeInfoUtil method getDocumentation.

/**
     * Gets the documentation.
     * 
     * @param memid
     *            the memid
     * @return the documentation
     */
public TypeInfoDoc getDocumentation(MEMBERID memid) {
    BSTRByReference pBstrName = new BSTRByReference();
    BSTRByReference pBstrDocString = new BSTRByReference();
    DWORDByReference pdwHelpContext = new DWORDByReference();
    BSTRByReference pBstrHelpFile = new BSTRByReference();
    HRESULT hr = this.typeInfo.GetDocumentation(memid, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
    COMUtils.checkRC(hr);
    TypeInfoDoc TypeInfoDoc = new TypeInfoDoc(pBstrName.getString(), pBstrDocString.getString(), pdwHelpContext.getValue().intValue(), pBstrHelpFile.getString());
    OLEAUTO.SysFreeString(pBstrName.getValue());
    OLEAUTO.SysFreeString(pBstrDocString.getValue());
    OLEAUTO.SysFreeString(pBstrHelpFile.getValue());
    return TypeInfoDoc;
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) BSTRByReference(com.sun.jna.platform.win32.WTypes.BSTRByReference)

Example 7 with BSTRByReference

use of com.sun.jna.platform.win32.WTypes.BSTRByReference in project jna by java-native-access.

the class TypeInfoUtil method GetMops.

/**
     * Gets the mops.
     * 
     * @param memid
     *            the memid
     * @return the string
     */
public String GetMops(MEMBERID memid) {
    BSTRByReference pBstrMops = new BSTRByReference();
    HRESULT hr = this.typeInfo.GetMops(memid, pBstrMops);
    COMUtils.checkRC(hr);
    return pBstrMops.getString();
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) BSTRByReference(com.sun.jna.platform.win32.WTypes.BSTRByReference)

Example 8 with BSTRByReference

use of com.sun.jna.platform.win32.WTypes.BSTRByReference in project jna by java-native-access.

the class ITypeInfoTest method testGetDllEntry.

@Test
@Ignore("Needs a DLL that contains code")
public void testGetDllEntry() {
    ITypeInfo[] typeInfos = getTypeInfos();
    MEMBERID memid = new MEMBERID(0);
    BSTRByReference pBstrDllName = new BSTRByReference();
    BSTRByReference pBstrName = new BSTRByReference();
    WORDByReference pwOrdinal = new WORDByReference();
    for (ITypeInfo typeInfo : typeInfos) {
        HRESULT hr = typeInfo.GetDllEntry(memid, INVOKEKIND.INVOKE_FUNC, pBstrDllName, pBstrName, pwOrdinal);
        if (COMUtils.SUCCEEDED(hr)) {
            //System.out.println("pwOrdinal: " + pwOrdinal.getValue());
            return;
        }
    }
    throw new RuntimeException("Didn't find Dll entry for member in any of the type infos");
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) MEMBERID(com.sun.jna.platform.win32.OaIdl.MEMBERID) BSTRByReference(com.sun.jna.platform.win32.WTypes.BSTRByReference) DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) WORDByReference(com.sun.jna.platform.win32.WinDef.WORDByReference) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with BSTRByReference

use of com.sun.jna.platform.win32.WTypes.BSTRByReference in project jna by java-native-access.

the class VariantTest method testVariantConstructors.

public void testVariantConstructors() {
    VARIANT variant;
    // skipped: BSTRByReference constructor
    // skipped: empty constructor
    // skipped: pointer constructor
    // skipped: IDispatch constructor
    String testString = "TeST$รถ";
    BSTR bstr = OleAuto.INSTANCE.SysAllocString(testString);
    variant = new VARIANT(bstr);
    assertThat(variant.getValue(), instanceOf(BSTR.class));
    assertThat(((BSTR) variant.getValue()).getValue(), equalTo(testString));
    assertThat(variant.stringValue(), equalTo(testString));
    variant = new VARIANT(testString);
    assertThat(variant.getValue(), instanceOf(BSTR.class));
    assertThat(((BSTR) variant.getValue()).getValue(), equalTo(testString));
    assertThat(variant.stringValue(), equalTo(testString));
    OleAuto.INSTANCE.SysFreeString(bstr);
    OleAuto.INSTANCE.SysFreeString((BSTR) variant.getValue());
    BOOL boolTrue = new WinDef.BOOL(true);
    variant = new VARIANT(Variant.VARIANT_TRUE);
    assertThat(variant.getValue(), instanceOf(VARIANT_BOOL.class));
    assertThat(((VARIANT_BOOL) variant.getValue()).shortValue(), equalTo((short) 0xFFFF));
    assertThat(variant.booleanValue(), equalTo(true));
    variant = new VARIANT(boolTrue);
    assertThat(variant.getValue(), instanceOf(VARIANT_BOOL.class));
    assertThat(((VARIANT_BOOL) variant.getValue()).shortValue(), equalTo((short) 0xFFFF));
    assertThat(variant.booleanValue(), equalTo(true));
    int testInt = 4223;
    LONG testIntWin = new LONG(testInt);
    variant = new VARIANT(testIntWin);
    assertThat(variant.getValue(), instanceOf(LONG.class));
    assertThat(((LONG) variant.getValue()).intValue(), equalTo(testInt));
    assertThat(variant.intValue(), equalTo(testInt));
    variant = new VARIANT(testInt);
    assertThat(variant.getValue(), instanceOf(LONG.class));
    assertThat(((LONG) variant.getValue()).intValue(), equalTo(testInt));
    assertThat(variant.intValue(), equalTo(testInt));
    short testShort = 23;
    SHORT testShortWin = new SHORT(testShort);
    variant = new VARIANT(testShortWin);
    assertThat(variant.getValue(), instanceOf(SHORT.class));
    assertThat(((SHORT) variant.getValue()).shortValue(), equalTo(testShort));
    assertThat(variant.shortValue(), equalTo(testShort));
    variant = new VARIANT(testShort);
    assertThat(variant.getValue(), instanceOf(SHORT.class));
    assertThat(((SHORT) variant.getValue()).shortValue(), equalTo(testShort));
    assertThat(variant.shortValue(), equalTo(testShort));
    long testLong = 4223L + Integer.MAX_VALUE;
    variant = new VARIANT(testLong);
    assertThat(variant.getValue(), instanceOf(LONGLONG.class));
    assertThat(((LONGLONG) variant.getValue()).longValue(), equalTo(testLong));
    assertThat(variant.longValue(), equalTo(testLong));
    Date testDate = new Date(2042 - 1900, 2, 3, 23, 0, 0);
    variant = new VARIANT(testDate);
    assertThat(variant.getValue(), instanceOf(DATE.class));
    assertThat(variant.dateValue(), equalTo(testDate));
    byte testByte = 42;
    BYTE testByteWin = new BYTE(testByte);
    CHAR testByteWin2 = new CHAR(testByte);
    variant = new VARIANT(testByte);
    assertThat(variant.getValue(), instanceOf(BYTE.class));
    assertThat(((BYTE) variant.getValue()).byteValue(), equalTo(testByte));
    assertThat(variant.byteValue(), equalTo(testByte));
    variant = new VARIANT(testByteWin);
    assertThat(variant.getValue(), instanceOf(BYTE.class));
    assertThat(((BYTE) variant.getValue()).byteValue(), equalTo(testByte));
    assertThat(variant.byteValue(), equalTo(testByte));
    variant = new VARIANT(testByteWin2);
    assertThat(variant.getValue(), instanceOf(CHAR.class));
    assertThat(((CHAR) variant.getValue()).byteValue(), equalTo(testByte));
    assertThat(variant.byteValue(), equalTo(testByte));
    variant = new VARIANT(testByteWin2);
    assertThat(variant.getValue(), instanceOf(CHAR.class));
    assertThat(((CHAR) variant.getValue()).byteValue(), equalTo(testByte));
    assertThat(variant.byteValue(), equalTo(testByte));
    double testDouble = 42.23;
    variant = new VARIANT(testDouble);
    assertThat(variant.getValue(), instanceOf(Double.class));
    // If this fails introduce comparison with range
    assertThat(variant.doubleValue(), equalTo(testDouble));
    float testFloat = 42.23f;
    variant = new VARIANT(testFloat);
    assertThat(variant.getValue(), instanceOf(Float.class));
    // If this fails introduce comparison with range
    assertThat(variant.floatValue(), equalTo(testFloat));
    char testChar = 42 + Short.MAX_VALUE;
    variant = new VARIANT(testChar);
    assertThat(variant.getValue(), instanceOf(USHORT.class));
    assertThat(((USHORT) variant.getValue()).intValue(), equalTo((int) testChar));
    assertThat(variant.intValue(), equalTo((int) testChar));
}
Also used : VARIANT_BOOL(com.sun.jna.platform.win32.OaIdl.VARIANT_BOOL) CHAR(com.sun.jna.platform.win32.WinDef.CHAR) VARIANT(com.sun.jna.platform.win32.Variant.VARIANT) Date(java.util.Date) SHORT(com.sun.jna.platform.win32.WinDef.SHORT) USHORT(com.sun.jna.platform.win32.WinDef.USHORT) BSTR(com.sun.jna.platform.win32.WTypes.BSTR) DATE(com.sun.jna.platform.win32.OaIdl.DATE) LONGLONG(com.sun.jna.platform.win32.WinDef.LONGLONG) VARIANT_BOOL(com.sun.jna.platform.win32.OaIdl.VARIANT_BOOL) BOOL(com.sun.jna.platform.win32.WinDef.BOOL) BYTE(com.sun.jna.platform.win32.WinDef.BYTE) USHORT(com.sun.jna.platform.win32.WinDef.USHORT) LONG(com.sun.jna.platform.win32.WinDef.LONG) LONGLONG(com.sun.jna.platform.win32.WinDef.LONGLONG)

Aggregations

BSTRByReference (com.sun.jna.platform.win32.WTypes.BSTRByReference)7 HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)7 DWORDByReference (com.sun.jna.platform.win32.WinDef.DWORDByReference)5 MEMBERID (com.sun.jna.platform.win32.OaIdl.MEMBERID)3 Test (org.junit.Test)3 WORDByReference (com.sun.jna.platform.win32.WinDef.WORDByReference)2 Dispatch (com.sun.jna.platform.win32.COM.Dispatch)1 IEnumMoniker (com.sun.jna.platform.win32.COM.IEnumMoniker)1 Moniker (com.sun.jna.platform.win32.COM.Moniker)1 DATE (com.sun.jna.platform.win32.OaIdl.DATE)1 VARIANT_BOOL (com.sun.jna.platform.win32.OaIdl.VARIANT_BOOL)1 VARIANT (com.sun.jna.platform.win32.Variant.VARIANT)1 BSTR (com.sun.jna.platform.win32.WTypes.BSTR)1 BOOL (com.sun.jna.platform.win32.WinDef.BOOL)1 BYTE (com.sun.jna.platform.win32.WinDef.BYTE)1 CHAR (com.sun.jna.platform.win32.WinDef.CHAR)1 LONG (com.sun.jna.platform.win32.WinDef.LONG)1 LONGLONG (com.sun.jna.platform.win32.WinDef.LONGLONG)1 SHORT (com.sun.jna.platform.win32.WinDef.SHORT)1 USHORT (com.sun.jna.platform.win32.WinDef.USHORT)1