C++ 错误:名称后跟'::'必须是类或命名空间名称。DLL 中的 WindowsForm
C++ Error: name followed by '::' must be a class or namespace name. WindowsForm in DLL
所以我在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
相关文章:
- 在命名空间中使用全局命名空间中的函数
- '使用命名空间{嵌套在另一个命名空间中的某个命名空间}"
- 使用另一个命名空间中的函数C++
- 有没有办法不使用命名空间中的项?
- 不同C++文件中未命名命名空间中的名称可以引用同一个命名事物吗?
- 在类设计中查找外部命名空间中的重载运算符
- 无法获取 wig %ignore 以忽略命名空间中的类,从而导致编译错误
- 初始化命名空间中的变量是否类似于将它们初始化为类成员?
- 匿名命名空间中的const与静态const
- 如何访问嵌套在命名命名空间中的未命名命名空间变量?
- C++使用其他命名空间中的符号,而不使它们可从外部访问
- CERN 根:为命名空间中的外部"C"结构生成流处理器
- 如何从嵌套在命名空间中的类调用成员函数?
- 命名空间中的unordered_map不会跨源文件"saving"其数据
- 访问向量字段的键 - 枚举类还是命名空间中的枚举?
- C++从 std::async 函数读取命名空间中的全局变量标志
- 使用匿名命名空间中的函数或另一个文件中的静态函数不应该出错吗?
- 库期望平面命名空间中的符号,尽管使用两级命名空间编译
- 命名空间中的'bad_cast' 'std' 未命名类型错误
- pahole 不显示命名空间中的类