Hi all, I'm using CALL_EXTERNAL to run a C function. This functions well - I can call it and it runs fine. My question relates to how to return an array from this function. I've tried changing the return type to a pointer, but I can't make this work. I've also tried passing a pointer to the array as an input value, modifying the array within the function, and then returning void. If I do so, when I try to access in IDL the array I modified in C, the array has not been modified. The examples that come with CALL_EXTERNAL only cover the passing in of arrays, and returning e.g. the sum. Can anyone point me to the correct way to do this, or definitely rule out the possibility? Any help would be greatly appreciated. See below for a MWE. Thanks, Sam pro test_call frame = dblarr(10*10) CALL_EXTERNAL(GET_CALLEXT_EXLIB_NEW(), 'test_ext', frame, VALUE=[0], /CDECL) print, frame end Then in test_ext.c: #include <stddef.h> #include <stdio.h> #include <math.h> #include <time.h> #include <stdlib.h> #include <string.h> #include "idl_export.h" void test_ext(int argc, void argv*[]) { double *input = argv[0]; long i, j; for (i=0; i<10; i++) for (j=0; j<10; j++) input[i + 10*j] = 1.0; return; } Finally, the get_callext_lib_new.pro: function get_callext_exlib_new, VERBOSE=verbose common GET_CALLEXT_EXLIB_BLK, shlib ; Build sharable library if this is the first call or lib doesn't exist build_lib = n_elements(shlib) eq 0 if (not build_lib) then build_lib = not FILE_TEST(shlib, /READ) if (build_lib) then begin ; Location of the CALL_EXTERNAL files from the IDL distribution call_ex_dir = '.' source = [ 'test_ext' ] export_rtns = [ 'test_ext' ] MAKE_DLL, source, 'call_external_new', export_rtns, $ INPUT_DIR=call_ex_dir, DLL_PATH=shlib, $ VERBOSE=verbose, SHOW_ALL_OUTPUT=verbose endif return, shlib end I expect to be able to call `print, frame' in IDL afterwards and get an array of 1s - instead, I get an array of 0s.
|