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