天下

记录修行的印记

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 天下 阅读(704) 评论(0)  编辑 收藏 引用 所属分类: C/C++C#


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2013年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

导航

统计

常用链接

留言簿(4)

随笔分类(378)

随笔档案(329)

链接

最新随笔

搜索

最新评论