【问题标题】:a handle to a non-managed class is not allowed不允许使用非托管类的句柄
【发布时间】:2018-08-19 07:53:37
【问题描述】:

我正在尝试在 c++ windows 窗体和 mysql 数据库之间建立连接, 但它向我显示了这个错误。

不允许使用非托管类的句柄

        #pragma endregion
        private: System::Void MyForm_Load(System::Object^  sender, System::EventArgs^  e) {
            std::string^ constring =L "datasource=localhost;port=**;username=root;password=**";
            MySqlConnection^ conDataBase=gcnew MySqlConnection(constring);
            MySqlCommand^ cmdDataBase=gcnew MySqlCommand("",conDataBase);
        }
    };
}

【问题讨论】:

    标签: c++ mysql winforms user-interface clr


    【解决方案1】:

    std::string 是 C++ 标准库中的字符串类。您不能将其与 ^ 一起使用(即,作为托管类)。

    改为使用 .NET String 类:

    System::String^ constring = L"datasource=localhost;port=**;username=root;password=**";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-08
      • 1970-01-01
      • 2012-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多