{love to code?}

July 5, 2009

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

Filed under: C++/CLI — navaneethkn @ 4:46 PM
Tags: , ,

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

2 Comments »

  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

    Comment by numob — December 17, 2009 @ 9:01 PM | Reply

    • Do you have proper namespace includes? Are you sure you have proper references to required assemblies?

      Comment by navaneethkn — December 18, 2009 @ 9:53 AM | Reply


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.