gpt4 book ai didi

DLL 中的 C++ 错误 : name followed by '::' must be a class or namespace name. WindowsForm

转载 作者:太空宇宙 更新时间:2023-11-04 14:11:22 24 4
gpt4 key购买 nike

所以我在 visual studio 2012 中制作了一个 windows32 C++ dll 应用程序,然后我在头文件部分添加了一个 Windows 窗体,并将其命名为“UserInterface.h”。当我单击“添加”按钮时,我收到一个弹出窗口,提示“您正在向 native 项目添加 CLR 组件。您的项目将被转换为具有公共(public)语言运行时支持。您希望继续吗?”然后我单击是,它生成了文件“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) {
}
};
}

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

最佳答案

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

MS 说明将解决 System 和 System::Collections 的问题,但不会解决 System::ComponentModel、System::Windows::Forms、System::Data 和 System::Drawing 的问题。

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

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

代码现在可以编译了。

关于DLL 中的 C++ 错误 : name followed by '::' must be a class or namespace name. WindowsForm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14025655/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com