.NET Questions (CLOSED)Questions and Answers on any aspect of .NET. Now closed. |
||
|
This discussion group is now closed.
Have a question about .NET development? Try stackoverflow.com, a worldwide community of great developers asking and answering questions 24 hours a day. The archives of .NET Questions contain years of Q&A. Even older .NET Questions are still online, too. |
Hi,
Does anybody know of a way to convert a C++ std:string to a .NET System::String^ , obviously in C++/CLI . I've tried std::string ns("Hello"); String^ ms(ns.c_str()); and std::wstring ns("Hello"); String^ ms(ns.c_str()); just in case it's a unicode issue. But to no avail. There's loads of examples on how to go the other way managed->native but I can't see anything for native->managed. I'd really appreciate it if anybody has the answer!! Cheers Thursday, August 16, 2007
Yeah I had to research that for a project I just did.
std::string ns("Hello"); String^ ms(ns.c_str()); ms = Marshal::PtrToStringAnsi(static_cast<IntPtr>(const_cast<char *>(ns.c_str())))
nullptr Thursday, August 16, 2007
This works for me, and sees regular use in production code :
System::String^ NativeToDotNet( const std::string& input ) { return System::Runtime::InteropServices::Marshal::PtrToStringAnsi( static_cast<LPVOID>( input.c_str() ) ); } Should be the same as nullptr's example, really. |
|
Powered by FogBugz


