LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Having bad times creating safearray from array of c-strings

I'm working with Excel app ActiveX drivers and I want to write an array of c-strings at once using safearray. I've already done that with numeric values, but with an array of c-string, the functions "CA_Array2DToSafeArray" or "CA_Array1DToSafeArray" return me the same error code "E_OUTOFMEMORY" or 0x8007000E.

Any idea for correcting that prob will be welcomed.
0 Kudos
Message 1 of 2
(3,231 Views)
I'm not quite sure what function you are wanting to use to actually write to the Excel spreadsheet since you didn't specify so I can't really tell you if you are trying to format your data correctly or not. But since you did indicate that you were trying to place an array of strings into a safearray I can tell you how to do that.

I'm not really sure why you are getting that specific error when using either of the two functions you mentioned but the CA_Array1DToSafeArray function is the correct one to use. If you consider the following code you can prove to yourself in the CVI debugger that it is correctly placing an array of C Strings into a SafeArray since you can retrieve them with its inverse function (place a breakpoint at the return statement and vie
w the contents of str_array1 and str_array2 while it is running):

#include
#include

static LPSAFEARRAY safe_array;

char * str_array1[5];
char * str_array2[6];

int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */

str_array1[0] = "Hello!";
str_array1[1] = "Goodbye!";
str_array1[2] = "How are you?";
str_array1[3] = "Have a nice day.";
str_array1[4] = "Good and you?";

CA_Array1DToSafeArray (str_array1, CAVT_CSTRING, 5, &safe_array);

CA_SafeArrayTo1DArrayBufEx (&safe_array, CAVT_CSTRING, 0, str_array2,
20, NULL);

return 0;
}
0 Kudos
Message 2 of 2
(3,231 Views)