我正在开发一个Java应用程序。在那里,我想开始一个过程。这是由 JNA 4.0 框架(capsel Kernel32.dll)完成的。
现在我想通过应用程序的进程ID获取一个对象。
package de.test.windows;
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.Kernel32;
import com.sun.jna.platform.win32.WinBase;
import com.sun.jna.platform.win32.WinDef;
public class TestWindows {
public static void main(String[] args) {
WinBase.STARTUPINFO startupInfo = new WinBase.STARTUPINFO();
startupInfo.dwFlags = 1;
WinBase.PROCESS_INFORMATION.ByReference processInformation = new WinBase.PROCESS_INFORMATION.ByReference();
boolean status = Kernel32.INSTANCE.CreateProcess(null, "C:\\Program Files\\MyProgram\\Program.exe", null, null, true, new WinDef.DWORD(0), Pointer.NULL, System.getProperty("java.io.tmpdir"), startupInfo, processInformation);
if (status) {
System.out.println("Process-ID: " + processInformation.dwProcessId);
}
}
}
现在,我如何从Process-Id获取一个对象?