C++/CLI 本地字符串和託管字符串之間的轉換

參考: https://docs.microsoft.com/zh-cn/cpp/dotnet/overview-of-marshaling-in-cppwindows

 

#include "msclr/marshal.h"
#include "msclr/marshal_windows.h"
#include "msclr/marshal_cppstd.h"
#include "msclr/marshal_atl.h"cli

 

int main(cli::array<System::String ^> ^args)
{gc

    marshal_context^ context = gcnew marshal_context();view

    DWFString s(context->marshal_as<const wchar_t *>(args[0]));vi

 

    System::String ^s2 = marshal_as<System::String^>((const wchar_t *)s);co

}new

相關文章
相關標籤/搜索