CString to const variant&

Hi,
i want to call a function that has a parameter of type const VARIANT&.
i want to pass a string as parameter.

i try to do like this

VARIANT Var;
Var.vt = VT_BSTR;
Var.pbVal = (unsigned char *) LPCTSTR("Testing string");
function(Var);

but i use watch window to watch Var variable and it shows {"" VT_BSTR}

so i try other method

Var.vt = VT_BSTR;
Var.bstrVal = (unsigned short*) LPCTSTR("Testing string");

the same thing happen, what have i did wrong ?
How to convert string value to VARIANT ?

thanks
[597 byte] By [weiwei] at [2007-11-19 6:38:38]
# 1 Re: CString to const variant&
i want to call a function that has a parameter of type const VARIANT&. i want to pass a string as parameter.Note that variants require a BSTR: You can't simply copy an existing LPCTSTR, since BSTRs are always UNICODE and have an additional length field. You can reallocate an existing BSTR from a CString via SetSysString(), or create a new one with AllocSysString(). As for dealing with variants, I would suggest to use the handy class COleVariant (since you're using MFC anyway).
gstercken at 2007-11-11 0:30:32 >
# 2 Re: CString to const variant&
Thanks , it works.

I use SetSysString() to reallocate BSTR then the watch window show the string value.
weiwei at 2007-11-11 0:31:34 >