[英]Using GetWindowModuleFileName in JNA
这是我的流程列表:
public class lab2 {
public static void main(String args[]) {
Kernel32 kernel32 = Kernel32.INSTANCE;
User32 user32 = User32.INSTANCE;
Tlhelp32.PROCESSENTRY32.ByReference processEntry = new Tlhelp32.PROCESSENTRY32.ByReference();
WinNT.HANDLE snapshot = kernel32.CreateToolhelp32Snapshot(
Tlhelp32.TH32CS_SNAPPROCESS, new WinDef.DWORD(0));
char path[] = new char[512];
HWND hWnd = User32.INSTANCE.GetWindowModuleFileName(hWnd, path, 512);
try {
while (kernel32.Process32Next(snapshot, processEntry)) {
System.out.println(Native.toString(processEntry.szExeFile)
+ "\t" + Native.toString(path));
}
} finally {
kernel32.CloseHandle(snapshot);
}
}
}
我试图将变量路径设置为文件的完整路径。 我收到一个错误@Type不匹配:无法从int转换为 HWND hWnd = User32.INSTANCE.GetWindowModuleFileName(hWnd, path, 512);
WinDef.HWND @ HWND hWnd = User32.INSTANCE.GetWindowModuleFileName(hWnd, path, 512);
我哪里做错了? 怎么做对? 谢谢。
您使用的功能错误。
例如,
User32 user32 = User32.INSTANCE;
char path[] = new char[512];
long sleepTime = 2000;
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {}
HWND hWnd = user32.GetForegroundWindow();
user32.GetWindowModuleFileName(hWnd, path, 512);
System.out.println("Foreground Window Module FileName: " +
Native.toString(path));
user32.GetWindowText(hWnd, path, 512);
System.out.println("Window text is: " + Native.toString(path));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.