Sometimes it might be necessary to return a CSTRING
from Clarion function. For instance you need to pass
a value to the program which is not written by you
and this program expects a dll with the following
function: Afunc(USHORT),CSTRING,C,RAW. (In C it looks
like: char* afunc(int);)
In Windows and other systems STRING is usually an
array of characters ending with the ASCII 0 character.
Strings returned by the functions (and parameter strings)
are passed as a string address.
Clarion allows to call functions returning 0-terminated
strings written in other languages (e.g. Afunc(USHORT),CSTRING,C,RAW
) but does not allow to create such functions. The
help explicitly states "Variable return types are
provided just for prototyping external library functions
written in another language) which return only the
address of data they are not valid for use on Clarion
language procedures. " The chapter about multi-language
programming from the "Programmers Guide" says that
if you need to pass a CSTRING to a program written
in another language you can not do it via RETURN but
should use *CSTRING parameter instead.
If you are not satisfied with that you could try the
Create a function which return LONG value and return
the address of a static CSTRING variable (using Clarion
Afunction (SHORT ID), LONG,C,Name('_afunction')
Afunction PROCEDURE (SHORT ID)
STATIC attribute for the LOC:RetStr is required in
order to place this variable in a static memory. Otherwise
this variable will disappear right after RETURN operator.
On the calling side this function needs to be described
in a C program this function needs to be described