在 Windows 窗体中,我使用 2 个文本框。来自 textBox1 的信息必须成为函数 encrypte() 的参数之一,它接受两个
string
参数并返回 string 值。
std::string encrypte(std::string text, std::string key);
将字符串转换为字符串^ 我使用 marshal_as,但 marshal_as 指的是旧函数模板。我看到我的程序的旧版本。如果我不使用 marshal_as 就没有那个错误。
Earliel 我有“label2->Text =“fjff””而不是“label2->Text = ENC”。第一个作品(“fjff”),我什至删除了它。
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
System::String^ text;
System::String^ key;
if (checkBox1->Checked) {
text = System::Convert::ToString(textBox1->Text);
key = System::Convert::ToString(textBox3->Text);
msclr::interop::marshal_context context;
string key2 = context.marshal_as<std::string>(key);
string text2 = context.marshal_as<std::string>(text);
string enc = encrypte(text2, key2);
String^ ENC = context.marshal_as<System::String^>(enc);
label2->Text = ENC;
}
}
我该如何解决?
我重建了我的项目,它解决了问题。