use of com.sun.jna.platform.win32.WinDef.ULONGByReference in project jna by java-native-access.
the class EnumMoniker_Test method Next.
@Test
public void Next() {
// GetRunningObjectTable
PointerByReference pprot = new PointerByReference();
HRESULT hr = Ole32.INSTANCE.GetRunningObjectTable(new DWORD(0), pprot);
COMUtils.checkRC(hr);
IRunningObjectTable rot = new RunningObjectTable(pprot.getValue());
// EnumRunning
PointerByReference ppenumMoniker = new PointerByReference();
hr = rot.EnumRunning(ppenumMoniker);
COMUtils.checkRC(hr);
IEnumMoniker iterator = new EnumMoniker(ppenumMoniker.getValue());
// Reset
hr = iterator.Reset();
COMUtils.checkRC(hr);
// Next
PointerByReference rgelt1 = new PointerByReference();
ULONGByReference pceltFetched1 = new ULONGByReference();
hr = iterator.Next(new ULONG(1), rgelt1, pceltFetched1);
COMUtils.checkRC(hr);
// Next
PointerByReference rgelt2 = new PointerByReference();
ULONGByReference pceltFetched2 = new ULONGByReference();
hr = iterator.Next(new ULONG(1), rgelt2, pceltFetched2);
COMUtils.checkRC(hr);
assertNotEquals(rgelt1.getValue(), rgelt2.getValue());
}
use of com.sun.jna.platform.win32.WinDef.ULONGByReference in project jna by java-native-access.
the class EnumMoniker_Test method Reset.
@Test
public void Reset() {
// GetRunningObjectTable
PointerByReference pprot = new PointerByReference();
HRESULT hr = Ole32.INSTANCE.GetRunningObjectTable(new DWORD(0), pprot);
COMUtils.checkRC(hr);
IRunningObjectTable rot = new RunningObjectTable(pprot.getValue());
// EnumRunning
PointerByReference ppenumMoniker = new PointerByReference();
hr = rot.EnumRunning(ppenumMoniker);
COMUtils.checkRC(hr);
IEnumMoniker iterator = new EnumMoniker(ppenumMoniker.getValue());
// Reset
hr = iterator.Reset();
COMUtils.checkRC(hr);
// Next
PointerByReference rgelt1 = new PointerByReference();
ULONGByReference pceltFetched1 = new ULONGByReference();
hr = iterator.Next(new ULONG(1), rgelt1, pceltFetched1);
COMUtils.checkRC(hr);
// Reset
hr = iterator.Reset();
COMUtils.checkRC(hr);
// Next
PointerByReference rgelt2 = new PointerByReference();
ULONGByReference pceltFetched2 = new ULONGByReference();
hr = iterator.Next(new ULONG(1), rgelt2, pceltFetched2);
COMUtils.checkRC(hr);
assertEquals(rgelt1.getValue(), rgelt2.getValue());
}
use of com.sun.jna.platform.win32.WinDef.ULONGByReference in project jna by java-native-access.
the class Advapi32Test method testWriteEncryptedFileRaw.
public void testWriteEncryptedFileRaw() throws Exception {
// create an encrypted file
File file = createTempFile();
String lpFileName = file.getAbsolutePath();
assertTrue(Advapi32.INSTANCE.EncryptFile(lpFileName));
// open file for export
ULONG ulFlags = new ULONG(0);
PointerByReference pvContext = new PointerByReference();
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.OpenEncryptedFileRaw(lpFileName, ulFlags, pvContext));
// read encrypted file
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
FE_EXPORT_FUNC pfExportCallback = new FE_EXPORT_FUNC() {
@Override
public DWORD callback(Pointer pbData, Pointer pvCallbackContext, ULONG ulLength) {
if (pbData == null) {
throw new NullPointerException("Callback data unexpectedly null");
}
byte[] arr = pbData.getByteArray(0, ulLength.intValue());
try {
outputStream.write(arr);
} catch (IOException e) {
throw new RuntimeException(e);
}
return new DWORD(W32Errors.ERROR_SUCCESS);
}
};
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.ReadEncryptedFileRaw(pfExportCallback, null, pvContext.getValue()));
outputStream.close();
Advapi32.INSTANCE.CloseEncryptedFileRaw(pvContext.getValue());
// open file for import
String lbFileName2 = System.getProperty("java.io.tmpdir") + File.separator + "backup-" + file.getName();
ULONG ulFlags2 = new ULONG(CREATE_FOR_IMPORT);
PointerByReference pvContext2 = new PointerByReference();
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.OpenEncryptedFileRaw(lbFileName2, ulFlags2, pvContext2));
// write encrypted file
final IntByReference elementsReadWrapper = new IntByReference(0);
FE_IMPORT_FUNC pfImportCallback = new FE_IMPORT_FUNC() {
@Override
public DWORD callback(Pointer pbData, Pointer pvCallbackContext, ULONGByReference ulLength) {
int elementsRead = elementsReadWrapper.getValue();
int remainingElements = outputStream.size() - elementsRead;
int length = Math.min(remainingElements, ulLength.getValue().intValue());
pbData.write(0, outputStream.toByteArray(), elementsRead, length);
elementsReadWrapper.setValue(elementsRead + length);
ulLength.setValue(new ULONG(length));
return new DWORD(W32Errors.ERROR_SUCCESS);
}
};
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.WriteEncryptedFileRaw(pfImportCallback, null, pvContext2.getValue()));
Advapi32.INSTANCE.CloseEncryptedFileRaw(pvContext2.getValue());
file.delete();
new File(lbFileName2.toString()).delete();
}
use of com.sun.jna.platform.win32.WinDef.ULONGByReference in project jna by java-native-access.
the class RunningObjectTable_Test method GetObject.
@Test
public void GetObject() {
PointerByReference pprot = new PointerByReference();
HRESULT hr = Ole32.INSTANCE.GetRunningObjectTable(new DWORD(0), pprot);
COMUtils.checkRC(hr);
IRunningObjectTable rot = new RunningObjectTable(pprot.getValue());
PointerByReference ppenumMoniker = new PointerByReference();
hr = rot.EnumRunning(ppenumMoniker);
COMUtils.checkRC(hr);
IEnumMoniker iterator = new EnumMoniker(ppenumMoniker.getValue());
iterator.Reset();
PointerByReference rgelt = new PointerByReference();
ULONGByReference pceltFetched = new ULONGByReference();
hr = iterator.Next(new ULONG(1), rgelt, pceltFetched);
while (WinNT.S_OK.equals(hr) && pceltFetched.getValue().intValue() > 0) {
Moniker moniker = new Moniker(rgelt.getValue());
PointerByReference ppbc = new PointerByReference();
Ole32.INSTANCE.CreateBindCtx(new DWORD(), ppbc);
String name = moniker.GetDisplayName(ppbc.getValue(), moniker.getPointer());
PointerByReference ppunkObject = new PointerByReference();
hr = rot.GetObject(moniker.getPointer(), ppunkObject);
COMUtils.checkRC(hr);
IUnknown unk = new Unknown(ppunkObject.getValue());
PointerByReference ppvObject = new PointerByReference();
hr = unk.QueryInterface(new REFIID(IUnknown.IID_IUNKNOWN), ppvObject);
assertEquals(0, hr.intValue());
assertNotNull(ppvObject.getValue());
moniker.Release();
hr = iterator.Next(new ULONG(1), rgelt, pceltFetched);
}
}
Aggregations