开发者

convert VARIANT to unsigned char array

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 canno开发者_运维百科t find any detailed info about how to convert data from a VARIANT structure. How can I convert the variant to an unsigned char array??


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜