GLBasic forum

Main forum => GLBasic - en => Topic started by: MushroomHead on 2009-Jun-25

Title: Returning strings from a function
Post by: MushroomHead on 2009-Jun-25
Code (glbasic) Select

b$ = test2()
PRINT b$, 100, 100
SHOWSCREEN
MOUSEWAIT
END

FUNCTION test2:
LOCAL a$
a$ = "HelloWorld"
RETURN a$
ENDFUNCTION


Why doesn't this work?
Title: Re: Returning strings from a function
Post by: Kitty Hello on 2009-Jun-25
FUNCTION test2$:
Title: Re: Returning strings from a function
Post by: MushroomHead on 2009-Jun-25
Thanks, one other question, when exporting strings as a DLL is this correct?
Code (glbasic) Select

EXPORT test2$

FUNCTION test2$:
LOCAL a$
a$ = "HelloWorld"
RETURN a$
ENDFUNCTION


Is this right? When dumping the DLL I get a function called test2_Str but when I call this function I get a crash. How are strings returned i.e. are they like "C" strings with a null "\0" terminator?

This is how I call it in powerbasic :-

Code (glbasic) Select

DECLARE FUNCTION test2 CDECL LIB "test.dll" ALIAS "test2_Str" () AS STRING

FUNCTION PBMAIN () AS LONG
    MSGBOX test2()
END FUNCTION


Title: Re: Returning strings from a function
Post by: Schranz0r on 2009-Jun-25
you receive a 100% C++ const char*