By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

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



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?
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.

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

v:\> echo %@wmi[.,"Select ProcessId from Win32_Process where Name='explorer.exe'"]
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).

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