| Re: CALL_EXTERNAL and strarr() [message #18229 is a reply to message #18212] |
Thu, 09 December 1999 00:00  |
rivers
Messages: 228 Registered: March 1991
|
Senior Member |
|
|
In article <384E7B7E.6672F751@sbrc.umanitoba.ca>, Richard Tyc <richt@sbrc.umanitoba.ca> writes:
> I need to call an external C function (unix/shared lib method) which
> will collect a string array of different size strings. I have been
> using call_external with success on returning other types (floats,
> strings etc) but this seems more challenging. The problem being I don't
> know how large each string will be in the string array so it needs to be
> dynamically allocated.
>
>
> I know the following can pass IN a string array and return a single
> string:
>
> replyStr = CALL_EXTERNAL('IDLquery_call.so','GetPatientList',strarr,$
> N_ELEMENTS(strarr), /S_VALUE)
>
> the key point in the C function being to make the returned string static
> to avoid memory leaks.
>
> Anyone care to point out how I might be able to retrieve a string array.
I have done this by having IDL pass a 2-D byte array, where the first dimension
is the maximum length string which can be returned. Null terminate each string
in your C code, and then convert the byte to array into a string with
s = string(byte_array)
after it is returned to IDL.
Mark Rivers
|
|
|
|