如何解决非静态成员引用必须相对于特定对象
我正在尝试将文本框 tb_key
中的文本写入我的 std::string Key
变量 这样做:
std::string Key = TRIPRECOILWARE::LoginForm::tb_key->Text;
我收到一条错误消息:
非静态成员引用必须相对于特定的 对象
我尝试搜索,但找不到任何真正适合我的东西。
最小可重复示例:
LoginForm.h
namespace TRIPRECOILWARE {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
private: System::Void tb_key_TextChanged(System::Object^ sender,System::EventArgs^ e)
{
}
}
LoginForm.cpp
std::string Key = TRIPRECOILWARE::LoginForm::tb_key->Text;
我正在尝试在 LoginForm.h
中使用它private: System::Void button1_Click(System::Object^ sender,System::EventArgs^ e) {
if (Authenticate(Stringtochar(Key),(Stringtochar(hwid)))) // Authenticates key & hwid
{
this->Hide();
Software^ soft = gcnew Software();
soft->Show();
}
基本上,我想从名为 tb_key
的 TextBox 中获取 Key 并写入
它到我上面定义的 Key
变量。然后使用该键
验证并执行 code
解决方法
你真正的问题是How to turn System::String^ into std::string?
的重复更正的代码:
#include <msclr\marshal.h>
#include <msclr\marshal_cppstd.h>
using namespace System;
using namespace msclr::interop;
void button1_Click(System::Object^ sender,System::EventArgs^ e)
{
std::string Key = marshal_as<std::string>(tb_key->Text);
if (Authenticate(Key.c_str(),hwid.c_str())) // Authenticates key & hwid
{
Hide();
Software^ soft = gcnew Software();
soft->Show();
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。