From GetWindowThreadProcessId
[out, optional] lpdwProcessId
Type: LPDWORD
A pointer to a variable that receives the process identifier. If this parameter is not NULL, GetWindowThreadProcessId copies the identifier of the process to the variable; otherwise, it does not.
In other words, pass an IntByReference
, and afterwards retrieve its value. For instance (error checking omitted):
IntByReference lpdwProcessId = new IntByReference();
User32.INSTANCE.GetWindowThreadProcessId(desktopWindow.getHWND(), lpdwProcessId);
Optional<ProcessHandle> processHandle = ProcessHandle.of(lpdwProcessId.getValue());