Create C++ Windows Forms application in Visual Studio 2017 RRS feed

  • Debate general

  • Background:

    From Windows Forms Application in Visual C++ ???!!!!:

    "MS removed the WinForms C++/CLI template starting in either VS2012 or VS2013. The official explanation is that they want to encourage managed desktop UI development in C# or VB and relegate C++/CLI to serve as glue between native back end code and managed UI code."

    But for some reason, there are still many people who have reason to create a Windows Forms project of type C++/CLI, for these people, the following steps will show you how to create a C++/CLI Windows Forms app in Visual Studio 2017.

    Environmental configuration:

    Modify the Visual Studio 2017 installer and make sure the Visual Studio 2017 have installed C++ package with C++/CLR:

    Create new project:

    1, If you have installed all the package and components, then open Visual Studio 2017 and create a new project:

    2, You need to configure some properties first, right click on the Project and choose Properties option:

    Add new item:

    1, Right click on the project to add a new item, select UI under Visual C++,then choose Windows Form:

    In general, you will get error as below in this step:

    2, Don't worry, close it and add the following code to the MyForm.cpp:

        using namespace System;
        using namespace System::Windows::Forms;
        void Main(array<String^>^ args) {
            //WinformCDemo is your project name
    	WinformCDemo::MyForm form;

    3, After that, save it and close the Visual Studio, then reopen your Project. Note that when you reopen your Project, remember to build(or run directly) it first:

    4, Now you can design your app in the form by double click MyForm.h:

    That's all.

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    jueves, 6 de diciembre de 2018 7:42

Todas las respuestas

  • The current version of Visual Studio 2017:

    Microsoft Visual Studio Community 2017
    Version 15.9.4
    Microsoft .NET Framework
    Version 4.7.03056

    Does not allow uppercase for main.  Substitute main for Main in the linker->advanced setting and in the MyForm.cpp.

    lunes, 18 de febrero de 2019 17:50
  • I love you Dude, i swear i have about five hours looking in all the forums, i have twenty tab's looking for that, and always appeared the same Link Error, until i read your comment . I can't believe that only an uppercase could cause so much trouble, i really thank you for existing and comment here ChicagoCGuy ♥♥♥

    • Editado CamiloBY martes, 2 de abril de 2019 2:54
    martes, 2 de abril de 2019 2:53
  • With Visual Studio 15.7.3 I not only had to remove the capitalization for "Main" but he also had to change from "void main" to "int main" to resolve all linker errors.
    martes, 21 de mayo de 2019 20:29
  • If you cant get the namespace to work for the second to last line in the main() function it might be because for some reason namespaces take out special characters such as "_" and "+" as seen in this tutorial. If that's your problem, and you don't know what is omitted; take a look at the solution explorer, expand the header files folder, and then you should see another thing you can expand that has this by it "{ }". That is your namespace that you need to use. Hope that could help someone else that struggled as bad as me :) 

    Also don't uppercase main as others have said
    miércoles, 3 de julio de 2019 16:44
  • Alright, Thank you so much! It took me hours to get it to work!
    domingo, 5 de abril de 2020 22:07
  • Hello!

    Sir there is no UI option in my Visual Studio 2019 under new item menu.


    miércoles, 8 de julio de 2020 9:32
  • I just tested with VS 2019 16.7. Make sure you have installed the C++/CLI optional component and the .Net desktop development. When I only had the .Net development installed I didn't see the wizard option for a Windows Form project so the C++/CLI components is very much required.
    jueves, 6 de agosto de 2020 20:31
  • please use this simple steps:

    1-Download C++ Express 2010 from VS download page

    2-Install it

    3-If you are using VS greater than 2010 then all you need is create a project with c++ 2010

    4-Copy it to the VS, let's say, VS 2017/projects folder.

    5-Use VS 2017m open the project and there it is, it will work exactly as you create with VS 2017

    6-You need not go thru modification and stuffs

    Happy coding

    viernes, 14 de agosto de 2020 13:19
  • using namespace System;
    using namespace System::Windows::Forms;


    int APIENTRY wWinMain(_In_ HINSTANCE hInstance, 
    _In_opt_ HINSTANCE hPrevInstance,
    _In_ LPWSTR    lpCmdLine,
    _In_ int       nCmdShow)

    /*int main(array<String^>^ args) - this one runs with console, the upper one with  Windows (/SUBSYSTEM:WINDOWS) in linker */

    //WinformCDemo is your project name
    WinformCDemo::MyForm form;


    Microsoft Visual Studio Enterprise 2019

    lunes, 17 de agosto de 2020 21:00