This post in honor to the memory of Hermann Hoch, R.I.P. Thank You HH!
Not really documented anywhere AFAIK, but when you need to receive a string from a pointer to a C Char string ( *char) from a function in a foreign library, there is a function in libFoundation to convert a Pointer to a zero terminated C-string into a LiveCode String type:
Code: Select all
foreign handler MCStringCreateWithCString(in pCharStringPtr as Pointer, out rString as String) returns CBool binds to "<builtin>"
Use it like this:
Code: Select all
variable tStrPtr as Pointer
variable tString as String
put c_Foreign_Func_That_Returns_Char_Pointer() into tStrPtr
if MCStringCreateWithCString(tStrPtr, tString) then
log tString
end if
For passing to a *char type, you can instead use ZStringNative (or the other variations like Unicode). But for receiving, the LCB VM will let you use ZStringNative to receive a *char too, but it only works once (while the pointer is still valid I guess) and then the next time you try to use your function the engine will crash! Instead define your foreign function to return the actual *char Pointer to the *char back 'as Pointer' and then use the function above to turn it into a LiveCode String.