System::String _gc* to char *
-
:eek::eek::eek::eek::eek:I can't achieve this process in .Net Visual C++. I use below code and the interpreter doesn't give any error at compile time but an error is occours at run time ("object referance not set to an object instance") char *dosya; String *dizi; dizi=textBox1->Text; dosya=new char(512); dosya=reinterpret_cast(dizi->ToCharArray()); also I used below code and the compiler gave an error at run time ("index was outside of range" like this I can't remember completly) dosya=reinterpret_cast(dizi->get_Chars(dizi->get_Lenght())); for summary I can't get the characters from a System::String class to a char pointer. (instead of char to use wchar_t variable didn't solve the problem
-
:eek::eek::eek::eek::eek:I can't achieve this process in .Net Visual C++. I use below code and the interpreter doesn't give any error at compile time but an error is occours at run time ("object referance not set to an object instance") char *dosya; String *dizi; dizi=textBox1->Text; dosya=new char(512); dosya=reinterpret_cast(dizi->ToCharArray()); also I used below code and the compiler gave an error at run time ("index was outside of range" like this I can't remember completly) dosya=reinterpret_cast(dizi->get_Chars(dizi->get_Lenght())); for summary I can't get the characters from a System::String class to a char pointer. (instead of char to use wchar_t variable didn't solve the problem
a look at msdn brings the following solution: using namespace System::Runtime::InteropServices;
const char* str = (const char*) (Marshal::StringToHGlobalAnsi(managedString)).ToPointer(); // use str as you wish or copy it elsewhere // free string Marshal::FreeHGlobal(IntPtr((void*)str));
We are men. We are different. We have only one word for soap. We do not own candles. We have never seen anything of any value in a craft shop. We do not own magazines full of photographs of celebrities with their clothes on. - Steve