Click to See Complete Forum and Search --> : C++, VB ActiveX and VARIANT's


Berthold Hutten
March 29th, 1999, 07:56 AM
Hi,


I'm not a very well C++ programmer, and I have the following problem:

I've a VB activex with successfully is merged with my C++ project. So far no problem. But now I want to invoke a method of the VB ActiveX, the method looks like:


virtual /* [id] */ HRESULT __stdcall GetValue(

/* [in] */ VARIANT sCategory,

/* [in] */ VARIANT sName,

/* [defaultvalue][optional][in] */ VARIANT sDefault,

/* [retval][out] */ VARIANT __RPC_FAR *__MIDL_0015) = 0;


The method call would be something like:


mGlobals->GetValue(sCategory, sName, sDefault, RetVal);


My problem is type casting between the VARIANT's and some CString's I have.

Can somebody give me an example of how the convert VARIANT's to CString's or any other type I can better use. (I can use some tips on with type to use for strings).


Thanks in advance.


Regards,

Berthold Hutten

Daren Chandisingh
March 29th, 1999, 08:23 AM
I don't know the *best* way, but this should work:


----

VARIANT sValue;


// construct a new _bstr_t from the VARIANT

_bstr_t bstrVal(sValue);


// construct a new CString using the char * operator on the _bstr_t object.

CString strVal((char *)(bstrVal));

Rich
March 30th, 1999, 06:15 AM
How about


VARIANT Var;


CString strValue = Var.bstr;


Or


Var.bstr = strValue.AllocSysString();


Good Luck


Rich