Search in sources :

Example 26 with PointerByReference

use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.

the class IShellFolderTest method testEnumObjects.

public void testEnumObjects() throws Exception {
    PointerByReference peidlPTR = new PointerByReference();
    int SHCONTF_FOLDERS = 0x20;
    int SHCONTF_NONFOLDERS = 0x40;
    boolean sawNames = false;
    WinNT.HRESULT hr = psfMyComputer.EnumObjects(null, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, peidlPTR);
    assertTrue(COMUtils.SUCCEEDED(hr));
    IEnumIDList peidl = IEnumIDList.Converter.PointerToIEnumIDList(peidlPTR);
    PointerByReference pidlItem = new PointerByReference();
    while (peidl.Next(1, pidlItem, null).intValue() == COMUtils.S_OK) {
        PointerByReference sr = new PointerByReference();
        hr = psfMyComputer.GetDisplayNameOf(pidlItem.getValue(), 0, sr);
        assertTrue(COMUtils.SUCCEEDED(hr));
        PointerByReference pszName = new PointerByReference();
        hr = Shlwapi.INSTANCE.StrRetToStr(sr, pidlItem.getValue(), pszName);
        assertTrue(COMUtils.SUCCEEDED(hr));
        String wideString = pszName.getValue().getWideString(0);
        if (wideString != null && wideString.length() > 0)
            sawNames = true;
        Ole32.INSTANCE.CoTaskMemFree(pszName.getValue());
        Ole32.INSTANCE.CoTaskMemFree(pidlItem.getValue());
    }
    peidl.Release();
    // We should see at least one item with a name
    assertTrue(sawNames);
}
Also used : PointerByReference(com.sun.jna.ptr.PointerByReference)

Example 27 with PointerByReference

use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.

the class RunningObjectTable_Test method GetTimeOfLastChange.

@Test
public void GetTimeOfLastChange() {
    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,
// so we can't register an object, and hence can't get a registration key
//rot.GetTimeOfLastChange(pmkObjectName, pfiletime);
}
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)

Example 28 with PointerByReference

use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.

the class RunningObjectTable_Test method Revoke.

@Test
public void Revoke() {
    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,
// so we can't register an object, and hence can't get a registration key to Revoke one
//rot.Revoke(dwRegister);
}
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)

Example 29 with PointerByReference

use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.

the class Shell32Test method testCurrentProcessExplicitAppUserModelID.

public void testCurrentProcessExplicitAppUserModelID() {
    String appUserModelID = "com.sun.jna.platform.win32.Shell32Test";
    HRESULT r1 = Shell32.INSTANCE.SetCurrentProcessExplicitAppUserModelID(new WString(appUserModelID));
    assertEquals(WinError.S_OK, r1);
    PointerByReference ppszAppID = new PointerByReference();
    HRESULT r2 = Shell32.INSTANCE.GetCurrentProcessExplicitAppUserModelID(ppszAppID);
    assertEquals(WinError.S_OK, r2);
    assertEquals(appUserModelID, ppszAppID.getValue().getWideString(0));
    Ole32.INSTANCE.CoTaskMemFree(ppszAppID.getValue());
}
Also used : WString(com.sun.jna.WString) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) PointerByReference(com.sun.jna.ptr.PointerByReference) WString(com.sun.jna.WString)

Example 30 with PointerByReference

use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.

the class VersionTest method testGetFileVersion.

public void testGetFileVersion() {
    String systemRoot = System.getenv("SystemRoot");
    assertNotNull("Missing system root environment variable", systemRoot);
    File file = new File(systemRoot + File.separator + "regedit.exe");
    if (!file.exists()) {
        fail("Can't obtain file version, file " + file + " is missing");
    }
    String filePath = file.getAbsolutePath();
    int size = Version.INSTANCE.GetFileVersionInfoSize(filePath, null);
    assertTrue("GetFileVersionInfoSize(" + filePath + ")", size > 0);
    Pointer buffer = Kernel32.INSTANCE.LocalAlloc(WinBase.LMEM_ZEROINIT, size);
    assertTrue("LocalAlloc(" + size + ")", !buffer.equals(Pointer.NULL));
    try {
        assertTrue("GetFileVersionInfo(" + filePath + ")", Version.INSTANCE.GetFileVersionInfo(filePath, 0, size, buffer));
        IntByReference outputSize = new IntByReference();
        PointerByReference pointer = new PointerByReference();
        assertTrue("VerQueryValue", Version.INSTANCE.VerQueryValue(buffer, "\\", pointer, outputSize));
        VerRsrc.VS_FIXEDFILEINFO fixedFileInfo = new VerRsrc.VS_FIXEDFILEINFO(pointer.getValue());
        assertTrue("dwFileVersionLS", fixedFileInfo.dwFileVersionLS.longValue() > 0);
        assertTrue("dwFileVersionMS", fixedFileInfo.dwFileVersionMS.longValue() > 0);
    } finally {
        Kernel32Util.freeGlobalMemory(buffer);
    }
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) PointerByReference(com.sun.jna.ptr.PointerByReference) Pointer(com.sun.jna.Pointer) File(java.io.File)

Aggregations

PointerByReference (com.sun.jna.ptr.PointerByReference)127 HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)54 IntByReference (com.sun.jna.ptr.IntByReference)35 Pointer (com.sun.jna.Pointer)20 Test (org.junit.Test)19 DWORD (com.sun.jna.platform.win32.WinDef.DWORD)18 REFIID (com.sun.jna.platform.win32.Guid.REFIID)13 File (java.io.File)13 ULONG (com.sun.jna.platform.win32.WinDef.ULONG)10 PSID (com.sun.jna.platform.win32.WinNT.PSID)10 Memory (com.sun.jna.Memory)8 WString (com.sun.jna.WString)8 Dispatch (com.sun.jna.platform.win32.COM.Dispatch)7 ULONGByReference (com.sun.jna.platform.win32.WinDef.ULONGByReference)7 WinNT (com.sun.jna.platform.win32.WinNT)7 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)7 IID (com.sun.jna.platform.win32.Guid.IID)6 ArrayList (java.util.ArrayList)6 IDispatch (com.sun.jna.platform.win32.COM.IDispatch)5 UINT (com.sun.jna.platform.win32.WinDef.UINT)5