Converting console application to windows application – C++/CLI

Have you ever needed to convert a console application to windows application?

Recently, I worked on an application which was created to run on console, but later decided to move to windows application. To make it a windows forms application, you only have to add new windows form to the project. VS will add all necessary references automatically.

Modify your main method like,


int main(array<System::String ^> ^args)
{
        // Enabling Windows XP visual effects before any controls are created
        Application::EnableVisualStyles();
        Application::SetCompatibleTextRenderingDefault(false);
        // Create the main window and run it
        Application::Run(gcnew MainForm());
}

Run the application and you can see windows form coming up with a console window. Yes, the console window is not disappeared. To disable the console window, you need to change the /SUBSYSTEM linker option. Here is what MSDN says about /SUBSYSTEM.

The /SUBSYSTEM option tells the operating system how to run the .exe file. The choice of subsystem affects the entry point symbol (or entry point function) that the linker will choose.

Take the project properties, Configuration properties, Linker, System and set SubSystem as Windows (/SUBSYSTEM:WINDOWS). Run the application and you can see it starts without a console window.

Happy programming

About these ads

13 thoughts on “Converting console application to windows application – C++/CLI

  1. hi
    i tryto modify main() what u tell but there’er errors such as

    Error 1 error C2653: ‘Application’ : is not a class or namespace name c:\Users\Ob\Documents\Visual Studio 2008\Projects\testwin\testwin\testwin.cpp 13 testwin

    Error 2 error C3861: ‘EnableVisualStyles’: identifier not found c:\Users\Ob\Documents\Visual Studio 2008\Projects\testwin\testwin\testwin.cpp 13 testwin

    Error 3 error C2653: ‘Application’ : is not a class or namespace name c:\Users\Ob\Documents\Visual Studio 2008\Projects\testwin\testwin\testwin.cpp 14 testwin

    Error 4 error C3861: ‘SetCompatibleTextRenderingDefault’: identifier not found c:\Users\Ob\Documents\Visual Studio 2008\Projects\testwin\testwin\testwin.cpp 14 testwin

    Error 6 error C2061: syntax error : identifier ‘MainForm’ c:\Users\Ob\Documents\Visual Studio 2008\Projects\testwin\testwin\testwin.cpp 16 testwin

    Error 7 error C3861: ‘Run’: identifier not found c:\Users\Ob\Documents\Visual Studio 2008\Projects\testwin\testwin\testwin.cpp 16 testwin

    i don’t know how to fix this

    please tell me
    send me back
    my e-mail numobjakadee@gmail.com

  2. Hi

    I needed to concert my console application to windows form application and i did have exactly the same errors like in comment 1

    it seems that u managed to solve this problem. Can you please tell me how did u fix it?
    my mail is dina.reda.khattab@gmail.com

  3. i recieve the following errors?
    when you say “Do you have proper namespace includes?” what do you mean?

    please advise

    1>.\camera2.cpp(27) : error C2653: ‘Application’ : is not a class or namespace name
    1>.\camera2.cpp(27) : error C3861: ‘EnableVisualStyles’: identifier not found
    1>.\camera2.cpp(28) : error C2653: ‘Application’ : is not a class or namespace name
    1>.\camera2.cpp(28) : error C3861: ‘SetCompatibleTextRenderingDefault’: identifier not found
    1>.\camera2.cpp(31) : error C2653: ‘Application’ : is not a class or namespace name
    1>.\camera2.cpp(31) : error C2061: syntax error : identifier ‘Form1′
    1>.\camera2.cpp(31) : error C3861: ‘Run’: identifier not found

  4. I want to do the exact opposite – I have a Win32 application that I want to write a CLI (console) interface for so I can call it from a script. Obviously, I don’t want to have any windows popping up when I run the CLI.

  5. 1>FormCheck2.cpp(8): error C2337: ‘STAThreadAttribute’ : attribute not found
    1>FormCheck2.cpp(12): error C2653: ‘Application’ : is not a class or namespace name
    1>FormCheck2.cpp(12): error C3861: ‘EnableVisualStyles’: identifier not found
    1>FormCheck2.cpp(13): error C2653: ‘Application’ : is not a class or namespace name
    1>FormCheck2.cpp(13): error C3861: ‘SetCompatibleTextRenderingDefault’: identifier not found
    1>FormCheck2.cpp(16): error C2653: ‘Application’ : is not a class or namespace name
    1>FormCheck2.cpp(16): error C2061: syntax error : identifier ‘Form1′
    1>FormCheck2.cpp(16): error C3861: ‘Run’: identifier not found

    I am gettting the above errors, similar to abdul in the above thread, can u please correct me???
    my email id is gowthamravisankar90@gmail.com

  6. Hi,

    I am having a console application project in VC++. and I want to convert that project into windows supported application.

    I have followed the steps you have given in above discussion, but it gives me the error like this:

    Error 1 error D8016: ‘/clr:pure’ and ‘/Gm’ command-line options are incompatible D:\myWorks\skypekit-sdk_sdk-4.0.2.138_480749\skypekit-sdk_sdk-4.0.2.138_480749\examples\cpp\tutorial\build\vs2008\cl tutorial_1

    Please help me out…

    my email ID is : jagdishchopde20@gmail.com
    jagdishchopde@live.com

    Thank You…

  7. Hi,
    I have solved with that ‘/Gm’ error with changing that option from properties of project.

    but now I am facing another problem as listed above in this page.

    The errors are like these:

    Error 1 error C2871: ‘tutorial_1′ : a namespace with this name does not exist

    Error 2 error C2337: ‘STAThreadAttribute’ : attribute not found

    Error 3 error C2653: ‘Application’ : is not a class or namespace name

    Error 4 error C3861: ‘EnableVisualStyles’: identifier not found

    Error 5 error C2653: ‘Application’ : is not a class or namespace name

    Error 6 error C3861: ‘SetCompatibleTextRenderingDefault’: identifier not found

    Error 7 error C2653: ‘Application’ : is not a class or namespace name

    Error 8 error C2061: syntax error : identifier ‘frmLogin’

    Error 9 error C3861: ‘Run’: identifier not found

    Please anybody help me to solve this my problem while converting my console based VC++ project into Windows based Application in VS 2010.

    Thank You.

  8. I have made an encryption program as a console application, and I would like to convert it to a Win32 app. The only thing is… I use Dev-C++ so all of the VS things don’t work. Any ideas?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s