1

I'm using Comm32 (an activeX control) to get data coming through serial port using the method GetInput(). This method returns a _variant_t, so I need to convert it to an array of unsigned char's.

When serial port is configured to TextMode (this is data input is interpreted as String), converting the Variant to a BSTR and then to a CString works as expected (code not writed by me):

_variant_t x = m_comm32.GetInput();
CString cs = x.bstrVal;

However, as data sent through serial port is actually binary data, when configuring comm32 to interpret data as binary the sample code above doesn't give me the valid data. So I think I need to convert it to another format (unsigned char array maybe? that's somehting I want to test).

My problem is I'm getting crazy as I cannot find any detailed info about how to convert data from a VARIANT structure. How can I convert the variant to an unsigned char array??

Pherrymason
  • 7,835
  • 8
  • 39
  • 57

1 Answers1

1

The InputMode property determines the type of data that is retrieved with the Input property. If InputMode is set to comInputModeText then the Input property returns text data in a Variant. If InputMode is comInputModeBinary then the Input property returns binary data in an array of bytes in a Variant. (from msdn)

To understand how to get data from the safearray see examples sample1 or sample2

Community
  • 1
  • 1
Victor
  • 3,497
  • 3
  • 39
  • 51