Re: Convert _bstr_t to c_str by Sergei
Sergei
Mon Jun 21 02:32:33 CDT 2004
"Carl Daniel [VC++ MVP]" <cpdaniel_remove_this_and_nospam@mvps.org.nospam> wrote in message
news:uzIZYXnVEHA.3788@TK2MSFTNGP11.phx.gbl...
> pat wrote:
> > Is the following correct?
> >
> > char* c_str;
> > _bstr_t b;
> > ...
> > c_str = b;
> >
> > If correct, how could an ANSI char* pointer get pointing at a memory
> > of unicode string?
>
> _bstr_t automatically converts to a narrow-character string and returns a
> pointer to a temporary buffer when you invoke the const char* conversion
> operator (which the code above does).
That assignment invokes the char* conversion not the const char* and the
returned pointer points to the actual internal _bstr_t's char * buffer, which
is as temporary as the _bstr_t itself is. Though the buffer is only allocated
if requested by such conversion.
Sergei
> -cd