IniRead (AHK v2): spaces as default value

Report problems with documented functionality
User avatar
jeeswg
Posts: 5275
Joined: 19 Dec 2016, 01:58
Location: UK

IniRead (AHK v2): spaces as default value

21 Sep 2018, 15:48

In AHK v2 it appears that if you specify a default value of space or multiple spaces, a blank string is returned.

Code: Select all

;tested on AHK v2.0-a099
vPath := ""
MsgBox("[" IniRead(vPath, "Section", "NonExistentKey", A_Space) "]") ;[]
MsgBox("[" IniRead(vPath, "Section", "NonExistentKey", A_Space A_Space A_Space) "]") ;[]
MsgBox("[" IniRead(vPath, "Section", "NonExistentKey", "default") "]") ;[default]
lexikos
Posts: 6201
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: IniRead (AHK v2): spaces as default value

21 Sep 2018, 19:53

This is standard Windows behaviour. IniRead when specifying a key is literally just a call to GetFullPathName and a call to GetPrivateProfileString. Everything is handled by the latter function, including returning a default value if the key wasn't found.
User avatar
jeeswg
Posts: 5275
Joined: 19 Dec 2016, 01:58
Location: UK

Re: IniRead (AHK v2): spaces as default value

22 Sep 2018, 01:21

Thanks, that also explains the curious IniRead (AHK v1) behaviour.

GetPrivateProfileString function | Microsoft Docs
https://docs.microsoft.com/en-gb/window ... filestring
Avoid specifying a default string with trailing blank characters. The function inserts a null character in the lpReturnedString buffer to strip any trailing blanks.
Note: GetPrivateProfileString appears to trim trailing spaces but not tabs or any other characters.

Code: Select all

;test IniRead default strings (tested on AHK v2.0-a099)
vPath := "", vOutput := ""
Loop 65535
{
	vDefault := "abc" Chr(A_Index)
	vRet := IniRead(vPath, "Section", "NonExistentKey", vDefault)
	if !(vDefault = vRet)
		vOutput .= A_Index "`r`n"
}
Clipboard := vOutput
MsgBox(vOutput) ;32 ;only trailing spaces appear to be trimmed
return

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 8 guests