/ Published in: C#
Specifically, this code enables you to pass a string from C# into C++ managed code and then get a C++ pointer to the string's chars.
Marshal.StringToHGlobalAnsi Method from MSDN.
Good information about native vs. managed types.
Related forum post.
Expand |
Embed | Plain Text
C# void cSharpMethod() { String myString = "ASCII/ANSI String in C#"; cPlusPlusClass.cPlusPlusMethod(myString); } C++ int cPlusPlusMethod(System::String^ aString) { char* charPtr = (char*)Marshal::StringToHGlobalAnsi(aString).ToPointer(); // Use it... Marshal::FreeHGlobal(IntPtr(charPtr)); // Free memory }
Comments
Subscribe to comments
You need to login to post a comment.

gud