天下

记录修行的印记

char*和wchar_t* 转String^

#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 

posted on 2015-12-21 19:07 天下 阅读(755) 评论(0)  编辑 收藏 引用 所属分类: C/C++C#

<2011年11月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

导航

统计

常用链接

留言簿(4)

随笔分类(378)

随笔档案(329)

链接

最新随笔

搜索

最新评论