Creating a FORTRAN interface to a C function that returns a char*

I've been held up on this for about a week, now, and have searched forum after forum for a clear explanation of how to send a char* from C to FORTRAN. To make the matter more frustrating, sending a char* argument from FORTRAN to C was straight-forward...

(I can't literally use the DIMENSION(*), so I've gone oversize to 255.)

This should return a pointer to an array of 255 C-style characters - but if it does, I've been unable to convert this to a meaningful string. In practice, it returns a random set of characters, anywhere from Wingdings to the 'bell' character...

I've also attempted to return:

A pointer to CHARACTER(LEN=255, KIND=C_CHAR).

Literally CHARACTER(LEN=255, KIND=C_CHAR).

A INTEGER(C_SIZE_T), and tried to finesse that into a pointer to a string array.

A CHARACTER.

etc.

If anybody can give me an example of how to do this, I would be very grateful...

Strings of dynamic length are always a bit tricky with the C interaction. A possible solution is to use pointers.

First a simple case, where you have to hand over a null-character terminated string to a C-Function. If you really pass the string only in, you have to ensure to finalize it with the c_null_char, thus this direction is pretty straight forward. Here are examples from a LuaFortran Interface:

Now the little more complex case, where we have to deal with a returned string from C with a dynamic length. The most portable solution I found so far is using pointers.
Here is an example with a pointer, where the string is given by the C-Routine (also from the
Aotus library mentioned above):