Page 1 of 1

Reverse string Dllcall not working anymore?

Posted: 09 Jun 2018, 12:20
by brutus_skywalker
So i was going over https://autohotkey.com/board/topic/4239 ... e-a-string, and i can't figure out why NON of the DllCall's seem to work, the thing is i recall using some of these,but they just don't seem to work anymore.

Any Ideas as to why?

[Win7x64-Ultimate]

Code: Select all


MsgBox, % DllCall("msvcrt.dll\_strrev", "str", "autohotkey", "cdecl str")

MsgBox, % DllCall( "msvcrt.dll\_strrev", Str,"autohotkey", UInt,0, Str )

var = autohotkey
MsgBox, % DllCall( "msvcrt.dll\_strrev", Str,var, UInt,0, Str )


Re: Reverse string Dllcall not working anymore?  Topic is solved

Posted: 09 Jun 2018, 12:36
by Flipeador
you are using the "ANSI" (for UTF-8 strings) version...

Code: Select all

; https://msdn.microsoft.com/en-us/library/9hby7w40.aspx
MsgBox % DllCall("msvcrt.dll\_wcsrev", "Str", "AutoHotkey", "CDecl Str")

var := "autohotkey"
MsgBox % DllCall("msvcrt.dll\_wcsrev", "UPtr", &var, "CDecl Str")

Re: Reverse string Dllcall not working anymore?

Posted: 09 Jun 2018, 12:42
by brutus_skywalker
Flipeador wrote:you are using the ANSI version...

Code: Select all

; https://msdn.microsoft.com/en-us/library/9hby7w40.aspx
MsgBox % DllCall("msvcrt.dll\_wcsrev", "Str", "AutoHotkey", "CDecl Str")

var := "autohotkey"
MsgBox % DllCall("msvcrt.dll\_wcsrev", "UPtr", &var, "CDecl Str")

Yeah, that was stupid of me, i didn't notice, just checked the msdn. SORRY.

Re: Reverse string Dllcall not working anymore?

Posted: 09 Jun 2018, 12:43
by Flipeador
No using Unicode, those were some of the examples i tried from the linked page.
It was not a question. I was referring to _strrev, not AHK. The above code works perfectly for me.

Re: Reverse string Dllcall not working anymore?

Posted: 09 Jun 2018, 12:45
by Flipeador

Code: Select all

String := "AutoHotkey"

Size := StrPut(String, "UTF-8")
VarSetCapacity(Buffer, Size)
StrPut(String, &Buffer, "UTF-8")

MsgBox % DllCall("msvcrt.dll\_strrev", "UPtr", &Buffer, "CDecl AStr")

Re: Reverse string Dllcall not working anymore?

Posted: 09 Jun 2018, 12:47
by brutus_skywalker
Apiologies, just checked msdn. My Bad!

Re: Reverse string Dllcall not working anymore?

Posted: 09 Jun 2018, 12:55
by Helgef
You can do "astr", str. Also note that you reverse the input string, so using "(a)str" for the return is unnecessary. If you want to preserve the input you can pass str . "" (and then use "(a)str" for the return)

Cheers.

Re: Reverse string Dllcall not working anymore?

Posted: 09 Jun 2018, 13:00
by Flipeador
Also note that you reverse the input string, so using "(a)str" for the return is unnecessary.
You can do "astr", str
True ;)

Code: Select all

var := "AutoHotkey"
DllCall("msvcrt.dll\_wcsrev", "UPtr", &var, "CDecl")
MsgBox % var

Code: Select all

; but you can't use UPtr
MsgBox % DllCall("msvcrt.dll\_strrev", "AStr", "autohotkey", "CDecl AStr")
Helgef wrote:If you want to preserve the input you can passstr . "" (and then use "(a)str" for the return)
How is that?

Re: Reverse string Dllcall not working anymore?

Posted: 09 Jun 2018, 13:12
by Helgef
How is that?
str . "" results in a temporary string, not a variable reference. So "astr", str . "" passes the address of a temporary string, while "astr", str passes the address of str.

In v2 we can do "ptr", &(str . "") :shh:

Cheers.

Edit, maybe more intuitive, you can do "ptr", &revStr := str to preserve it.

Re: Reverse string Dllcall not working anymore?

Posted: 09 Jun 2018, 13:23
by Flipeador
ah!, yeah, I do not know what I had tried that did not work for me. :facepalm:
Yes, passing directly the memory address is faster.
In v2 we can do.. :silent: :)