Udostępnij za pośrednictwem


ConvertBSTRToString

Microsoft Specific

Converts a BSTR value to a char *.

char* __stdcall ConvertBSTRToString( 
   BSTR pSrc 
);

Parameters

  • pSrc
    A BSTR variable.

Remarks

ConvertBSTRToString allocates a string you must delete.

Example

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

Requirements

Header: comutil.h.

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

See Also

Reference

Compiler COM Global Functions