I found this really nice piece of code that converts a string to System:String^, as in:
System::String^ rtn = gcnew String(move.c_str());
I pass rtn back to a C # program. In any case, inside the function where this code exists, I pass System::String^. I also found code to convert System:String^to string using the following code:
pin_ptr<const wchar_t> wch = PtrToStringChars(cmd);
size_t convertedChars = 0;
size_t sizeInBytes = ((cmd->Length + 1) * 2);
errno_t err = 0;
char *ch = (char *)malloc(sizeInBytes);
err = wcstombs_s(&convertedChars,ch, sizeInBytes,wch, sizeInBytes);
Now I can use 'ch' as a string.
This, however, seems to do a lot more work than converting another method using gcnew. So finally, my question is: is there something there that converts a string System::String^to a string using a similar method as with gcnew?
David source
share