Gabriel Kniznik
"ken" <k...@1sthost.com> wrote in message news:#oiVtjx#$GA.60@cppssbbsa04...
> Hi,
>
> I need to copy a BSTR to a BSTR, how to do that?
>
> BSTR country=SysAllocString(L"US");
>
> newVal="UK"; from function input
>
> country=newVal??????
> use memcpy, how to deal with the string length?
>
> thanks
>
>
Steve
myfunc(BSTR val)
{
CComBSTR country;
country = val;
}
CComBSTR handles much of the memory allocation / destruction for you. Also
there is the compiler supported BSTR class _bstr_t that has similar
functionality.
--
Howard M. Swope III [hsw...@spitzinc.com]
Software Engineer
Spitz, Inc. [http://www.spitzinc.com]
"ken" <k...@1sthost.com> wrote in message news:#oiVtjx#$GA.60@cppssbbsa04...
BSTR bstrSource = L"Source";
BSTR bstrTarget;
(Case 1 - ATL-Inner module call)
CComBSTR bstrSource( bstrSource );
(Case 2 - ATL-Interface output retval parameter)
bstrSource.CopyTo( &bstrTarget );
(Case 3 - simplest, but unstable state in ATL-modules)
bstrTarget = _bstr_t( bstrSource ).copy();
Test it:
::MessageBox( NULL, ( char* )_bstr_t( bstrTarget ), "Result", MB_OK );