DllCall only works in AHK x64 if use MsgBox command Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

DllCall only works in AHK x64 if use MsgBox command

04 Jun 2017, 17:43

?

Code: Select all

q:: ;get PROCESS_BASIC_INFORMATION (tested on Windows 7)
Loop, 2
{
	;if A_Is64bitOS
	;	DllCall("kernel32\Wow64DisableWow64FsRedirection", PtrP,0)

	WinGet, hWnd, ID, ahk_class Notepad
	WinGet, vPID, PID, % "ahk_id " hWnd

	vPIs64 := (A_PtrSize=8)
	vSize := vPIs64?48:24
	vPtrType := vPIs64?"Int64":"Int"
	vUPtrType := vPIs64?"UInt64":"UInt"

	;PROCESS_QUERY_LIMITED_INFORMATION := 0x1000
	;PROCESS_QUERY_INFORMATION := 0x400
	;PROCESS_VM_READ := 0x10
	;PROCESS_ALL_ACCESS := 0x1F0FFF ;(check)
	;hProc := DllCall("OpenProcess", UInt,0x1F0FFF, Int,0, Ptr,vPID)
	hProc := DllCall("OpenProcess", UInt,0x410, Int,0, Ptr,vPID)

	;data only retrieved on AHK x64 if this MsgBox line is used
	;data retrieved on AHK x32 with/without this MsgBox line
	if (A_Index = 1)
		MsgBox, % vPIs64 " " vSize " " vPtrType

	;ProcessBasicInformation := 0
	VarSetCapacity(PROCESS_BASIC_INFORMATION, vSize, 0)
	DllCall("Ntdll.dll\NtQueryInformationProcess", Ptr,hProc, Int,0, Ptr,&PROCESS_BASIC_INFORMATION, UInt,vSize)

	vOutput1 := NumGet(&PROCESS_BASIC_INFORMATION, 0, vPtrType) ;ExitStatus
	vOutput2 := NumGet(&PROCESS_BASIC_INFORMATION, vPIs64?8:4, vPtrType) ;PebBaseAddress
	vOutput3 := NumGet(&PROCESS_BASIC_INFORMATION, vPIs64?16:8, vPtrType) ;AffinityMask
	vOutput4 := NumGet(&PROCESS_BASIC_INFORMATION, vPIs64?24:12, vPtrType) ;BasePriority
	vOutput5 := "(" vPID ") " NumGet(&PROCESS_BASIC_INFORMATION, vPIs64?32:16, vUPtrType) ;UniqueProcessId
	vOutput6 := NumGet(&PROCESS_BASIC_INFORMATION, vPIs64?40:20, vPtrType) ;InheritedFromUniqueProcessId

	vOutput := ""
	Loop, 6
		vOutput .= vOutput%A_Index% "`r`n"
	MsgBox, % vOutput
	DllCall("CloseHandle", Ptr,hProc)
}
return
Trying to convert this:
c++ - How to get list of GDI handles - Stack Overflow
https://stackoverflow.com/questions/13905661/how-to-get-list-of-gdi-handles

For this:
get a process's GDI handles (e.g. get/set title bar font and apply WM_SETFONT to a control) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=31228

Similar issue:
HTMLFile object, getElementsByTagName reports 0 initially - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=31322

Btw this seems to retrieving data for AHK x64 or x32, to an external program that is x64 or x32 (all 4 combinations).
Last edited by jeeswg on 17 Feb 2019, 17:24, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Helgef
Posts: 4081
Joined: 17 Jul 2016, 01:02
Contact:

Re: DllCall only works in AHK x64 if use MsgBox command

05 Jun 2017, 02:57

?

Code: Select all

	vPtrType := vPIs64?"Int64":"Int"
	vUPtrType := vPIs64?"UInt64":"UInt"
Maybe try Ptr or Uptr instead, regardless of vPIs64. As far as I recall, UInt64 doesn't exist in ahk.

Cheers.
just me
Posts: 6666
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: DllCall only works in AHK x64 if use MsgBox command

05 Jun 2017, 03:11

UInt64 is valid but doesn't differ from Int64.
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

Re: DllCall only works in AHK x64 if use MsgBox command

05 Jun 2017, 08:29

I changed:
DllCall("Ntdll.dll\NtQueryInformationProcess", Ptr,hProc, Int,0, Ptr,&PROCESS_BASIC_INFORMATION, UInt,vSize)
DllCall("Ntdll.dll\NtQueryInformationProcess", Ptr,hProc, Int,0, Ptr,&PROCESS_BASIC_INFORMATION, UInt,vSize, Ptr,0)
And the script appeared to work normally, without needing a MsgBox.

It's curious if the MsgBox is having some effect.

I've had various issues with parameters in other people's code, and undocumented functions working on this.

Many thanks.

==================================================

Btw @just me and others, for your viewing pleasure:
GUIs via DllCall: control zoo - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=32106

@just me: Nice to have you back, I think you were away for a while. Link.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
just me
Posts: 6666
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: DllCall only works in AHK x64 if use MsgBox command

05 Jun 2017, 09:31

jeeswg wrote:It's curious if the MsgBox is having some effect.
See x64 Software Conventions->Parameter Passing.The first four parameters are passed in registers. The fifth parameter is expected on the stack. Maybe the MsgBox command does something on the stack which accidentally prevents the DllCall from failing.

Return to “Ask For Help”

Who is online

Users browsing this forum: A_Birdi, flyingDman, Google [Bot], howardb1, J170, miracle, SirSocks, TAC109 and 228 guests