How to convert CComBSTR to LPCSTR

Viewed 60

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

1 Answers

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
}
Related