Error dll function returning String made with bmax

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

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

you could try returning a $z instead (cstring).

You may have to use
Return ls_msg.toCString()


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'

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


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

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.

And what is the command to free a byte ptr in blitmax please ?

MemFree(myBytePtr)


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

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 ?