Created
June 13, 2017 21:47
-
-
Save DamianSuess/ac4baa57bc7b8c97bed91282eab45e87 to your computer and use it in GitHub Desktop.
Managed C++, convert String^ to std::string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// ---------------------------------------------------------------------------- | |
/// <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