Returning strings from a function

Previous topic - Next topic

MushroomHead

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?

Kitty Hello


MushroomHead

#2
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



Schranz0r

you receive a 100% C++ const char*
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard