Skip to content

Instantly share code, notes, and snippets.

@DamianSuess
Created June 13, 2017 21:47
Show Gist options
  • Save DamianSuess/ac4baa57bc7b8c97bed91282eab45e87 to your computer and use it in GitHub Desktop.
Save DamianSuess/ac4baa57bc7b8c97bed91282eab45e87 to your computer and use it in GitHub Desktop.
Managed C++, convert String^ to std::string
/// ----------------------------------------------------------------------------
/// <summary>Convert from String^ to std::string</summary>
System::Void TestClass::MarshalString(String ^ strIn, string& strOut)
{
using namespace Runtime::InteropServices;
const char* chars = (const char*)(Marshal::StringToHGlobalAnsi(strIn)).ToPointer();
strOut = chars;
Marshal::FreeHGlobal(IntPtr((void*)chars));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment