_bstr_t BString;
char String[100];
BString = "Hello World!"; // automatic conversion
strcpy(String, (char*)BString); // uses operator const char*( ) const throw(
_com_error )
std::string stdString;
stdString = (char*)BString;
BSTR bstrText = ::SysAllocString(L"Test");
char* szText = _com_util::ConvertBSTRToString(bstrText);
::SysFreeString(bstrText);
Take it easy.
--
Ajay Kalra [MVP - VC++]
ajay...@yahoo.com
"Peter Olcott" <NoS...@SeeScreen.com> wrote in message
news:7Itsh.65205$kn7....@newsfe23.lga...
bstr_t BString;
char String[100];
BString = "Hello World!";
char* temp = (char*)BString;
strcpy(String, temp);
delete temp[];
and
std::string stdString;
char* temp = (char*)BString;
stdString = temp;
delete temp[];
-Nick
You can just call the coversion constructor directly:
_bstr_t bstring( "Hello World" );
> strcpy(String, (char*)BString); // uses operator const char*( )
I'm not sure what you're wanting to do with the above, but it's not needed
for the conversion to std::string
> const throw( _com_error )
This is invalid code in this context.
> std::string stdString;
> stdString = (char*)BString;
You'll want to use _bstr_t::operator const char*() here. And it's best to
call the conversion constructor directly as in either of the two statements:
std::string stdString( (const char*)bstring );
std::string stdString = (const char*)bstring;
I'm not sure if BSTR's can have embedded nulls. If so you'll need to use:
std::string stdString( (const char*)bstring, bstring.length() );
Jeff Flinn