1

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

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

4

1 回答 1

0

您将需要创建一个混合模式应用程序。Microsoft对所需步骤有明确的说明。

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

代码现在将编译。

于 2015-11-11T17:15:20.003 回答