Search in sources :

Example 1 with FindName

use of com.sun.jna.platform.win32.COM.TypeLibUtil.FindName in project jna by java-native-access.

the class TypeLibUtilTest method testFindName.

public void testFindName() {
    // Test is modelled after ITypeLibTest#testFindName
    TypeLibUtil shellTypeLib = loadShellTypeLib();
    String memberValue = "count";
    String memberValueOk = "Count";
    FindName result = shellTypeLib.FindName(memberValue, 0, (short) 100);
    // 2 matches come from manual tests
    assertEquals(2, result.getFound());
    // Check that function return corrected member name (Count) - see uppercase C
    assertEquals(memberValueOk, result.getNameBuf());
    // There have to be as many pointers as reported by pcFound
    ITypeInfo[] typelib = result.getTInfo();
    assertEquals(2, typelib.length);
    assertNotNull(typelib[0]);
    assertNotNull(typelib[1]);
    PointerByReference pbr = new PointerByReference();
    HRESULT hr = typelib[1].GetTypeAttr(pbr);
    assertTrue(COMUtils.SUCCEEDED(hr));
    OaIdl.TYPEATTR pTypeAttr = new OaIdl.TYPEATTR(pbr.getValue());
    // Either interface FolderItemVerbs ({1F8352C0-50B0-11CF-960C-0080C7F4EE85})
    // or FolderItems ({744129E0-CBE5-11CE-8350-444553540000})
    String typeGUID = pTypeAttr.guid.toGuidString();
    assertTrue(typeGUID.equals("{1F8352C0-50B0-11CF-960C-0080C7F4EE85}") || typeGUID.equals("{744129E0-CBE5-11CE-8350-444553540000}"));
    typelib[1].ReleaseTypeAttr(pTypeAttr);
}
Also used : TYPEATTR(com.sun.jna.platform.win32.OaIdl.TYPEATTR) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) PointerByReference(com.sun.jna.ptr.PointerByReference) TYPEATTR(com.sun.jna.platform.win32.OaIdl.TYPEATTR) OaIdl(com.sun.jna.platform.win32.OaIdl) FindName(com.sun.jna.platform.win32.COM.TypeLibUtil.FindName)

Example 2 with FindName

use of com.sun.jna.platform.win32.COM.TypeLibUtil.FindName in project jna by java-native-access.

the class TypeLibUtil method FindName.

/**
     * Find name.
     * 
     * @param name
     *            the name
     * @param hashVal
     *            the hash val or 0 if unknown
     * @param maxResult
     *            maximum number of items to search
     * @return the find name
     */
public FindName FindName(String name, int hashVal, short maxResult) {
    Pointer p = Ole32.INSTANCE.CoTaskMemAlloc((name.length() + 1L) * Native.WCHAR_SIZE);
    WTypes.LPOLESTR olestr = new WTypes.LPOLESTR(p);
    olestr.setValue(name);
    ULONG lHashVal = new ULONG(hashVal);
    USHORTByReference pcFound = new USHORTByReference(maxResult);
    Pointer[] ppTInfo = new Pointer[maxResult];
    MEMBERID[] rgMemId = new MEMBERID[maxResult];
    HRESULT hr = this.typelib.FindName(olestr, lHashVal, ppTInfo, rgMemId, pcFound);
    COMUtils.checkRC(hr);
    FindName findName = new FindName(olestr.getValue(), ppTInfo, rgMemId, pcFound.getValue().shortValue());
    Ole32.INSTANCE.CoTaskMemFree(p);
    return findName;
}
Also used : ULONG(com.sun.jna.platform.win32.WinDef.ULONG) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) LPOLESTR(com.sun.jna.platform.win32.WTypes.LPOLESTR) MEMBERID(com.sun.jna.platform.win32.OaIdl.MEMBERID) LPOLESTR(com.sun.jna.platform.win32.WTypes.LPOLESTR) USHORTByReference(com.sun.jna.platform.win32.WinDef.USHORTByReference) Pointer(com.sun.jna.Pointer) WTypes(com.sun.jna.platform.win32.WTypes)

Aggregations

HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)2 Pointer (com.sun.jna.Pointer)1 FindName (com.sun.jna.platform.win32.COM.TypeLibUtil.FindName)1 OaIdl (com.sun.jna.platform.win32.OaIdl)1 MEMBERID (com.sun.jna.platform.win32.OaIdl.MEMBERID)1 TYPEATTR (com.sun.jna.platform.win32.OaIdl.TYPEATTR)1 WTypes (com.sun.jna.platform.win32.WTypes)1 LPOLESTR (com.sun.jna.platform.win32.WTypes.LPOLESTR)1 ULONG (com.sun.jna.platform.win32.WinDef.ULONG)1 USHORTByReference (com.sun.jna.platform.win32.WinDef.USHORTByReference)1 PointerByReference (com.sun.jna.ptr.PointerByReference)1