Converting data from TextBox (String^) to string
-
The first line creates a String^. I believe you already have that in textBox->Text. The second line converts that to a string. The third line converts that to a wstring. What else do you not see?
«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++)I guess I need the second then. Currently I have
std::string str1 = (const char*)(Marshel::StringToHGlobalAnsi(textBox->Text)).ToPointer();
But it gives me the following errors:
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(200) : error C2653: 'Marshel' : is not a class or namespace name
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(200) : error C2228: left of '.ToPointer' must have class/struct/union
1> type is ''unknown-type''
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(200) : error C3861: 'StringToHGlobalAnsi': identifier not foundSo I tried to #include , but that didn't work either. How can I use this function? And by the way - thanks for your fast replies :)
-
I guess I need the second then. Currently I have
std::string str1 = (const char*)(Marshel::StringToHGlobalAnsi(textBox->Text)).ToPointer();
But it gives me the following errors:
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(200) : error C2653: 'Marshel' : is not a class or namespace name
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(200) : error C2228: left of '.ToPointer' must have class/struct/union
1> type is ''unknown-type''
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(200) : error C3861: 'StringToHGlobalAnsi': identifier not foundSo I tried to #include , but that didn't work either. How can I use this function? And by the way - thanks for your fast replies :)
Typo It should be
Marshal
. You got it wrong there. Look at my posting.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) -
Typo It should be
Marshal
. You got it wrong there. Look at my posting.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++)1>d:\stageappvc\terminalapp\terminalapp\Form1.h(7) : fatal error C1083: Cannot open include file: 'Marshal': No such file or directory :p Yeh - I corrected it but copied the wrong stuff I saw... But with A its still not working :( I am using Visual C++ Express Edition. Downloaded the package yesterday :p
-
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(7) : fatal error C1083: Cannot open include file: 'Marshal': No such file or directory :p Yeh - I corrected it but copied the wrong stuff I saw... But with A its still not working :( I am using Visual C++ Express Edition. Downloaded the package yesterday :p
I suspect some mix-up in your code. You do not have to include any file called
Marshal
. And you can use this class only in managed applications.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) -
I suspect some mix-up in your code. You do not have to include any file called
Marshal
. And you can use this class only in managed applications.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++)#pragma once
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
//#include <Windows.h>namespace TerminalApp {
using namespace std; using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; /// <summary> /// Summary for Form1 /// /// WARNING: If you change the name of this class, you will need to change the /// 'Resource File Name' property for the managed resource compiler tool /// associated with all .resx files this class depends on. Otherwise, /// the designers will not be able to interact properly with localized /// resources associated with this form. /// </summary> //Variabele waar alle code in komt te staan// std::vector<string> textCode; public ref class Form1 : public System::Windows::Forms::Form { public: Form1(void) { InitializeComponent(); // // } protected: /// <summary> /// Clean up any resources being used. /// </summary> ~Form1() { if (components) { delete components; } } private: System::Windows::Forms::Button^ exitButton; private: System::Windows::Forms::Button^ addText; private: System::Windows::Forms::RichTextBox^ textBox; private: System::Windows::Forms::Button^ saveButton; private: System::Windows::Forms::TextBox^ invoerVeld; private: System::Windows::Forms::Button^ voegTextButton; private: /// <summary> /// Required designer variable. /// </summary> System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->exitButton = (gcnew System::Windows::Forms::Button());
this->addText = (gcnew System::Windows::Forms::Button());
this->textBox = (gcnew System::Windows::Forms::RichTextBox());
this->saveButton = (gcnew System::Windows::Forms::Button());
this->invoerVeld = (gcnew System::Windows::Forms::TextBox());
this->voegTextButton = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// exitButton
//
this->exitButton->Location = System -
#pragma once
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
//#include <Windows.h>namespace TerminalApp {
using namespace std; using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; /// <summary> /// Summary for Form1 /// /// WARNING: If you change the name of this class, you will need to change the /// 'Resource File Name' property for the managed resource compiler tool /// associated with all .resx files this class depends on. Otherwise, /// the designers will not be able to interact properly with localized /// resources associated with this form. /// </summary> //Variabele waar alle code in komt te staan// std::vector<string> textCode; public ref class Form1 : public System::Windows::Forms::Form { public: Form1(void) { InitializeComponent(); // // } protected: /// <summary> /// Clean up any resources being used. /// </summary> ~Form1() { if (components) { delete components; } } private: System::Windows::Forms::Button^ exitButton; private: System::Windows::Forms::Button^ addText; private: System::Windows::Forms::RichTextBox^ textBox; private: System::Windows::Forms::Button^ saveButton; private: System::Windows::Forms::TextBox^ invoerVeld; private: System::Windows::Forms::Button^ voegTextButton; private: /// <summary> /// Required designer variable. /// </summary> System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->exitButton = (gcnew System::Windows::Forms::Button());
this->addText = (gcnew System::Windows::Forms::Button());
this->textBox = (gcnew System::Windows::Forms::RichTextBox());
this->saveButton = (gcnew System::Windows::Forms::Button());
this->invoerVeld = (gcnew System::Windows::Forms::TextBox());
this->voegTextButton = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// exitButton
//
this->exitButton->Location = SystemTry adding this line -
using namespace System::Runtime::InteropServices;
«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) -
Try adding this line -
using namespace System::Runtime::InteropServices;
«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++)1>d:\stageappvc\terminalapp\terminalapp\Form1.h(200) : error C2653: 'Marshel' : is not a class or namespace name
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(200) : error C2228: left of '.ToPointer' must have class/struct/union
1> type is ''unknown-type''
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(200) : error C3861: 'StringToHGlobalAnsi': identifier not foundIs there any other known way to get text out such TextBox into a string? One made by Microsoft themselves? :p
-
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(200) : error C2653: 'Marshel' : is not a class or namespace name
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(200) : error C2228: left of '.ToPointer' must have class/struct/union
1> type is ''unknown-type''
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(200) : error C3861: 'StringToHGlobalAnsi': identifier not foundIs there any other known way to get text out such TextBox into a string? One made by Microsoft themselves? :p
You have typed in
Marsh**e**l
. The correct spelling isMarsh**a**l
. Do you see the difference?«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) -
You have typed in
Marsh**e**l
. The correct spelling isMarsh**a**l
. Do you see the difference?«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) -
How strange - because I copied it directly from your post - since first of all I hate typing and secondly its always better to copy paste :p But it is working now - let me test the output etc. Thanks in advance <3
:thumbsup: But I really think you should not be driving now. :)
«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) -
:thumbsup: But I really think you should not be driving now. :)
«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++)No Im not driving lol. It works! *cheering the hell outta it* Adding text to the TextBox and with a button its sending the data to my vector string which can be read and send to the output :-\ Thank you very very much! I really needed this line! <33 :rose: