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.

This is what i use to copy data from a String directly to a buffer, bypassing ToCString()
i really wish the String class could do this ;)
#include "E:\Program Files\BlitzMax\mod\brl.mod\blitz.mod\blitz_string.h"

int CopyToCString( BBString *str, char *dst, int maxlen) {
	int i, sz;
	if( str->length+1 >= maxlen)
		sz = maxlen - 1;
	else
		sz = str->length;
	for( i=0; i<sz; i++) 
		dst[i] = str->buf[i];
	dst[sz] = 0;
	return sz;
}

Then you could alternatively do this:
Function GetString:Int( buffer:Byte Ptr, maxlen:Int)
   Return CopyToCString( "Hello World!", buffer, maxlen)
EndFunction