Correct passing NULL into DllCall string parameters Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
vmech
Posts: 356
Joined: 25 Aug 2019, 13:03

Correct passing NULL into DllCall string parameters

Post by vmech » 28 Sep 2022, 04:09

What is the mostly correct way to pass NULL into DllCall string parameters (e.g. for ShellExecuteW function): as a ('Str', ''), or as a ('Str', 0) ?

PS. The Autohotkey Reference explains passing NULL for numeric parameters, but does not cover this point for string parameters.
Please post your script code inside [code] ... [/code] block. Thank you.

User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: Correct passing NULL into DllCall string parameters  Topic is solved

Post by jNizM » 28 Sep 2022, 04:16

For your example ShellExecuteW
LPCWSTR is a 32-bit pointer to a constant string of 16-bit Unicode characters, which MAY be null-terminated. So you could use "Ptr", 0

Maybe you find this useful: viewtopic.php?t=99817
And look at the explanation by lexikos: viewtopic.php?p=25611#p25611
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile

vmech
Posts: 356
Joined: 25 Aug 2019, 13:03

Re: Correct passing NULL into DllCall string parameters

Post by vmech » 28 Sep 2022, 04:32

jNizM wrote:
28 Sep 2022, 04:16
Maybe you find this useful: viewtopic.php?t=99817
I use this tool all the time, TY :)
Please post your script code inside [code] ... [/code] block. Thank you.

User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: Correct passing NULL into DllCall string parameters

Post by jNizM » 28 Sep 2022, 04:38

e.g. with "Ptr"

Code: Select all

ShellExecute(handle, File, Operation, ...)
{
	DllCall("shell32\ShellExecuteW", "Ptr", handle									; HWND    hwnd
	                               , "Ptr", (Operation ? StrPtr(Operation) : 0)		; LPCWSTR lpOperation
	                               , "Str", File									; LPCWSTR lpFile
	                               , ...
}
or or or... all (many) roads lead to Rome

Use whatever is most understandable or clear to you
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile

Post Reply

Return to “Ask for Help (v2)”