Convert System::String to char*
char* ConvertStringToChar( String^ str)
{
using namespace Runtime::InteropServices;
IntPtr p = Marshal::StringToHGlobalAnsi(str);
return static_cast<char*>(p.ToPointer());
}
Convert char* to System::String
String^ ConvertCharToString(char* strChar, int length)
{
String^ msg = gcnew String((char*)strChar);
if (msg->Length > length)
msg = msg->Substring(0, length);
return msg;
}
Leave a Reply