Reverse string Dllcall not working anymore? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
brutus_skywalker
Posts: 175
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Reverse string Dllcall not working anymore?

09 Jun 2018, 12:20

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 )

Outsourcing Clicks & Presses Since 2004.
User avatar
Flipeador
Posts: 1204
Joined: 15 Nov 2014, 21:31
Location: Argentina
Contact:

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

09 Jun 2018, 12:36

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")
brutus_skywalker
Posts: 175
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: Reverse string Dllcall not working anymore?

09 Jun 2018, 12:42

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.
Last edited by brutus_skywalker on 09 Jun 2018, 12:46, edited 2 times in total.
Outsourcing Clicks & Presses Since 2004.
User avatar
Flipeador
Posts: 1204
Joined: 15 Nov 2014, 21:31
Location: Argentina
Contact:

Re: Reverse string Dllcall not working anymore?

09 Jun 2018, 12:43

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.
User avatar
Flipeador
Posts: 1204
Joined: 15 Nov 2014, 21:31
Location: Argentina
Contact:

Re: Reverse string Dllcall not working anymore?

09 Jun 2018, 12:45

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")
brutus_skywalker
Posts: 175
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: Reverse string Dllcall not working anymore?

09 Jun 2018, 12:47

Apiologies, just checked msdn. My Bad!
Outsourcing Clicks & Presses Since 2004.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Reverse string Dllcall not working anymore?

09 Jun 2018, 12:55

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.
User avatar
Flipeador
Posts: 1204
Joined: 15 Nov 2014, 21:31
Location: Argentina
Contact:

Re: Reverse string Dllcall not working anymore?

09 Jun 2018, 13:00

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?
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Reverse string Dllcall not working anymore?

09 Jun 2018, 13:12

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.
User avatar
Flipeador
Posts: 1204
Joined: 15 Nov 2014, 21:31
Location: Argentina
Contact:

Re: Reverse string Dllcall not working anymore?

09 Jun 2018, 13:23

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: :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, OrangeCat and 184 guests