Error dll function returning String made with bmax

BlitzMax Forums/BlitzMax Programming/Error dll function returning String made with bmax

patmaba(Posted 2007) [#1]
Hi,

I have created a dll with somme functions returning String value.

I have problems with one of them to test my exemple. Here my scenario


code into the dll source
Function GetMyString:String()
Local ls_msg:String = "Test de retour de valeur au format string"
Return ls_msg
End Function

code call the dll
Global GetMyString() = GetProcAddress ( Library , "GetMyString" )
...
DebugLog "GetMyString=" + GetMyString()

output is
DebugLog:GetMyString=269114428

Where is the problem, a bad conversion of String Type ?
How to convert correctly the string return value ?

Thanks


Perturbatio(Posted 2007) [#2]
you could try returning a $z instead (cstring).

You may have to use
Return ls_msg.toCString()



patmaba(Posted 2007) [#3]
I have made your change. I receveid an error
Where is bad ?

Function GetMyStringC$()
Local ls_msg$ = "Test de retour de valeur au format string"
Return ls_msg.ToCString()
End Function

Compile Error: Unable to convert from 'Byte Ptr' to 'String'


Azathoth(Posted 2007) [#4]
In the dll
Function GetMyString:byte ptr()
Local ls_msg:String = "Test de retour de valeur au format string"
Return ls_msg.ToCString()
End Function


And in the test program
Global GetMyString:byte ptr() = GetProcAddress ( Library , "GetMyString" )
...
DebugLog "GetMyString=" + String.FromCString(GetMyString())



patmaba(Posted 2007) [#5]
thanks it work

Function GetMyStringC:Byte Ptr()
Local ls_msg:String = "Test de retour de valeur au format string"
Return ls_msg.ToCString()
End Function

Global GetMyStringC:Byte Ptr() = GetProcAddress ( Library , "GetMyStringC" )

DebugLog "GetMyStringC=" + String.FromCString(GetMyStringC())

DebugLog:GetMyStringC=Test de retour de valeur au format String


Azathoth(Posted 2007) [#6]
You might want to free the byte ptr when you no longer need it as blitzmax doesn't do this automatically, or pass a pointer to GetMyString for it to set the contents instead.


patmaba(Posted 2007) [#7]
And what is the command to free a byte ptr in blitmax please ?


Brucey(Posted 2007) [#8]
MemFree(myBytePtr)



patmaba(Posted 2007) [#9]
thank you

Now, i'm currently tryning to use the function into b3d.
And i have problem to interface.
Cn you hlpe me pplease ?

http://www.blitzmax.com/Community/posts.php?topic=67816


patmaba(Posted 2007) [#10]
In blitz3d, im tryning to get and send string value into dll
fort GetMyString:byte ptr

I receive a message "user lib function not found".

What is the solution to interface correctly bmax dll with b3d code when i use Byte Ptr() String value or String data type ?

Can you help me please ?