Iczer Posted June 27, 2016 Posted June 27, 2016 i have some (encoding?, type?) troubles with string return values from FreeBasic DLL - FreeBasic DLL source : Public function some_test_function(ByVal xx as String, ByRef yy as String) as String Export yy = Left(xx, 3) return yy end Function and AutoIt script : #AutoIt3Wrapper_UseX64=Y #include <Array.au3> $h = DllOpen(@ScriptDir & "\DLL Project.dll") ConsoleWrite("DllOpen @error = " & @error & @CRLF) $a = "abcdefgh" $b = "" $aRet = DllCall($h,"STR","SOME_TEST_FUNCTION", "STR*", $a, "STR", $b) ConsoleWrite("DllCall @error = " & @error & @CRLF) ConsoleWrite("return = " & $aRet[0] & " $a = " & $aRet[1] & " $b = " & $aRet[2] & @CRLF) _ArrayDisplay($aRet) and I get : DllOpen @error = 0 DllCall @error = 0 return = ђЖ¤ $a = abcdefgh $b = `Ж¤ But why? Where i wrong? It even not unicode...
JohnOne Posted June 27, 2016 Posted June 27, 2016 No idea what freebasic is, but... Probably partly because you say you are passing a pointer to a string in first parameter, but ask yourself how "abcdefgh" is a pointer to a string? Then look at the rest of the code as at a glance it all looks wrong. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
UEZ Posted June 27, 2016 Posted June 27, 2016 Try this. Test.bas / Test.dll Extern "Windows-MS" Dim Shared As String s Function Test(sString As ZString Ptr) As ZString Ptr Export s = Left(*sString, 5) Return StrPtr(s) End Function End Extern Test.au3 $sText = "Hello World" $aReturn = DllCall("Test.dll", "str", "Test", "str", $sText) ConsoleWrite($aReturn[0] & @CRLF) Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Iczer Posted June 28, 2016 Author Posted June 28, 2016 Thanks! its works... but only if return variable is declared outside function as shared. If i declare it inside function as "local" - dim as string - DllCall return "SUB" (\x1a) character: return = $a = abcdefgh Is there a reson for it? another question about unicode - if i pass to function some unicode word "いくつかのUnicodeの言葉" Extern "Windows-MS" '========================================================================================== Dim Shared As WString * 512 zz '========================================================================================== Function FunctionTest(xx as WString Ptr) as wString Ptr Export zz = Left(*xx, 5) return StrPtr(zz) End Function '========================================================================================== End Extern $h = DllOpen(@ScriptDir & "\TestProject.dll") ConsoleWrite("DllOpen @error = " & @error & @CRLF) $a = "いくつかのUnicodeの言葉" $b = "" $aRet = DllCall($h,"WSTR","FunctionTest", "WSTR", $a) ConsoleWrite("DllCall @error = " & @error & @CRLF) ConsoleWrite("return = " & $aRet[0] & " $a = " & $aRet[1] & @CRLF) _ArrayDisplay($aRet) it works, but FreeBasic on compile time return warning on "return StrPtr(zz)" string: E:\Program Files\FreeBASIC\FreeBASIC-1.05.0-win64\fbc -s gui -dll -export "TestProject.bas" TestProject.bas(10) warning 4(1): Suspicious pointer assignment Make done
UEZ Posted June 28, 2016 Posted June 28, 2016 Well, I'm a newbie in FreeBasic. Might be a good idea to create an account @ http://www.freebasic.net/forum/ and ask there for help. Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now