AksharRoop
AksharRoop

Reputation: 2293

How does it convert _bstr_t to BSTR when passing as an argument?

Taking a simple example:

_bstr_t smartString(L"MyString");

Process(smartString); // takes BSTR.

Initially I thought _bstr_t has a BSTR operator converting from _bstr_t to BSTR, but looking at msdn there is no such operator defined.

How does it work when passign _bstr_t to BSTR parameter or _variant_t to VARIANT?

Upvotes: 3

Views: 3802

Answers (2)

Armin Horn
Armin Horn

Reputation: 1

If I understand your problem correctly, you want to call a method that expects BSTR*. There is no implicit conversion. Instead, use the GetAddress() parameter for the conversion.

void foo( BSTR* ) {...}

void f()
{
   _bstr_t myBstr;
   foo( myBstr.GetAddress() );
}

Upvotes: 0

sharptooth
sharptooth

Reputation: 170489

BSTR is typedefed to be WCHAR* (wtypes.h file) and the latter is typedefed to be wchar_t* (winnt.h file) and _bstr_t has operator wchar_t*() member variable. So the compiler just uses that operator for conversion.

Upvotes: 3

Related Questions