使用_bstr_t需要包含的头文件:

#include <comutil.h>
#include <comdef.h>

// test.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <comutil.h>
#include <comdef.h>
#include <string>
using namespace std;

string ws2ms(const wstring& ws)
{
    _bstr_t t = ws.c_str();
    char* pchar = (char*)t;
    return pchar;
}

wstring ms2ws(const string& s)
{
    _bstr_t t = s.c_str();
    wchar_t* pwchar = (wchar_t*)t;
    return pwchar;
}

int _tmain(int argc, _TCHAR* argv[])
{
    string s = "123";
    wstring ws = L"456";

    ::MessageBoxA(0, s.c_str(), (char *)ws2ms(ws).c_str(), 0);
    ::MessageBoxW(0, ms2ws(s).c_str(), ws.c_str(), 0);

    return 0;
}

 

 

 

 

相关文章:

  • 2022-02-24
  • 2022-12-23
  • 2021-07-01
  • 2021-11-08
  • 2022-12-23
  • 2021-07-19
  • 2022-02-02
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案