Freigeben über


ConvertStringToBSTR

Microsoft Specific

Converts a char * value to a BSTR.

BSTR __stdcall ConvertStringToBSTR(
   const char* pSrc
)

Parameters

  • pSrc
    A char * variable.

Example

// 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

Requirements

Header: comutil.h

Lib: comsuppw.lib or comsuppwd.lib (see /Zc:wchar_t (wchar_t Is Native Type) for more information)

See Also

Concepts

Compiler COM Global Functions