如何将CComBSTR转换为LPCSTR



我的代码中有CComBSTR,必须将其传递给参数类型为LPCSTR的函数。如何将CComBSTR转换为LPCSTR

有很多方法可以做到这一点,但ATL的方法是使用MFC MBCS/Unicode转换宏:

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

最新更新