Search code examples
user-interfacec++-cliunmanagedmanaged

Conversion between managed and unmanaged types in C++?


When I use a GUI in C++ the text fields are stored as managed strings, i think. I need a way to convert them to standard ints, floats and strings. Any help?


Solution

  • You can convert a System.String into an unmanaged char * using Marshal.StringToHGlobalAnsi. Make sure you free it when you're done by calling Marshal.FreeHGlobal. To convert the strings to numeric values, you can use the regular .NET parsing functions such as Int32.Parse.