C++ 错误:名称后跟'::'必须是类或命名空间名称。DLL 中的 WindowsForm

C++ Error: name followed by '::' must be a class or namespace name. WindowsForm in DLL

本文关键字:命名空间 中的 WindowsForm DLL 错误 C++      更新时间:2023-10-16

所以我在visual studio 2012中制作了一个windows32c++ dll应用程序,然后在头文件部分添加了一个windows窗体,并将其命名为"UserInterface.h"。当我点击添加按钮时,我看到一个弹出框说"你正在向本地项目添加CLR组件。"您的项目将被转换为具有公共语言运行时支持。你想继续吗?",我点击是,它使文件"UserInterface1.cpp"answers"UserInterface1.h"。

但是在"UserInterface1.h"里面到处都是错误。以下是它的内容:

#pragma once
namespace AssultCubeDLL {

    //ERRORS HERE: ******************************************************
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 UserInterface
/// </summary>
    // ERROS HERE: *********************************************************
public ref class UserInterface : public System::Windows::Forms::Form
{
public:
    UserInterface(void)
    {
        InitializeComponent();
        //
        //TODO: Add the constructor code here
        //
    }
protected:
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    ~UserInterface()
    {
        if (components)
        {
            delete components;
        }
    }
private:
    /// <summary>
    /// Required designer variable.
    /// </summary>
           // ERRORS HERE: ************************************************
    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->SuspendLayout();
        // 
        // UserInterface
        // ERRORS HERE: *******************************************************
        this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
        this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
        this->ClientSize = System::Drawing::Size(284, 262);
        this->Name = L"UserInterface";
        this->Text = L"UserInterface";
        this->Load += gcnew System::EventHandler(this, &UserInterface::UserInterface_Load);
        this->ResumeLayout(false);
    }
    #pragma endregion
private: System::Void UserInterface_Load(System::Object^  sender, System::EventArgs^  e) {
         }
};
}

我在错误弹出的地方添加了注释,如"错误:名称后面跟着'::'必须是一个类或命名空间名称。"有人知道为什么我得到这些问题吗?

您将需要创建一个混合模式应用程序。微软对所需步骤有明确的说明。

MS指令将解决System和System::Collections的问题,但不能解决System::ComponentModel、System::Windows::Forms、System::Data和System::Drawing的问题。

要编译,必须向应用程序添加对缺失dll的引用。您可以从stdafx.h文件中删除using <System.Windows.Forms>。右键单击属性并选择References...,然后选择Add New Reference,然后检查以下dll

System
System.Data
System.Drawing
System.Windows.Forms