Click to See Complete Forum and Search --> : VARIANT types


Jim Bassett
April 8th, 1999, 01:14 PM
How does one set a double type to a VARIANT RT_8 type?

Thanks

rick
April 9th, 1999, 01:24 PM
Hi Jim

There are two ways of doing this:
1)Here is some code to demonstrate the usage of the VARIANT type.
//----
VARIANT v_Var;
double d = 1.6;
v_Var.vt = VT_R8;
v_Var.dblVal = d;
//----
2) You can also create a COleVariant object and pass the double in the constructor. The COleVariant will be accepted anywhere the VARIANT is called for.

Hope this works out for you :o)

Rick
P.S. Send me a line to tell me how it worked out.

Rick
April 9th, 1999, 01:24 PM
Hi Jim

There are two ways of doing this:
1)Here is some code to demonstrate the usage of the VARIANT type.
//----
VARIANT v_Var;
double d = 1.6;
v_Var.vt = VT_R8;
v_Var.dblVal = d;
//----
2) You can also create a COleVariant object and pass the double in the constructor. The COleVariant will be accepted anywhere the VARIANT is called for.

Hope this works out for you :o)

Rick
P.S. Send me a line to tell me how it worked out.

Stephen Yip
April 9th, 1999, 11:31 PM
Rick,

I've been stuck on a VARIANT problem for some time. I wonder if you could help shed some light.

I have a MS ActiveX control. One of its methods is declared as:

void SetOutput(const VARIANT& newValue);

I'm quite sure that the method accepts only the BSTR part of the VARIANT. The method behaves as expected when I pack it with a BSTR with 1 or more characters:

CString cstrTemp = "a";
varTemp.vt= VT_BSTR;
varTemp.bstrVal = cstrTemp.AllocSysString();
SetOutput(varTemp);

However, I wish to call the method with a NULL character (i.e. 0x00). The question is: How do I put a 0x00 in the VARIANT as a BSTR?

Thanks,

NB. the control is MSComm32.ocx


--
Stephen

kmtambasc98
April 10th, 1999, 04:12 PM
COleVariant has these Constructors:

COleVariant( LPCTSTR lpszSrc );
COleVariant( LPCTSTR lpszSrc, VARTYPE vtSrc );
COleVariant( CString& strSrc );

I'm sure you could fill a CString or the LPCTSTR string to a Null character, and then use the VARIANT operator to pass it along as the parameter for your function. Im not able to test this out, but this may work:

TCHAR temp[1];
temp[0] = '\0';
CString temp2(temp);
COleVariant var(temp);

The last line of code will give you your variant. Then call your function:

FunctionCall((VARIANT)var);

Hope this helps, again I haven't tried this out, but it should work.

rick
April 12th, 1999, 03:22 PM
To pass an empty VARIANT try;

variant.vt = VT_NULL;
or
variant.vt = VT_EMPTY;

in the help there is somthing about put in VT_ERROR but I'm not to shure how that works.

Rick

Rick
April 12th, 1999, 03:22 PM
To pass an empty VARIANT try;

variant.vt = VT_NULL;
or
variant.vt = VT_EMPTY;

in the help there is somthing about put in VT_ERROR but I'm not to shure how that works.

Rick