Aashish
Aashish

Reputation: 13

How to convert CComBSTR to LPCSTR

I have CComBSTR in my code and have to pass it to function with argument type LPCSTR. How to convert CComBSTR to LPCSTR?

Upvotes: 1

Views: 337

Answers (1)

Simon Mourier
Simon Mourier

Reputation: 139157

There are many ways to do this, but the ATL way would be using Using MFC MBCS/Unicode Conversion Macros:

void SomeCode()
{
    USES_CONVERSION;
    CComBSTR bstr(L"hello world");
    LPCSTR lp = W2CA(bstr); // bstr is a LPWSTR
}

Upvotes: 1

Related Questions