0

I can easily convert a 'const char *' to 'BSTR' using

BSTR bs = _bstr_t(myConstChar);

This works fine.

But I am not sure now to convert a BSTR to const char *.

I don't know what the function (like "_bstr_t") for such a conversion would be.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
tmighty
  • 10,734
  • 21
  • 104
  • 218
  • It has a conversion operator, just cast to (const char*). The buffer for that string is released at the same time as the _btr_t is destructed so copy if necessary. – Hans Passant Feb 14 '14 at 17:51
  • Pardon me? I don't understand this theoretical explanation. – tmighty Feb 14 '14 at 17:59

1 Answers1

0

Unfortunately there is not a true 1-1 mapping from a BSTR to a char*. The reason why is that a BSTR can hold values that a char* cannot like embedded null values. Outside of that though you can use the ConvertBSTRToString function (Link)

JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454