@winapi GetWindowThreadProcessId , PDWORD=PID , PID is not assigned

Dec 29, 2021
18
2

GetWindowThreadProcessId(handle,PDWORD=n)


does not give a value back for second parameter.

TCC v28 Code:
set hprogman=%@winapi[user32.dll,FindWindow,Progman,"Program Manager"] set hshell=%@winapi[user32.dll,FindWindowEx,%hprogman,NULL,"shelldll_defview",NULL] set hListView=%@winapi[user32.dll,FindWindowEx,%hshell,NULL,"syslistview32",NULL] echo hlistView = %hlistView hlistView = 65874 set PID=-1 set thread=%@winapi[user32.dll,GetWindowThreadProcessId,%hListView,PDWORD=PID] echo thread=%thread PID=%PID thread=5468 PID=-1

The PID variable value is not changed.

From the help:

"PDWORD - a pointer to the DWORD n"

Its not clear what n is,
Is n an environment variable? , must it exist before the call?

In python we get a PID for the handle:
python -c "from win32process import GetWindowThreadProcessId;print(GetWindowThreadProcessId(%hlistView))" [5468, 5472]

How do get @winapi working for GetWindowThreadProcessId?
 
May 20, 2008
11,800
118
Syracuse, NY, USA
A quick look at @WINAPI suggests you can't do it (at least easily). From the help:

The return value is either a string value returned by the API (if BUFFER or aBUFFER is specified), or the integer value returned by the API.

You could try giving it BUFFER or aBUFFER. GetWindowThreadProcessId should put the DWORD PID at the buffer location (it won't be NUL-terminated) but you will have to interpret it as a number (instead of a string). I don't know if that's possible.

If you really need explorer's PID there are (at least) two other ways.

Code:
v:\> echo %@pid[explorer.exe]
6916

v:\> echo %@wmi[.,"Select ProcessId from Win32_Process where Name='explorer.exe'"]
6916
 
May 20, 2008
11,800
118
Syracuse, NY, USA
Hmmm! Maybe you can. Here's a technique for digging an integer (in this case, 64-bit unsigned) out of @WINAPI's buffer. This BTM gives the current time as a FILETIME (an "age" to TCC).

Code:
:: AGENOW.BTM
setdos /x-1245678
set foo=%@unicode[%@winapi[kernel32.dll,GetSystemTimePreciseAsFileTime,buffer]]
setdos /x+1245678
set agenow=%@eval[%@word[0,%foo] + (%@word[1,%foo] SHL 16) + (%@word[2,%foo] SHL 32) + (%@word[3,%foo] SHL 48)]
echo %agenow