GetCurrentProcess関数を使用して現在のプロセスから hWnd を取得して、各プロセスへのパスを表示しようとしました。しかし、この行でエラーが発生しました: User32.INSTANCE.GetWindowThreadProcessId(hWnd, pid);
How to convert it to the desired type?
タイプ User32 のメソッド GetWindowThreadProcessId(WinDef.HWND, IntByReference) は、引数 (WinNT.HANDLE, IntByReference) には適用されません。
私のコードがあります:
try {
while (kernel32.Process32Next(snapshot, processEntry)) {
kernel32.GetCurrentProcess();
HANDLE hWnd = kernel32.GetCurrentProcess();
User32.INSTANCE.GetWindowThreadProcessId(hWnd, pid);
HANDLE process = Kernel32.INSTANCE.OpenProcess(0x0400 | 0x0010,
false, pid.getValue());
psapi.GetModuleFileNameExA(process, null, path, 1024);
System.out.println(Native.toString(path));
}
} finally {
kernel32.CloseHandle(snapshot);
}
UPD: この問題は次のように解決されました。
try {
while (kernel32.Process32Next(snapshot, processEntry)) {
HANDLE process = Kernel32.INSTANCE.OpenProcess(0x0400 | 0x0010,
false, processEntry.th32ProcessID.intValue());
if (process != null) {
int len = psapi.GetModuleFileNameExW(process, null, path,
1024);
if (len > 0) {
System.out.println(new String(path, 0, len));
} else {
System.out.println("GetModuleFileNameW failed");
}
} else {
System.out.println(kernel32.GetLastError());
}
System.out.println(process != null ? Native.toString(path) : "error");
}
} finally {
kernel32.CloseHandle(snapshot);
}
ご協力ありがとう御座います!