There is my list of processes:
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);
}
}
}
I tried to set a variable path the full path to the file. I got an error @Type mismatch: cannot convert from int to WinDef.HWND@ in HWND hWnd = User32.INSTANCE.GetWindowModuleFileName(hWnd, path, 512);
Where did I go wrong? How to do it right? Thank you.
You're using the function wrong.
eg,
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));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.