本文整理汇总了Java中com.sun.jna.platform.win32.Kernel32.INSTANCE属性的典型用法代码示例。如果您正苦于以下问题:Java Kernel32.INSTANCE属性的具体用法?Java Kernel32.INSTANCE怎么用?Java Kernel32.INSTANCE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.sun.jna.platform.win32.Kernel32
的用法示例。
在下文中一共展示了Kernel32.INSTANCE属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDiskSize
private long getDiskSize(Disk disk) {
long result = -1l;
Kernel32 kernel32 = Kernel32.INSTANCE;
HANDLE diskHandle = kernel32.CreateFile(disk.path, WinNT.GENERIC_READ, WinNT.FILE_SHARE_READ, null,
WinNT.OPEN_EXISTING, WinNT.FILE_ATTRIBUTE_NORMAL, null);
if (WinBase.INVALID_HANDLE_VALUE.equals(diskHandle)) {
return result;
}
try {
Memory output = new Memory(Native.getNativeSize(LARGE_INTEGER.class));
IntByReference lpBytes = new IntByReference();
boolean success = kernel32.DeviceIoControl(diskHandle,
WinioctlUtil.CTL_CODE(Winioctl.FILE_DEVICE_DISK, 0x17, Winioctl.METHOD_BUFFERED,
Winioctl.FILE_READ_ACCESS),
null, 0, output, Native.getNativeSize(LARGE_INTEGER.class), lpBytes, null);
// TODO: Check success?
result = output.getLong(0);
}
finally {
Kernel32Util.closeHandle(diskHandle);
}
return result;
}
示例2: getWindowsProcessId
/**
* @param process NiFi Registry Process Reference
* @param logger Logger Reference for Debug
* @return Returns pid or null in-case pid could not be determined
* This method takes {@link Process} and {@link Logger} and returns
* the platform specific Handle for Win32 Systems, a.k.a <b>pid</b>
* In-case it fails to determine the pid, it will return Null.
* Purpose for the Logger is to log any interaction for debugging.
*/
private static Long getWindowsProcessId(final Process process, final Logger logger) {
/* determine the pid on windows plattforms */
try {
Field f = process.getClass().getDeclaredField("handle");
f.setAccessible(true);
long handl = f.getLong(process);
Kernel32 kernel = Kernel32.INSTANCE;
WinNT.HANDLE handle = new WinNT.HANDLE();
handle.setPointer(Pointer.createConstant(handl));
int ret = kernel.GetProcessId(handle);
logger.debug("Detected pid: {}", ret);
return Long.valueOf(ret);
} catch (final IllegalAccessException | NoSuchFieldException nsfe) {
logger.debug("Could not find PID for child process due to {}", nsfe);
}
return null;
}
示例3: getProcessPid
/**
* Returns {@code pid} for Windows process
* @param process Windows process
* @return pid of the {@code process}
*/
public static int getProcessPid(Process process) {
if (process.getClass().getName().equals("java.lang.Win32Process") ||
process.getClass().getName().equals("java.lang.ProcessImpl")) {
try {
long handle = ReflectionUtil.getField(process.getClass(), process, long.class, "handle");
Kernel32 kernel = Kernel32.INSTANCE;
WinNT.HANDLE winHandle = new WinNT.HANDLE();
winHandle.setPointer(Pointer.createConstant(handle));
return kernel.GetProcessId(winHandle);
} catch (Throwable e) {
throw new IllegalStateException(e);
}
} else {
throw new IllegalStateException("Unknown Process implementation");
}
}
示例4: findProcessId
@Override
public String findProcessId(Process process) throws NoSuchFieldException, IllegalAccessException {
if (process.getClass().getName().equals("java.lang.Win32Process")
|| process.getClass().getName().equals("java.lang.ProcessImpl")) {
Field f = process.getClass().getDeclaredField("handle");
f.setAccessible(true);
long handleNumber = f.getLong(process);
Kernel32 kernel = Kernel32.INSTANCE;
WinNT.HANDLE handle = new WinNT.HANDLE();
handle.setPointer(Pointer.createConstant(handleNumber));
int pid = kernel.GetProcessId(handle);
log.debug("Found pid for managed process: {}", pid);
return pid + "";
}
return null;
}
示例5: ensureWinApiInstances
private static void ensureWinApiInstances() {
if (user32 == null) {
user32 = User32.INSTANCE;
}
if (kernel32 == null) {
kernel32 = Kernel32.INSTANCE;
}
}
示例6: WindowsXPMouse
public WindowsXPMouse()
{
if (!Platform.isWindows())
{
throw new UnsupportedOperationException(
"Not supported on this platform.");
}
USER32INST = User32.INSTANCE;
KERNEL32INST = Kernel32.INSTANCE;
mouseHook = hookTheMouse();
Native.setProtected(true);
}
示例7: getWindowsPid
static long getWindowsPid(Process process) {
if (process.getClass().getName().equals("java.lang.Win32Process") || process.getClass().getName().equals("java.lang.ProcessImpl")) {
try {
Field f = process.getClass().getDeclaredField("handle");
f.setAccessible(true);
long handl = f.getLong(process);
Kernel32 kernel = Kernel32.INSTANCE;
WinNT.HANDLE handle = new WinNT.HANDLE();
handle.setPointer(Pointer.createConstant(handl));
return kernel.GetProcessId(handle);
} catch (Throwable ignored) {
}
}
return -1;
}
示例8: repopulateNameWindowMap
private void repopulateNameWindowMap() {
final List<HWND> windows = new ArrayList<HWND>();
nameWindowMap = new HashMap<String, HWND>();
User32 user32 = User32.INSTANCE;
User32Ext myuser32 = User32Ext.INSTANCE;
Kernel32 k32 = Kernel32.INSTANCE;
getWindowNameMap(windows, user32, nameWindowMap);
for (ListDataListener listener : ((AbstractListModel) this.jList1.getModel()).getListDataListeners()) {
listener.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, 0, nameWindowMap.keySet().size() - 1));
}
//this.jScrollPane1.revalidate();
//this.jScrollPane1.repaint();
}
示例9: bringHandleToFront
public void bringHandleToFront(HWND selectedWindow) {
User32 user32 = User32.INSTANCE;
User32Ext myuser32 = User32Ext.INSTANCE;
Kernel32 k32 = Kernel32.INSTANCE;
boolean result = true;
int foreThread = myuser32.GetWindowThreadProcessId(myuser32.GetForegroundWindow(), null);
int targetThread = myuser32.GetWindowThreadProcessId(selectedWindow, null);
int appThread = k32.GetCurrentThreadId();
if (SwingUtilities.isEventDispatchThread()) {
System.out.println("is the event dispatch thread.");
}
if (foreThread != appThread) {
System.out.printf("Proc Handler: Fore %d App %d target %d\n", foreThread, appThread, targetThread);
System.out.println("Selected window name " + User32ExtUtil.getWindowText(selectedWindow));
System.out.println("Foreground and app thread different.");
result = myuser32.AttachThreadInput(appThread, foreThread, true);
result = myuser32.AttachThreadInput(targetThread, appThread, true);
processResult(result, "AttachThreadInput");
result = myuser32.ShowWindow(selectedWindow, WinUserExt.SW_RESTORE);
//result = myuser32.BringWindowToTop(selectedWindow);
result = myuser32.SetForegroundWindow(selectedWindow);
//myuser32.SwitchToThisWindow(selectedWindow, false);
//myuser32.BringWindowToTop(selectedWindow);
//processResult(result, "BringWindowToTop");
result = myuser32.AttachThreadInput(appThread, foreThread, false);
result = myuser32.AttachThreadInput(targetThread, appThread, false);
processResult(result, "DetachThreadInput");
} else {
System.out.println("Foreground and app thread alike.");
result = myuser32.SetForegroundWindow(selectedWindow);
processResult(result, "SetForegroundWindow");
}
}