03-11-2007 08:34 AM
03-11-2007 01:20 PM
I can see two ways to develop your function:
In the first case you can take as an example ConvertArrayType function in AdvancedAnalisys Library, whose definition is as follows:
void CVIFUNC ConvertArrayType(const void *sourceArray, int sourceDataType, void *targetArray,
int targetDataType, int numberOfPoints);
As you can see, a void pointer is passed to the function together with a data type field that describes which type is passed array. The function can then properly handle the array passed to it.
In the second case, CA_VariantGetType () function can be used to retrieve the data type associated to the variant and correctly retrieve data in a properly allocated array. A sample on using this function can be found in DataTypesServer and DataTypesClient samples located in <cvidir>\samples\activex\servers\DataTypes folder.
03-12-2007 09:45 AM
Hi Roberto,
I tried the 2nd option & it worked, however I need a bit more help on the retrive information: Here my codes:
#include <cviauto.h>
void GetVariantValues (VARIANT *var_ptr)
{
unsigned int i_val = 12;
double db_val = 34.56;
char *str = "ABC";
CA_VariantSetInt (var_ptr, i_val);
var_ptr++;
CA_VariantSetDouble (var_ptr, db_val);
var_ptr++;
CA_VariantSetCString (var_ptr, "ABC");
}
int main (int argc, char *argv[])
{
VARIANT var_ptr[3];
int i_type;
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
// Just for clarify the CAVT type numbers
i_type = CAVT_UINT; // = 103
i_type = CAVT_DOUBLE; // = 105
i_type = CAVT_CSTRING; // = 115
GetVariantValues (var_ptr); // var_ptr returns with 3 different types successfully
i_type = CA_VariantGetType (var_ptr); // first value return is i_type = 103 (CAVT_UINT)
var_ptr++; // ********** If add this line ---> ERROR COMPILE *****************
return 0;
}
I saw var_ptr return with all values I need to recieve but I can not retrieve the 2nd & 3rd values ... can you help here? I tried to increase the pointer or use var_ptr[1] or var_ptr[2] ---> compile error!
Many thanks
03-12-2007 10:14 AM
Hi again,
I did find the way to increase the pointer as the following:
i_type = CA_VariantGetType (var_ptr);
i_type = CA_VariantGetType (var_ptr+1);
i_type = CA_VariantGetType (var_ptr+2);
And it works, thanks for help
03-12-2007 10:23 AM
Yes, it's equivalent to the notation &var_ptr[x] I am using in this sample code, that can be run in the interactive window:
#include <cviauto.h>
#include <utility.h>
static VARIANT var_ptr[3];
static int i_type;
static unsigned int i_val = 12;
static double db_val = 34.56;
static char *str = "ABC";
static int xi, i, type[3];
static double xd;
static char *msg;
// Just for clarify the CAVT type numbers
i_type = CAVT_INT; // = 103
i_type = CAVT_DOUBLE; // = 105
i_type = CAVT_CSTRING; // = 115
CA_VariantSetInt (&var_ptr[0], i_val);
CA_VariantSetDouble (&var_ptr[1], db_val);
CA_VariantSetCString (&var_ptr[2], "ABC");
msg = malloc (32); memset (msg, 0, 32);
DebugPrintf ("Received types\n");
for (i = 0; i < 3; i++) {
type[i] = CA_VariantGetType (&var_ptr[i]); // first value return is i_type = 103 (CAVT_UINT)
switch (type[i]) {
case CAVT_INT:
CA_VariantGetInt (&var_ptr[i], &xi);
DebugPrintf ("%d: Type %d - Value %d\n", i, type[i], xi);
break;
case CAVT_DOUBLE:
CA_VariantGetDouble (&var_ptr[i], &xd);
DebugPrintf ("%d: Type %d - Value %f\n", i, type[i], xd);
break;
case CAVT_CSTRING:
CA_VariantGetCString (&var_ptr[i], &msg);
DebugPrintf ("%d: Type %d - Value %s\n", i, type[i], msg);
break;
}
}
03-13-2007 02:54 PM