如何在 VS2012 中创建 C++/CLI Winforms 应用程序? [英] How do I create a C++/CLI Winforms app in VS2012?

查看:28
本文介绍了如何在 VS2012 中创建 C++/CLI Winforms 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚为桌面安装了 Visual Studio 2012 express.我看不到任何地方可以用 C++ 创建 GUI 应用程序!Visual C++ 2010 中曾经存在过的Windows 窗体应用程序"在哪里?这些拖放控件在哪里?我安装它是因为我得到了详细信息,告诉它支持 GUI 智能感知(VisualC++:无法从另一个类调用方法)

I just installed Visual Studio 2012 express for Desktop. I can't see any place to create a GUI application with C++ ! Where is this "Windows Form Application" used to exists in Visual C++ 2010 ? Where are these drag and drop controls? I installed this because I got details telling this supports GUI intellisense (Visual C++: Unable to invoke method from another class)

推荐答案

这是一个明确的暗示,他们希望您停止创建 C++/CLI Winforms 应用程序.然而,管道仍然存在,至少对于 VS2012 和 VS2013.未来的情况可能不会如此.

It is an unsubtle hint that they want you to stop creating C++/CLI Winforms applications. The plumbing is still in place however, at least for VS2012 and VS2013. This might not be the case in a future one.

您可以通过以下步骤将 CLR 控制台应用程序转换为 Winforms 应用程序:

You can turn a CLR console application into a Winforms application with these steps:

  • 从文件 + 新建 + 项目、CLR 节点、CLR 控制台应用程序开始
  • 项目 + 添加新项目、UI 节点、Windows 窗体
  • 项目 + 属性、链接器、系统、子系统 = Windows
  • 项目 + 属性、链接器、高级、入口点 = main

将预先生成的 .cpp 文件更改为如下所示:

Change the pre-generated .cpp file to look like this:

#include "stdafx.h"
#include "MyForm.h"

namespace ConsoleApplication45 {    // Change this!!
    using namespace System;
    using namespace System::Windows::Forms;

    [STAThread]
    int main(array<System::String ^> ^args)
    {
        Application::EnableVisualStyles();
        Application::SetCompatibleTextRenderingDefault(false); 
        Application::Run(gcnew MyForm());
        return 0;
    }
}

请注意,您需要将命名空间名称更改为您的项目名称.按F5进行测试.一切检查完毕后,您就可以照常设计表单了.

Note that you'll need to change the namespace name to your project name. Press F5 to test. You can design the form as normal once everything checks out.

注意,Visual Studio 2015 在 CRT 中有一个令人讨厌的静态初始化顺序错误,如果项目包含任何本机 C++ 代码,它会导致应用程序在启动时立即崩溃并显示 AVE.尚未修复的错误,删除这些项目模板不可避免的危险.一种可能的解决方法是更改入口点(第 4 个项目符号).

NOTE, Visual Studio 2015 has a nasty static initialization order bug in the CRT that can cause the app to crash instantly with an AVE at startup if the project contains any native C++ code. As yet an unfixed bug, the somewhat inevitable hazard of having these project templates removed. A possible workaround is to change the Entry Point (4th bullet).

对于面向 x86 的项目,复制粘贴此字符串:

For a project that targets x86, copy paste this string:

?mainCRTStartupStrArray@@$$FYMHP$01AP$AAVString@System@@@Z

对于面向 x64 的项目,复制粘贴:

For a project that targets x64, copy paste:

?mainCRTStartupStrArray@@$$FYMHP$01EAPE$AAVString@System@@@Z

<小时>

在 VS2017 附近的某个地方,设计器无法打开带有神秘错误消息的新表单.解决方法是先构建项目,使用 Build > Build.


Somewhere around VS2017 the designer fails to open a new form with a cryptic error message. Workaround is to build the project first, use Build > Build.

这篇关于如何在 VS2012 中创建 C++/CLI Winforms 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆