| title |
ConvertStringToBSTR | 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 |
ConvertStringToBSTR function |
|
| ms.assetid |
071f9b3b-9643-4e06-a1e5-de96ed15bab2 |
| caps.latest.revision |
11 |
| author |
mikeblome |
| ms.author |
mblome |
| manager |
ghogen |
| translation.priority.ht |
cs-cz |
de-de |
es-es |
fr-fr |
it-it |
ja-jp |
ko-kr |
pl-pl |
pt-br |
ru-ru |
tr-tr |
zh-cn |
zh-tw |
|
Microsoft Specific
Converts a char * value to a BSTR.
BSTR __stdcall ConvertStringToBSTR(
const char* pSrc
)
pSrc
A char * variable.
// ConvertStringToBSTR.cpp
#include <comutil.h>
#include <stdio.h>
#pragma comment(lib, "comsuppw.lib")
#pragma comment(lib, "kernel32.lib")
int main() {
char* lpszText = "Test";
printf_s("char * text: %s\n", lpszText);
BSTR bstrText = _com_util::ConvertStringToBSTR(lpszText);
wprintf_s(L"BSTR text: %s\n", bstrText);
SysFreeString(bstrText);
}
char * text: Test
BSTR text: Test
Header: comutil.h
Lib: comsuppw.lib or comsuppwd.lib (see /Zc:wchar_t (wchar_t Is Native Type) for more information)
Compiler COM Global Functions