IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    char*和wchar_t* 转String^

    天下发表于 2015-12-21 11:07:00
    love 0
    #include "stdafx.h"
    #include <msclr/marshal.h>
    #using <mscorlib.dll>
    using namespace System;
    using namespace System::Text;
    using namespace System::Runtime::InteropServices;

    #ifdef _MANAGED
    #endif

    void abc123()
    {
        using namespace msclr::interop;
        const char* msg1 = "Test String to Marshal";
        const wchar_t* msg2= L"Good Luck Aaron";
        String^ aMsg = marshal_as<String^>(msg1);
        String^ uMsg = marshal_as<String^>(msg2);
        Console::WriteLine(aMsg);
        Console::WriteLine(uMsg);
    }
    #pragma unmanaged
    int _tmain(int argc, _TCHAR* argv[])
    {
        abc123();
        system("pause");
        return 0;
    }
    #pragma managed 


    天下 2015-12-21 19:07 发表评论


沪ICP备19023445号-2号
友情链接