有我的进程列表:
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); } } }
我试图设置一个variablespath文件的完整path。 我得到了一个错误@Type不匹配:不能转换从INT到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.GetWindowmoduleeFileName(hWnd, path, 512); System.out.println("Foreground Window modulee FileName: " + Native.toString(path)); user32.GetWindowText(hWnd, path, 512); System.out.println("Window text is: " + Native.toString(path));