C ++错误:名称后跟“::”必须是类或命名空间名称。 WindowsForm在DLL(C++

2019-10-17 12:33发布

所以我做了WINDOWS32 C ++ DLL应用程序的Visual Studio 2012,然后我加入了头文件部分Windows窗体,并给它取名为“UserInterface.h”。 当我点击添加按钮,我得到一个弹出说:“您要添加CLR组件的本地项目,你的项目将被转换为具有公共语言运行库支持。你要继续吗?” 我是点击,它生成的文件“UserInterface1.cpp”和“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) {
         }
};
}

我添加了注释到错误弹出类似“错误:名称后跟‘::’必须是类或命名空间名称。” 没有人知道为什么我收到这些问题呢?

Answer 1:

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

在MS指令将解析系统和System ::集合的问题,但没有解决对系统:: ComponentModel,系统:视窗:形式,系统::数据和系统::绘图问题。

要编译,你必须为失踪的DLL到应用程序中添加引用。 您可以删除using <System.Windows.Forms>从StdAfx.h文件。 右键单击属性,选择References... ,然后选择Add New Reference ,然后检查下列DLL

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

现在,该代码可以编译。



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