我创建了一个 C++ windows 窗体应用程序,我想将它绑定到数据库。但是,它一直给我一个我无法解决的错误。它突出显示了我conn
的类型变量,MYSQL*
只是给了我这个错误:this declaration has no storage class or type specifier
. 我已链接并包含所有库,因此我不知道有什么问题。
代码:
#pragma once
#include <iostream>
#include <mysql.h>
MYSQL* conn;
MYSQL_ROW row;
MYSQL_RES* res;
conn = mysql_init(0);
conn = mysql_real_connect(conn, my host here, my username, my password, my db name, port, NULL, 0);
namespace MSSLogin {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public ref class Login_Panel : public System::Windows::Forms::Form
{
public:
Login_Panel(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
~Login_Panel()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Label^ label1;
protected:
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::TextBox^ textBox2;
private: System::Windows::Forms::PictureBox^ pictureBox1;
private: System::Windows::Forms::Label^ label3;
protected:
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)
{
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Login_Panel::typeid));
this->label1 = (gcnew System::Windows::Forms::Label());
this->label2 = (gcnew System::Windows::Forms::Label());
this->button1 = (gcnew System::Windows::Forms::Button());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
this->label3 = (gcnew System::Windows::Forms::Label());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->BeginInit();
this->SuspendLayout();
//
// label1
//
this->label1->AutoSize = true;
this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 11.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label1->Location = System::Drawing::Point(71, 25);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(90, 18);
this->label1->TabIndex = 0;
this->label1->Text = L"Username:";
this->label1->Click += gcnew System::EventHandler(this, &Login_Panel::label1_Click);
//
// label2
//
this->label2->AutoSize = true;
this->label2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 11.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label2->Location = System::Drawing::Point(71, 56);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(88, 18);
this->label2->TabIndex = 1;
this->label2->Text = L"Password:";
this->label2->Click += gcnew System::EventHandler(this, &Login_Panel::label2_Click);
//
// button1
//
this->button1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 11.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->button1->Location = System::Drawing::Point(118, 95);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(196, 32);
this->button1->TabIndex = 2;
this->button1->Text = L"Login";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Login_Panel::button1_Click);
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(167, 23);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(192, 20);
this->textBox1->TabIndex = 3;
this->textBox1->TextChanged += gcnew System::EventHandler(this, &Login_Panel::textBox1_TextChanged);
//
// textBox2
//
this->textBox2->Location = System::Drawing::Point(167, 56);
this->textBox2->Name = L"textBox2";
this->textBox2->Size = System::Drawing::Size(192, 20);
this->textBox2->TabIndex = 4;
this->textBox2->TextChanged += gcnew System::EventHandler(this, &Login_Panel::textBox2_TextChanged);
//
// pictureBox1
//
this->pictureBox1->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"pictureBox1.Image")));
this->pictureBox1->Location = System::Drawing::Point(364, 146);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size = System::Drawing::Size(60, 55);
this->pictureBox1->SizeMode = System::Windows::Forms::PictureBoxSizeMode::Zoom;
this->pictureBox1->TabIndex = 5;
this->pictureBox1->TabStop = false;
this->pictureBox1->Click += gcnew System::EventHandler(this, &Login_Panel::pictureBox1_Click);
//
// label3
//
this->label3->AutoSize = true;
this->label3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 11.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label3->Location = System::Drawing::Point(12, 183);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(185, 18);
this->label3->TabIndex = 6;
this->label3->Text = L"@misrsoftwaresystems";
this->label3->Click += gcnew System::EventHandler(this, &Login_Panel::label3_Click);
//
// Login_Panel
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(436, 213);
this->Controls->Add(this->label3);
this->Controls->Add(this->button1);
this->Controls->Add(this->pictureBox1);
this->Controls->Add(this->textBox2);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->label1);
this->Controls->Add(this->label2);
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
this->HelpButton = true;
this->Icon = (cli::safe_cast<System::Drawing::Icon^>(resources->GetObject(L"$this.Icon")));
this->MaximizeBox = false;
this->MinimizeBox = false;
this->Name = L"Login_Panel";
this->Text = L"Login";
this->Load += gcnew System::EventHandler(this, &Login_Panel::Login_Panel_Load);
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->EndInit();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void groupBox1_Enter(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void pictureBox1_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void textBox2_TextChanged(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void label1_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void label2_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void label3_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void Login_Panel_Load(System::Object^ sender, System::EventArgs^ e) {
}
};
}
我已经尝试将那段代码不断地移入和移出命名空间和类,希望它会产生影响,但显然不会。
错误日志:
Warning C4829 Possibly incorrect parameters to function main. Consider 'int main(Platform::Array<Platform::String^>^ argv)' MSS_Login D:\MSS\MSS_System\MSS_Login\Login_Panel.cpp 7
Error C2664 'MYSQL *mysql_real_connect(MYSQL *,const char *,const char *,const char *,const char *,unsigned int,const char *,unsigned long)': cannot convert argument 1 from 'int' to 'MYSQL *' MSS_Login D:\MSS\MSS_System\MSS_Login\Login_Panel.h 10
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int MSS_Login D:\MSS\MSS_System\MSS_Login\Login_Panel.h 10
Error C2374 'conn': redefinition; multiple initialization MSS_Login D:\MSS\MSS_System\MSS_Login\Login_Panel.h 10
Error C2440 'initializing': cannot convert from 'MYSQL *' to 'int' MSS_Login D:\MSS\MSS_System\MSS_Login\Login_Panel.h 8
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int MSS_Login D:\MSS\MSS_System\MSS_Login\Login_Panel.h 8
Error (active) E0077 this declaration has no storage class or type specifier MSS_Login D:\MSS\MSS_System\MSS_Login\Login_Panel.h 10
Error (active) E0077 this declaration has no storage class or type specifier MSS_Login D:\MSS\MSS_System\MSS_Login\Login_Panel.h 8
libs
我的链接和截图includes
:
C/C++ > General > Additional Include Directories
包含目录的第一张图片
Linker > General > Additional Library Directories
图书馆目录的第二张图片
Linker > Input > Additional Dependencies
附加依赖项的第三个图像