これが私の必要性です
BSTR l_strArgs;
LPCWSTR sth;
//----
//---
OutputDebugStringW(sth);
BSTR を LPCWSTR に変換するには?
文字列型 (Microsoft) を LPCWSTR 型に変換するヘッダーのみのライブラリはありますか?
Just cover NULL
scenario and you're good to go
BSTR l_strArgs;
LPCWSTR sth = strArgs ? strArgs : L"";
As you mentioned ATL in the tag, here is ATL-style one-liner:
OutputDebugString(CString(l_strArgs));
or, to make sure you are staying in Unicode domain:
OutputDebugStringW(CStringW(l_strArgs));
私はちょうどこれを見つけました
BSTR l_strArgs;
LPCWSTR sth;
CString cs(_com_util::ConvertBSTRToString(l_strArg));
sth = cs;
OutputDebugStringW(sth);
代わりに _bstr_t のようなラッパーを使用すると、BSTR の処理が容易になります。それらに関するマイクロソフトのドキュメントは次のとおりです http://msdn.microsoft.com/en-us/library/zthfhkd6%28v=VS.100%29.aspx
ご想像のとおり、_bstr_t コンストラクターの 1 つは BSTR パラメーターを取ります。LPCWSTR にキャストできるはずの const wchar_t* を返す演算子もあります。
お役に立てれば