Invalid return type for DllCall Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
gqqnbig
Posts: 13
Joined: 27 Jul 2014, 15:00

Invalid return type for DllCall

10 Feb 2018, 01:55

Code: Select all

GetModuleFileNameEx( p_pid ) ; by shimanov -  www.autohotkey.com/forum/viewtopic.php?t=9000
{
   local h_process, name_size, result, name

   h_process := DllCall( "OpenProcess", "uint", 0x10|0x400, "int", false, "uint", p_pid )
   if ( ErrorLevel or h_process = 0 )
      return

   name_size:= 255
   VarSetCapacity( name, name_size )

   result := DllCall( "psapi.dll\GetModuleFileNameEx" ( A_IsUnicode ? "W" : "A" )
                 , "uint", h_process, "uint", 0, "str", name, "uint", name_size )

   DllCall "CloseHandle", h_process

   return name
}
This is the script that takes process ID and returns the path of the process. It works fine in AutoHotKey v1 but when it runs in V2, DllCall has error "Invalid return type". How do I fix that?

My AutoHotKey version is a086
无标题.png
无标题.png (12.12 KiB) Viewed 2379 times
just me
Posts: 9442
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Invalid return type for DllCall

10 Feb 2018, 02:33

I doubt that

Code: Select all

DllCall "CloseHandle", h_process
is working in v1.

If you pass an even number of parameters to DllCall(), the last parameter must be the return type (which can be a variable).
guest3456
Posts: 3462
Joined: 09 Oct 2013, 10:31

Re: Invalid return type for DllCall

10 Feb 2018, 13:35

its also weird how the string is getting interpreted as "Close111Handle"

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Invalid return type for DllCall

10 Feb 2018, 13:46

Sharp eyes guest3456. It doesn't happen on my pc though,

Code: Select all

Error:  Invalid return type.

	Line#
	006: {
	009: h_process := DllCall( "OpenProcess", "uint", 0x10|0x400, "int", false, "uint", p_pid )
	010: if ( ErrorLevel or h_process = 0 )
	011: Return
	013: name_size := 255
	014: VarSetCapacity( name, name_size )
	016: result := DllCall( "psapi.dll\GetModuleFileNameEx" ( A_IsUnicode ? "W" : "A" ), "uint", h_process, "uint", 0, "str", name, "uint", name_size )
--->	019: DllCall("CloseHandle", h_process)
	021: Return name
	022: }
	023: Exit
	024: Exit
	024: Exit

The current thread will exit.
:arrow: 2.0-a088-338ed55

Cheers.
guest3456
Posts: 3462
Joined: 09 Oct 2013, 10:31

Re: Invalid return type for DllCall  Topic is solved

10 Feb 2018, 14:11

just me wrote:I doubt that

Code: Select all

DllCall "CloseHandle", h_process
is working in v1.

If you pass an even number of parameters to DllCall(), the last parameter must be the return type (which can be a variable).
yes obviously the code should be

[code]
DllCall "CloseHandle", "uint", h_process
[/code]

Code: Select all

DllCall("CloseHandle", "uint", h_process)

gqqnbig
Posts: 13
Joined: 27 Jul 2014, 15:00

Re: Invalid return type for DllCall

10 Feb 2018, 20:49

guest3456 wrote:its also weird how the string is getting interpreted as "Close111Handle"
oh, LOL, I was just testing the code

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: No registered users and 35 guests