Microsoft 固有の仕様 →
char * に BSTR の値を変換します。
char* __stdcall ConvertBSTRToString(
BSTR pSrc
);
パラメーター
- pSrc
BSTR の変数。
解説
ConvertBSTRToString は削除する文字列を割り当てます。
使用例
// ConvertBSTRToString.cpp
#include <comutil.h>
#include <stdio.h>
#pragma comment(lib, "comsuppw.lib")
int main() {
BSTR bstrText = ::SysAllocString(L"Test");
wprintf_s(L"BSTR text: %s\n", bstrText);
char* lpszText2 = _com_util::ConvertBSTRToString(bstrText);
printf_s("char * text: %s\n", lpszText2);
SysFreeString(bstrText);
delete[] lpszText2;
}
必要条件
ヘッダー : comutil.h。
ライブラリ : comsuppw.lib または comsuppwd.lib (詳細については /Zc:wchar_t (wchar_t をネイティブ型として認識) を参照してください)