ConvertBSTRToString
Microsoft 特定的
將 BSTR 值轉換為 char *。
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。
**Lib:**comsuppw.lib 或 comsuppwd.lib (如需詳細資訊,請參閱 /Zc:wchar_t (wchar_t 是原生類型))