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