2

Possible Duplicate:
C++/CLI Converting from System::String^ to std::string

I am using a C# DLL in my C++ code (Visual Studio 2010). How do I convert a System::String^ to a C++ std::string?

Community
  • 1
  • 1
Rajat
  • 1,766
  • 2
  • 21
  • 42

1 Answers1

0

System.Runtime.InteropServices.Marshal has several methods that convert a string to an array of characters, which you could then use any manner of methods to get a std::string.

I believe the recommendation is to use StringToBSTR eventually calling FreeBSTR once you have copied the data to a different object.

The question I linked to as a comment recommends StringToCoTaskMemUni.

Guvante
  • 18,775
  • 1
  • 33
  • 64