LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how to return a safe array/variant from a CVI DLL to visual basic?

I am trying to return a safe array from a CVI Dll to visual basic. I can successfully call CVI functions from VB and return simple types like int , double etc but when I try to return a Safe Array then the "generate visual basic module" gives me error.
The line that give error in the header file to generate the visual basic module is
LPSAFEARRAY* getAmplitudes() ;

and the function where i generate the safe array is

LPSAFEARRAY* getAmplitudes()
{
CA_Array1DToSafeArray (Amplitudes, CAVT_DOUBLE, iterations, safeArray);
return safeArray;
}
0 Kudos
Message 1 of 3
(2,802 Views)
Try putting the safearray in a VARIANT with CA_VariantSetSafeArray and returning the VARIANT instead of the safearray. Something like:

VARIANT* getAmplitudes()
{
VARIANT vArray;

CA_Array1DToSafeArray (Amplitudes, CAVT_DOUBLE, iterations, safeArray);
CA_VariantSetSafeArray (&vArray, CAVT_DOUBLE, safeArray);

return &vArray;
}

Best Regards,

Chris Matthews
National Instruments
0 Kudos
Message 2 of 3
(2,802 Views)
I tried doing that but the generate visual basic include option gives the following error

syntax error found '*' expecting ';'

I had included the following line
VARIANT* getPWArray(int dummy) ;

Then I included , i.e

#include
VARIANT* getPWArray(int dummy);

in that case it gives an error "invalid visual basic return type pointer"

Then I removed the "*" i.e

#include
VARIANT getPWArray(int dummy);

in that case it gives the error
invalid visual basic return type VARIANT.

seems like only simple types like int , char etc are allowed to be returned to VB.

thanks for your help!
0 Kudos
Message 3 of 3
(2,802 Views)