use of com.sun.jna.platform.win32.WinDef.POINT in project jna by java-native-access.
the class ComEventCallbacks_Test method FindConnectionPoint.
@Test
public void FindConnectionPoint() {
// query for ConnectionPointContainer
Unknown unk = new Unknown(ieApp.getValue());
PointerByReference ppCpc = new PointerByReference();
HRESULT hr = unk.QueryInterface(new REFIID(IID_IConnectionPointContainer), ppCpc);
COMUtils.checkRC(hr);
ConnectionPointContainer cpc = new ConnectionPointContainer(ppCpc.getValue());
// find connection point for DWebBrowserEvents2
REFIID riid = new REFIID(IID_DWebBrowserEvents2);
PointerByReference ppCp = new PointerByReference();
hr = cpc.FindConnectionPoint(riid, ppCp);
COMUtils.checkRC(hr);
// On success the returned pointer must not be null
Assert.assertNotNull(ppCpc.getPointer());
}
use of com.sun.jna.platform.win32.WinDef.POINT in project jna by java-native-access.
the class Kernel32Test method testDeviceIoControlFsctlReparse.
/**
* NOTE: Due to process elevation, this test must be run as administrator
* @throws IOException
*/
public void testDeviceIoControlFsctlReparse() throws IOException {
Path folder = Files.createTempDirectory("testDeviceIoControlFsctlReparse_FOLDER");
Path link = Files.createTempDirectory("testDeviceIoControlFsctlReparse_LINK");
File delFolder = folder.toFile();
delFolder.deleteOnExit();
File delLink = link.toFile();
delLink.deleteOnExit();
// Required for FSCTL_SET_REPARSE_POINT
Advapi32Util.Privilege restore = new Advapi32Util.Privilege(WinNT.SE_RESTORE_NAME);
try {
restore.enable();
HANDLE hFile = Kernel32.INSTANCE.CreateFile(link.toAbsolutePath().toString(), WinNT.GENERIC_READ | WinNT.FILE_WRITE_ATTRIBUTES | WinNT.FILE_WRITE_EA, WinNT.FILE_SHARE_READ | WinNT.FILE_SHARE_WRITE | WinNT.FILE_SHARE_DELETE, new WinBase.SECURITY_ATTRIBUTES(), WinNT.OPEN_EXISTING, WinNT.FILE_ATTRIBUTE_DIRECTORY | WinNT.FILE_FLAG_BACKUP_SEMANTICS | WinNT.FILE_FLAG_OPEN_REPARSE_POINT, null);
if (WinBase.INVALID_HANDLE_VALUE.equals(hFile)) {
fail("CreateFile failed with " + Kernel32.INSTANCE.GetLastError());
}
try {
SymbolicLinkReparseBuffer symLinkReparseBuffer = new SymbolicLinkReparseBuffer(folder.getFileName().toString(), folder.getFileName().toString(), Ntifs.SYMLINK_FLAG_RELATIVE);
REPARSE_DATA_BUFFER lpBuffer = new REPARSE_DATA_BUFFER(WinNT.IO_REPARSE_TAG_SYMLINK, (short) 0, symLinkReparseBuffer);
assertTrue(Kernel32.INSTANCE.DeviceIoControl(hFile, FSCTL_SET_REPARSE_POINT, lpBuffer.getPointer(), lpBuffer.getSize(), null, 0, null, null));
Memory p = new Memory(REPARSE_DATA_BUFFER.sizeOf());
IntByReference lpBytes = new IntByReference();
assertTrue(Kernel32.INSTANCE.DeviceIoControl(hFile, FSCTL_GET_REPARSE_POINT, null, 0, p, (int) p.size(), lpBytes, null));
// Is a reparse point
lpBuffer = new REPARSE_DATA_BUFFER(p);
assertTrue(lpBytes.getValue() > 0);
assertTrue(lpBuffer.ReparseTag == WinNT.IO_REPARSE_TAG_SYMLINK);
assertEquals(folder.getFileName().toString(), lpBuffer.u.symLinkReparseBuffer.getPrintName());
assertEquals(folder.getFileName().toString(), lpBuffer.u.symLinkReparseBuffer.getSubstituteName());
} finally {
Kernel32Util.closeHandle(hFile);
}
} finally {
restore.close();
}
}
use of com.sun.jna.platform.win32.WinDef.POINT in project jna by java-native-access.
the class ProxyObject method advise.
public IComEventCallbackCookie advise(Class<?> comEventCallbackInterface, final IComEventCallbackListener comEventCallbackListener) {
assert COMUtils.comIsInitialized() : "COM not initialized";
try {
ComInterface comInterfaceAnnotation = comEventCallbackInterface.getAnnotation(ComInterface.class);
if (null == comInterfaceAnnotation) {
throw new COMException("advise: Interface must define a value for either iid via the ComInterface annotation");
}
final IID iid = this.getIID(comInterfaceAnnotation);
final ConnectionPoint rawCp = this.fetchRawConnectionPoint(iid);
// create the dispatch listener
final IDispatchCallback rawListener = factory.createDispatchCallback(comEventCallbackInterface, comEventCallbackListener);
// store it the comEventCallback argument, so it is not garbage
// collected.
comEventCallbackListener.setDispatchCallbackListener(rawListener);
// set the dispatch listener to listen to events from the connection
// point
final DWORDByReference pdwCookie = new DWORDByReference();
HRESULT hr = rawCp.Advise(rawListener, pdwCookie);
// release before check in case check
int n = rawCp.Release();
// throws exception
COMUtils.checkRC(hr);
// return the cookie so that a call to stop listening can be made
return new ComEventCallbackCookie(pdwCookie.getValue());
} catch (Exception e) {
throw new COMException("Error occured in advise when trying to connect the listener " + comEventCallbackListener, e);
}
}
use of com.sun.jna.platform.win32.WinDef.POINT in project jna by java-native-access.
the class ProxyObject method fetchRawConnectionPoint.
// ---------------------- IConnectionPoint ----------------------
private ConnectionPoint fetchRawConnectionPoint(IID iid) throws InterruptedException, ExecutionException, TimeoutException {
assert COMUtils.comIsInitialized() : "COM not initialized";
// query for ConnectionPointContainer
IConnectionPointContainer cpc = this.queryInterface(IConnectionPointContainer.class);
Dispatch rawCpcDispatch = (Dispatch) cpc.getRawDispatch();
final ConnectionPointContainer rawCpc = new ConnectionPointContainer(rawCpcDispatch.getPointer());
// find connection point for comEventCallback interface
final REFIID adviseRiid = new REFIID(iid.getPointer());
final PointerByReference ppCp = new PointerByReference();
HRESULT hr = rawCpc.FindConnectionPoint(adviseRiid, ppCp);
COMUtils.checkRC(hr);
final ConnectionPoint rawCp = new ConnectionPoint(ppCp.getValue());
return rawCp;
}
use of com.sun.jna.platform.win32.WinDef.POINT in project jna by java-native-access.
the class User32Test method testGetCursorPos.
@Test
public void testGetCursorPos() {
POINT cursorPos = new POINT();
boolean result = User32.INSTANCE.GetCursorPos(cursorPos);
assertTrue("GetCursorPos should return true", result);
assertTrue("X coordinate in POINT should be >= 0", cursorPos.x >= 0);
assertTrue("Y coordinate in POINT should be >= 0", cursorPos.y >= 0);
}
Aggregations