SKAN wrote: ↑15 Aug 2023, 12:38
20170201225639 wrote: ↑15 Aug 2023, 12:17
Is it because of any hidden trimming operation performed?
Seems like incorrect length!
Code: Select all
#Requires AutoHotkey v2.0
#SingleInstance
Str := ComObject("Scriptlet.TypeLib").Guid
VarSetStrCapacity(&Str, -1)
MsgBox StrLen(Str) ; 38
Interesting! So I guess the '40' result represent the internally-cached string length?
https://www.autohotkey.com/docs/v2/lib/VarSetStrCapacity.htm
Specify -1 for RequestedCapacity to update the variable's internally-stored string length to the length of its current contents. This is useful in cases where the string has been altered indirectly, such as by passing its address via DllCall or SendMessage. In this mode, VarSetStrCapacity returns the length rather than the capacity.
I tripped over this problem when converting my v1 script to v2. Both v1 and v2 give the StrLen of the initial guid string as 40 (2 more than the expected 38 (the 36 characters + the 2 curly brackets)). However, in my v1 script, I first StringLower-ed the initial string, which (unbeknownst to me) had the side effect of correctly updating the StrLen to 38, so when I then do SubStr(2,-1) to remove the brackets, I get the 36 character GUID.
In v2 however, StrLower-ing the initial guid string does not update the internal length. So when I then do SubStr(2,-1) to try and remove the brackets, something very unexpected results ...
This v1 code
Code: Select all
❶ := ComObjCreate("Scriptlet.TypeLib").Guid
StringLower, ❷, ❶
❸ := SubStr(❷, 2, -1)
print_as_json([❶, StrLen(❶), ❷, StrLen(❷), ❸, StrLen(❸)])
produces:
[
"{A944D6AF-1B95-4D92-ABF4-91DED0B9757E}",
40,
"{a944d6af-1b95-4d92-abf4-91ded0b9757e}",
38,
"a944d6af-1b95-4d92-abf4-91ded0b9757e",
36
]
But this v2 code
Code: Select all
❶ := ComObject("Scriptlet.TypeLib").Guid
❷ := StrLower(❶)
❸ := SubStr(❷, 2, -1)
print_as_json([❶, StrLen(❶), ❷, StrLen(❷), ❸, StrLen(❸)])
produces:
[
"{61123CC8-D58C-44B4-AE55-8A1DFF3DFD51}",
40,
"{61123cc8-d58c-44b4-ae55-8a1dff3dfd51}",
40,
"61123cc8-d58c-44b4-ae55-8a1dff3dfd51}", {{
!}}
38
]