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

问题描述 投票:1回答:1

所以我在visual studio 2012中制作了一个windows32 C ++ dll应用程序,然后我在头文件部分添加了一个窗体,并将其命名为“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) {
         }
};
}

我在错误弹出的位置添加了注释,如“错误:名称后跟'::'必须是类或命名空间名称。”有谁知道我为什么会遇到这些问题?

c++ windows forms dll visual-studio-2012
1个回答
0
投票

您需要创建一个混合模式应用程序。微软有clear instructions所需的步骤。

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

代码现在将编译。

© www.soinside.com 2019 - 2024. All rights reserved.