Greetings

Can you please tell me how to convert an incomprehensible Text format from textbox to MSVS2010 into a standard array of chars. C ++ language Windows Forms project

Thank!

  • Swears at Marshal. Need to connect something? And, let's say, if I decided to follow your advice about using String ^, then how can I convey a trite value from textBox to fopen ()? - eckler

1 answer 1

(I’ll try to get my finger into the sky, because, apparently, you are developing with C++/CLI , but I could be wrong)

  • TextBox has property Text :

     virtual property String^ Text { String^ get () override; void set (String^ value) override; } 
  • That is, turning to textBox->Text , you get a variable of type String^ .

  • The correct conversion from String^ to the char array is not the most trivial operation, since String^ is an abstraction much wider than char[] . Correctly this conversion operation is performed like this:

     IntPtr initialStringPtr = Marshal::StringToHGlobalAnsi(initialString); char* converted = static_cast<char*>(initialStringPtr.ToPointer()); // Работаете с 'converted'. Marshal::FreeHGlobal(initialStringPtr); // После этой строчки указатель 'converted' указывает на освобожденный участок памяти! 
  • I recommend to think 300 times (and then think 300 more times) before moving from a convenient unicode string implementation to char* .

  • one
    Join now. "I recommend to think 300 times (and then think 300 more times) before moving from a convenient unicode implementation of the string to char *." - AseN