C ++错误:名称后跟'::'必须是类或命名空间名称。 WindowsForm中的DLL [英] C++ Error: name followed by '::' must be a class or namespace name. WindowsForm in DLL
问题描述
所以我在Visual studio 2012中创建了一个windows32 C ++ dll应用程序,然后我在头文件部分添加了一个窗体,并给它名为UserInterface.h。当我单击添加按钮,我得到一个弹出窗口说:您正在添加一个CLR组件到一个本地项目。您的项目将被转换为具有Common Language Runtime支持,你要继续吗?我点击是,它做了文件UserInterface1.cpp和UserInterface1.h。
So i made a windows32 C++ dll application in visual studio 2012 and then i added a windows form in the header files section and gave it the name "UserInterface.h". When i clicked the Add button i got a popup saying "You are adding a CLR component to a native project. Your project will be converted to have Common Language Runtime support. Do you wish to continue?" and i clicked yes and it made the files "UserInterface1.cpp" and "UserInterface1.h".
但在UserInterface1.h中有错误。这里是它的内容:
but in the "UserInterface1.h" there are errors all over. here are its contents:
#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) {
}
};
}
我添加了注释到错误弹出的地方, '::'必须是类或命名空间名称。有人知道我为什么会遇到这些问题?
I added comments to where the errors pop up like "Error: name followed by '::' must be a class or namespace name." does anyone know why i am getting these problems?
推荐答案
您需要创建一个混合模式应用程序。 Microsoft已针对所需步骤清除说明。
You will need to create a mixed mode application. Microsoft has clear instructions for the required steps.
MS指令将解决System和System :: Collections的问题,但不能解决System :: ComponentModel,System :: Windows :: Forms,System :: Data的问题, System :: Drawing。
The MS instructions will resolve the problem for System and System::Collections, but does not resolve the issues for System::ComponentModel, System::Windows::Forms, System::Data, and System::Drawing.
要编译,必须向应用程序添加缺少的DLL的引用。您可以从stdafx.h文件中使用< System.Windows.Forms> 删除 To compile, you must add references for the missing DLLs to the application. You can remove the 代码现在将编译。 这篇关于C ++错误:名称后跟'::'必须是类或命名空间名称。 WindowsForm中的DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!。右键单击属性并选择
引用...
,然后选择添加新引用
,然后检查以下DLL
using <System.Windows.Forms>
from the stdafx.h file. Right-click properties and select References...
, then select Add New Reference
, then check the following DLLsSystem
System.Data
System.Drawing
System.Windows.Forms