| title | ConvertBSTRToString | Microsoft Docs | |
|---|---|---|
| ms.custom | ||
| ms.date | 11/04/2016 | |
| ms.reviewer | ||
| ms.suite | ||
| ms.technology |
|
|
| ms.tgt_pltfrm | ||
| ms.topic | language-reference | |
| f1_keywords |
|
|
| dev_langs |
|
|
| helpviewer_keywords |
|
|
| ms.assetid | ab6ce555-3d75-4e9c-9cb8-ada6d8ce43b1 | |
| caps.latest.revision | 11 | |
| author | mikeblome | |
| ms.author | mblome | |
| manager | ghogen |
Microsoft Specific
Converts a BSTR value to a char *.
char* __stdcall ConvertBSTRToString(
BSTR pSrc
);
pSrc
A BSTR variable.
ConvertBSTRToString allocates a string you must delete.
// 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;
}
BSTR text: Test
char * text: Test
END Microsoft Specific
Header: comutil.h.
Lib: comsuppw.lib or comsuppwd.lib (see /Zc:wchar_t (wchar_t Is Native Type) for more information)