How to extract an integer from the VARIANT structure?
I am trying serial port communications between two computers.
1.To send data,one computer runs a DOS-based program and use _outp() to send an integer.
2.To receive data,the other runs a windows-based program developed using MFC of VC,and MSComm is used to receive data.
Now I have trouble in extract the integer from the VARIANT structure after trying all bVal,iVal,dblVal,lVal....the retrieved data from these members are not correct.
Please give a hand to me.Thank you very much!
Thanks,but it still exists some problem
I have tried your code,there is a compiling error in the sentence:
WORD wd = cVar;
I also tried COleVariant instead of _variant_t,the similiar error occurs.
the error message is:
cannot convert from 'class COleVariant' to 'unsigned short'. No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
the compiler is MS Visual C++
I use MS Visual C++ as the compiler.
the code cannot pass the compile because of the error I mentioned above.
Do you use the same compiler?
Re: the compiler is MS Visual C++
Quote:
Originally posted by onon
I use MS Visual C++ as the compiler.
the code cannot pass the compile because of the error I mentioned above.
Do you use the same compiler?
I'm using Visual C++.NET. and it works on that, but suprise suprise.....I tried it on VC++6 (I assume you have this one) and it didnt compile.
I think version 6's implementation of _variant_t lacked an operator short() function (now added on VC++.NET).
This will work on VC++6
Code:
void foo(VARIANT* lpVar)
{
_variant_t cVar(lpVar);
cVar.ChangeType(VT_I2);//assuming you want a 16 bit value
SHORT wd = cVar;
//do whatever with wd
}