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 是本机类型) 有关更多信息)

请参见

参考

编译器COM全局函数