Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VARIANT Data Type

Status
Not open for further replies.

Saul775

Programmer
Aug 9, 2004
11
US
Hello:

I've a question about VARIANT. I'm calling an ActiveX method called GetData().

VARIANT data;
Client->GetData(1, 1, 1, 1, &data);

The arguments in the .tli are as follows...

inline enum ReturnValue Server::GetData(short Address, short Parameter, short StartIndex, short NumValues, VARIANT * values)

I'm trying to get the information stored in data. However, I cannot properly interpret the information. When I debug it, I know I want data.vt to be VT_R4 -- defining the variant as a float -- but it seems that data.vt is actually 8204 when I execute the code. When I look up the .vt number online, I see that it's an array. Now, reading the documentation which came with the software, it indicates that the variable "values" is "an array of values containing the requested data."

How can I obtain the value of the variant in terms of a float?
 
That is to say, when I try to acquire the value in the following fashion...

float x;
x = data.fltVal;

or

float x;
x = (float)data.fltVal;

*shrugs* I thought casting it might help. It doesn't. Any help would be much appreciated. Thank you, all.
 
Well, I solved the problem. One must note that a variant was passed into the function, and the type (data.vt = 8204). Well, while looking at the types, I determined that VT_ARRAY (8192) accompanied a bit-wise OR with VT_VARIANT (12), yields 8204, which is data.vt.

In all, it's an ARRAY of VARIANTS.

To access the data, create a variant pointer...

Code:
VARIANT* pData;
SafeArrayAccessData(data.parray, (void**)&pData);

float x;
x = pData[0].fltVal;

SafeArrayUnaccessData(data.parray);

Well, that's it. I hope this helps anyone who encounters this same problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top