Search in sources :

Example 6 with HRESULT

use of com.sun.jna.platform.win32.WinNT.HRESULT in project jna by java-native-access.

the class ITypeLibTest method loadShellTypeLib.

private ITypeLib loadShellTypeLib() {
    CLSID.ByReference clsid = new CLSID.ByReference();
    // get CLSID from string
    HRESULT hr = Ole32.INSTANCE.CLSIDFromString(new WString(SHELL_CLSID), clsid);
    assertTrue(COMUtils.SUCCEEDED(hr));
    // get user default lcid
    LCID lcid = Kernel32.INSTANCE.GetUserDefaultLCID();
    PointerByReference pShellTypeLib = new PointerByReference();
    // load typelib
    hr = OleAuto.INSTANCE.LoadRegTypeLib(clsid, SHELL_MAJOR, SHELL_MINOR, lcid, pShellTypeLib);
    assertTrue(COMUtils.SUCCEEDED(hr));
    return new TypeLib(pShellTypeLib.getValue());
}
Also used : WString(com.sun.jna.WString) LCID(com.sun.jna.platform.win32.WinDef.LCID) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) CLSID(com.sun.jna.platform.win32.Guid.CLSID) PointerByReference(com.sun.jna.ptr.PointerByReference) PointerByReference(com.sun.jna.ptr.PointerByReference) USHORTByReference(com.sun.jna.platform.win32.WinDef.USHORTByReference)

Example 7 with HRESULT

use of com.sun.jna.platform.win32.WinNT.HRESULT in project jna by java-native-access.

the class ITypeLibTest method testFindName.

public void testFindName() {
    ITypeLib shellTypeLib = loadShellTypeLib();
    // The found member is Count, search done with lowercase value to test
    // correct behaviour (search is case insensitive)
    String memberValue = "count";
    String memberValueOk = "Count";
    Pointer p = Ole32.INSTANCE.CoTaskMemAlloc((memberValue.length() + 1L) * Native.WCHAR_SIZE);
    WTypes.LPOLESTR olestr = new WTypes.LPOLESTR(p);
    olestr.setValue(memberValue);
    short maxResults = 100;
    ULONG lHashVal = new ULONG(0);
    USHORTByReference pcFound = new USHORTByReference(maxResults);
    Pointer[] pointers = new Pointer[maxResults];
    MEMBERID[] rgMemId = new MEMBERID[maxResults];
    HRESULT hr = shellTypeLib.FindName(olestr, lHashVal, pointers, rgMemId, pcFound);
    assertTrue(COMUtils.SUCCEEDED(hr));
    // If a reader can come up with more tests it would be appretiated,
    // the documentation is unclear what more can be expected
    // 2 matches come from manual tests
    assertTrue(pcFound.getValue().intValue() == 2);
    // Check that function return corrected member name (Count) - see uppercase C
    assertEquals(memberValueOk, olestr.getValue());
    // There have to be as many pointers as reported by pcFound
    assertNotNull(pointers[0]);
    assertNotNull(pointers[1]);
    // Might be flaky, contract only defined positions 0 -> (pcFound - 1)
    assertNull(pointers[2]);
    // Test access to second value
    TypeInfo secondTypeInfo = new TypeInfo(pointers[1]);
    PointerByReference pbr = new PointerByReference();
    hr = secondTypeInfo.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}"));
    secondTypeInfo.ReleaseTypeAttr(pTypeAttr);
    Ole32.INSTANCE.CoTaskMemFree(olestr.getPointer());
}
Also used : ULONG(com.sun.jna.platform.win32.WinDef.ULONG) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) MEMBERID(com.sun.jna.platform.win32.OaIdl.MEMBERID) Pointer(com.sun.jna.Pointer) WString(com.sun.jna.WString) WTypes(com.sun.jna.platform.win32.WTypes) PointerByReference(com.sun.jna.ptr.PointerByReference) USHORTByReference(com.sun.jna.platform.win32.WinDef.USHORTByReference) OaIdl(com.sun.jna.platform.win32.OaIdl)

Example 8 with HRESULT

use of com.sun.jna.platform.win32.WinNT.HRESULT in project jna by java-native-access.

the class ITypeLibTest method testGetTypeInfo.

public void testGetTypeInfo() {
    ITypeLib shellTypeLib = loadShellTypeLib();
    PointerByReference ppTInfo = new PointerByReference();
    HRESULT hr = shellTypeLib.GetTypeInfo(new UINT(0), ppTInfo);
    assertTrue(COMUtils.SUCCEEDED(hr));
//System.out.println("ITypeInfo: " + ppTInfo.toString());
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) PointerByReference(com.sun.jna.ptr.PointerByReference) UINT(com.sun.jna.platform.win32.WinDef.UINT)

Example 9 with HRESULT

use of com.sun.jna.platform.win32.WinNT.HRESULT in project jna by java-native-access.

the class ITypeLibTest method testIsName.

public void testIsName() {
    ITypeLib shellTypeLib = loadShellTypeLib();
    String memberValue = "Folder";
    Pointer p = Ole32.INSTANCE.CoTaskMemAlloc((memberValue.length() + 1L) * Native.WCHAR_SIZE);
    WTypes.LPOLESTR olestr = new WTypes.LPOLESTR(p);
    olestr.setValue(memberValue);
    WinDef.BOOLByReference boolByRef = new WinDef.BOOLByReference();
    HRESULT hr = shellTypeLib.IsName(olestr, new ULONG(0), boolByRef);
    assertTrue(COMUtils.SUCCEEDED(hr));
    // Folder is a member
    assertTrue(boolByRef.getValue().booleanValue());
    Ole32.INSTANCE.CoTaskMemFree(p);
}
Also used : ULONG(com.sun.jna.platform.win32.WinDef.ULONG) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) WinDef(com.sun.jna.platform.win32.WinDef) Pointer(com.sun.jna.Pointer) WString(com.sun.jna.WString) WTypes(com.sun.jna.platform.win32.WTypes)

Example 10 with HRESULT

use of com.sun.jna.platform.win32.WinNT.HRESULT in project jna by java-native-access.

the class RunningObjectTable_Test method IsRunning.

@Test
public void IsRunning() {
    PointerByReference pprot = new PointerByReference();
    HRESULT hr = Ole32.INSTANCE.GetRunningObjectTable(new DWORD(0), pprot);
    COMUtils.checkRC(hr);
    IRunningObjectTable rot = new RunningObjectTable(pprot.getValue());
//Can't yet be tested as IMoniker is not fully implemented,
//rot.IsRunning(pmkObjectName);
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) PointerByReference(com.sun.jna.ptr.PointerByReference) DWORD(com.sun.jna.platform.win32.WinDef.DWORD) Test(org.junit.Test)

Aggregations

HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)102 PointerByReference (com.sun.jna.ptr.PointerByReference)57 Test (org.junit.Test)26 REFIID (com.sun.jna.platform.win32.Guid.REFIID)20 UINT (com.sun.jna.platform.win32.WinDef.UINT)15 WString (com.sun.jna.WString)12 DWORD (com.sun.jna.platform.win32.WinDef.DWORD)12 WinNT (com.sun.jna.platform.win32.WinNT)12 DWORDByReference (com.sun.jna.platform.win32.WinDef.DWORDByReference)11 VARIANT (com.sun.jna.platform.win32.Variant.VARIANT)10 MEMBERID (com.sun.jna.platform.win32.OaIdl.MEMBERID)9 BSTRByReference (com.sun.jna.platform.win32.WTypes.BSTRByReference)9 ULONG (com.sun.jna.platform.win32.WinDef.ULONG)9 IID (com.sun.jna.platform.win32.Guid.IID)8 DISPIDByReference (com.sun.jna.platform.win32.OaIdl.DISPIDByReference)8 IntByReference (com.sun.jna.ptr.IntByReference)8 UINTByReference (com.sun.jna.platform.win32.WinDef.UINTByReference)7 COMException (com.sun.jna.platform.win32.COM.COMException)6 ConnectionPoint (com.sun.jna.platform.win32.COM.ConnectionPoint)6 Pointer (com.sun.jna.Pointer)5