Setting Types in C

BlitzMax Forums/BlitzMax Programming/Setting Types in C

Hi!

How can I set String Fields of BlitzMax Types in an external C function?

I've tried the following:
ref.bmx
SuperStrict

Framework BRL.Blitz

Import "ref.c"
Extern "C"
	Function getTest(test:Byte Ptr)
End Extern

Type TTest
	Field Foo:String
	Field Bar:String
	Field Info:String
	
	Method Debug()
		DebugLog(Foo + " " + Bar + " " + Info)
	End Method
End Type

Local test:TTest = New TTest

For Local i:Int = 0 Until 100
	getTest(test)
	test.Debug()
	Delay 100
Next

End


ref.c
#include <brl.mod/blitz.mod/blitz.h>
#include <windows.h>

typedef struct {
	BBString *Foo;
	BBString *Bar;
	BBString *Info;
} TTEST;

void getTest(TTEST *test) {
	BBRELEASE(test->Foo);
	BBRELEASE(test->Bar);
	BBRELEASE(test->Info)

	test->Foo = bbStringFromCString("Foo");
	test->Bar = bbStringFromCString("Bar");

	char info[255];
	sprintf(info, "%d ms", GetTickCount());
	test->Info = bbStringFromCString(info);
}


both in the same directory.

When I try to run ref.bmx in the debug mode I'am getting:
DebugLog:Foo Bar 2200671 ms
DebugLog:Foo Bar 2200765 ms
DebugLog:Foo Bar 2200875 ms
DebugLog:Foo Bar 2200968 ms
bad refs:obj=$c30670 refs=$7fffffff
String:Foo
bad refs:obj=$c30690 refs=$7fffffff
String:Bar
bad refs:obj=$c306b0 refs=$7fffffff
String:2195937 ms
bad refs:obj=$c30800 refs=$7fffffff
String:Foo
bad refs:obj=$c30820 refs=$7fffffff
String:Bar
...


When I comment out the BBRELEASE-Macro calls, I'am getting false results like:
DebugLog:Bar Bar 2554250 ms
DebugLog:Foo 2616703 ms 2616703 ms


So, how can I set BBStrings-Fields in C correctly?

cu olli