Returning strings from a dll and freeing C strings

BlitzMax Forums/BlitzMax Programming/Returning strings from a dll and freeing C strings

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I return strings from dlls like this:

global ReturnString:Byte ptr

Function GetString:Byte Ptr()
GCEnter()
ReturnString="Hello".tocstring()
return ReturnString
EndFunction


Now for the same of memory management, I believe it should be like this:
global ReturnString:Byte ptr

Function GetString:Byte Ptr()
GCEnter()
If ReturnString<>Null MemFree ReturnString
ReturnString="Hello".tocstring()
return ReturnString
EndFunction


However, this causes a crash in my program. Do I need to manually free the byte ptr like this?