LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with VARIANT parameters being passed by OCX

I am having problems with a function in a DLL that is being called by a customer supplied OCX.  I have included the relevant source code below:
 
char* __stdcall test_to_perform(int communications_port, VARIANT serial_number, VARIANT model_type)
{
  unsigned long id;
  char model[25];
  char *pointer;
  int com_port;
 
  com_port = communications_port;
 
  CA_VariantConvertToType(&serial_number, CAVT_CSTRING, &pointer);
  Scan(pointer, "%s>%i", &id);
 
  CA_VariantConvertToType(&model_type, CAVT_CSTRING, &pointer);
  strcpy(model, pointer);
  ...
 
If the following values are passed to the function by the OCX:
communications_port:    1
serial_number: "123456789A"
model_type:    "ABCDEFGHIJ"
 
The value of the local variables are:
com_port:  1
model:    65 (ASCII value for 'A')
id:       49 (ASCII value for '1')
 
When I look at the variable views for 'serial_number' and 'model_type', the following is shown:
serial_number: {VT_UI1 | VT_BYREF, 49}
model_type:    {VT_UI1 | VT_BYREF, 49}
 
What can I do to get the correct values for the VARIANT variables that are passed from the OCX?
 
Thanks in advance,
Mitch
0 Kudos
Message 1 of 4
(3,435 Views)
The function CA_VariantConvertToType can work, but it all depends how that Variant is actually stored in the OCX. Since it will be an array, the type must match exactly. If the Variant is a safe-array, it must be converted to a safe-array. If it is a BSTR, it must be converted to a BSTR. Once you get it to this form, you can use one of the conversion functions in order to convert to a c-style string.

Brandon Vasquez | Software Engineer | Integration Services | National Instruments
0 Kudos
Message 2 of 4
(3,416 Views)
I got some more information about the OCX from the customer.
 
The VARIANTS were defined in the OCX as follows:
 
varParamSN.vt=VT_BYREF|VTUI1;
varParamSN.pbVal=serial_no;
 
varParamModel.vt=VT_BYREF|VTUI1;
varParamModel.pbVal=model_type;
 
I was able to get the correct values in my DLL with the following statements:
 
Scan(serial_number.n1.n2.n3.pbVal, "%s>%i", &id);
strcpy(model, model_type.n1.n2.n3.pbVal);
 
Thanks,
Mitch
0 Kudos
Message 3 of 4
(3,396 Views)
Mitch,

Good to hear you got it working, with the VARIANTs defined like that it really is much easier to just use the Scan function or strcpy since a direct conversion function is not available.

Brandon Vasquez | Software Engineer | Integration Services | National Instruments
0 Kudos
Message 4 of 4
(3,378 Views)