X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 11 Dec 2009 02:43 PM by  anon
CALL_EXTERNAL and C style strings
 0 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
11 Dec 2009 02:43 PM
    I've got some C functions in a dynamic lib (DLL on windows) and I'm trying to call them with CALL_EXTERNAL. There are quite a few funcs of the form: uint32_t func(char* buf, uint32_t bufsz); This is first called as func(NULL, 0) and the return val is the strlen() of a string returned by the function. Next, a char buffer is allocated of the correct size and the function is called again. func(buffer, buffersz); The string data is memcpy'd into buffer. I can get the basic call working on a test function (returns short strings so I skip the strlen check in the example). buf='0000000000000000' sz=call_external(dllname,'func',buf,strlen(buf),/cdecl,/auto_glue,/all_value) This works ok...buf is the same length as I initialize it too but I can call MID(buf, 0, sz) to get a minimal string. The problem I have is figuring out how to do the dynamic allocation. STRING(BYTARR(sz)) yields a zero length string and I don't think I can count on BYTARR(sz,/nozero) not having 0's in it somewhere. Does anyone have any ideas? (or a better way to call these functions...I can't change the functions to take an IDL_STR and I'd really like to avoid hand rolling a wrapper function if I can)
    You are not authorized to post a reply.