Currently I'm busy to get some text from the textbox and then convert in into a const char*. I have the following code:
System::String^ host = textBoxHostadres->Text;
const char* host2 = (const char*)(void*)Marshal::StringToHGlobalAnsi(host);
//system(host2); //What to do with this?
Marshal::FreeHGlobal(host2);
It gives a redline (Visual Studio 2012) under Marshal::FreeHGlobal
. Can somebody give me a right direction to get the text from the textbox
and get it to a const char*
? The first line works well and through debugging I see the text get captured.
Update:
System::String^ host = textBoxHostadres->Text;
pin_ptr<const wchar_t> wch = PtrToStringChars(host);
// Convert to a char*
size_t origsize = wcslen(wch) + 1;
const size_t newsize = 100;
size_t convertedChars = 0;
char nstring[newsize];
wcstombs_s(&convertedChars, nstring, origsize, wch, _TRUNCATE);
strcat_s(nstring, " (char *)");
const char* host2 = (const char*)(void*)Marshal::StringToHGlobalAnsi(host);
system(host2);
traceroute hostAddress(host2);