c++ - Visual Studio 2015 C++ 中的 CLR 应用程序(无法识别的代码?)

标签 c++ visual-studio clr windows-forms-designer

那么,让我们开始吧。过去,我已经使用相同的 IDE 使用 C++ 创建了多个程序; Visual Studio,我似乎遇到了一个问题,当我试图调用 Application 命名空间时,它只是无法识别它。也许我在做一些愚蠢的事情,比如忘记导入或包含 namespace ,但我很确定这是正确的。我已经尽可能地查看了主要网站,但我还没有真正找到我要找的东西,所以我决定它会帮助很多像我这样的 C++ 新用户,但对 Visual Studio 没有帮助。

我已经知道如何在 C++ 中设置链接器,所以如果这与它有任何关系,则不会。

如果您想查看我的 LibraryWindow.cpp 文件:

#include "LibraryWindow.h"
#include <string.h>

using namespace System;
using namespace std;

[STAThread]
int Main(array<System::String^>^ args) {

    Application::SetCompatibleTextRenderingDefault(true);
    Application::EnableVisualStyles();

    LibraryWindow libraryWindow = new LibraryWindow();
    Application::Run(%libraryWindow);

}

主要是上面的代码是凭内存写的。

但是,如果您仍然不确定我的意思,命名空间“Application”会给出一个红色错误标志,显然它会编译错误。

我也觉得我在处理代码时做了一些愚蠢的事情,所以我希望最终能解决所有问题。

最佳答案

首先,Application 不是命名空间。它是命名空间 System::Windows::Forms ( Source ) 中的一个类。

所以,你需要添加

using namespace System::Windows::Forms;

在您的主要或命名空间之前,对 Application 的每次使用进行限定。

除此之外,您还需要添加对 System.Windows.Forms 的引用。可以通过以下方式添加:

项目属性 -> 通用属性 -> 引用 -> 添加新引用。

关于c++ - Visual Studio 2015 C++ 中的 CLR 应用程序(无法识别的代码?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35369760/

相关文章:

c++ - 使用 C++ 或任何 Windows 脚本语言格式化文本数据

c++ - Float 和 unsigned char 数组之间的 union ?

android - Visual Studio 2015 中的 "No devices available"

c# - ASP.NET - 复合控件 - 在 CreateChildControls 抑制 Button Click 事件后添加动态控件

c++ - 正确测量像素中的字符

c# - 不再需要 stringbuilder 了吗?

.net - 为什么有针对 .Net 的调试和发布版本,但没有针对 Java 的版本?

c++ - 有没有一种简单的方法可以在 OpenGL 中获得阴影?

c++ - 使用 Eclipse 链接 C++ 项目时出现 undefined symbol 错误

c# - 支持两个主窗口的通用 Windows 平台 (UWP) 应用程序