Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Choosing between WinMain and main in MC++

Choosing between WinMain and main in MC++

Scheduled Pinned Locked Moved Managed C++/CLI
c++helpquestion
8 Posts 2 Posters 24 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nish Nishant
    wrote on last edited by
    #1

    Hello If you use main or _tmain then your code will be basically a console app. Even if you use Application::Run to bring up a form, the ugly console will lurk behind. The solution is to use WinMain() instead of _tmain(). This was all very fine till I started using IJW. I need to #include <windows.h> But the moment I #include <windows.h> I get the compile error that says :- d:\Projects\Capture01\Capture01.cpp(22): error C2731: 'WinMain' : function cannot be overloaded :( :(:( :(:( :( Can anyone offer a solution? Nish


    Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

    N R 2 Replies Last reply
    0
    • N Nish Nishant

      Hello If you use main or _tmain then your code will be basically a console app. Even if you use Application::Run to bring up a form, the ugly console will lurk behind. The solution is to use WinMain() instead of _tmain(). This was all very fine till I started using IJW. I need to #include <windows.h> But the moment I #include <windows.h> I get the compile error that says :- d:\Projects\Capture01\Capture01.cpp(22): error C2731: 'WinMain' : function cannot be overloaded :( :(:( :(:( :( Can anyone offer a solution? Nish


      Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

      N Offline
      N Offline
      Nish Nishant
      wrote on last edited by
      #2

      Blast. I didn't think properly I guess. Problem solved. Used dummy args :-) Nish


      Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

      1 Reply Last reply
      0
      • N Nish Nishant

        Hello If you use main or _tmain then your code will be basically a console app. Even if you use Application::Run to bring up a form, the ugly console will lurk behind. The solution is to use WinMain() instead of _tmain(). This was all very fine till I started using IJW. I need to #include <windows.h> But the moment I #include <windows.h> I get the compile error that says :- d:\Projects\Capture01\Capture01.cpp(22): error C2731: 'WinMain' : function cannot be overloaded :( :(:( :(:( :( Can anyone offer a solution? Nish


        Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

        R Offline
        R Offline
        Rama Krishna Vavilala
        wrote on last edited by
        #3

        Well just go to linker options and add the following line to the command line /subsystem:windows, you will have a windows application with _tmain, or you can also try the reverse with /subsystem:console

        N 2 Replies Last reply
        0
        • R Rama Krishna Vavilala

          Well just go to linker options and add the following line to the command line /subsystem:windows, you will have a windows application with _tmain, or you can also try the reverse with /subsystem:console

          N Offline
          N Offline
          Nish Nishant
          wrote on last edited by
          #4

          Rama Krishna wrote: Well just go to linker options and add the following line to the command line /subsystem:windows, you will have a windows application with _tmain, or you can also try the reverse with /subsystem:console Thanks Rama, I didn't know that worked on C++ too :-) Thought that was a C# thing :-) Nish


          The posting stats are now in PDF:- http://www.busterboy.org/codeproject/ Feel free to make your comments. Updated - May 04th, Saturday

          1 Reply Last reply
          0
          • R Rama Krishna Vavilala

            Well just go to linker options and add the following line to the command line /subsystem:windows, you will have a windows application with _tmain, or you can also try the reverse with /subsystem:console

            N Offline
            N Offline
            Nish Nishant
            wrote on last edited by
            #5

            Rama Krishna wrote: add the following line to the command line /subsystem:windows, you will have a windows application with _tmain This didnt work on VS .NET academic and VS .NET beta 2. If you use the linker option - /subsystem:windows, it expects to find a WinMain. Nish


            The posting stats are now in PDF:- http://www.busterboy.org/codeproject/ Feel free to make your comments. Updated - May 04th, Saturday

            R 1 Reply Last reply
            0
            • N Nish Nishant

              Rama Krishna wrote: add the following line to the command line /subsystem:windows, you will have a windows application with _tmain This didnt work on VS .NET academic and VS .NET beta 2. If you use the linker option - /subsystem:windows, it expects to find a WinMain. Nish


              The posting stats are now in PDF:- http://www.busterboy.org/codeproject/ Feel free to make your comments. Updated - May 04th, Saturday

              R Offline
              R Offline
              Rama Krishna Vavilala
              wrote on last edited by
              #6

              I have been doing this for quite sometime. Can you mail me the project

              N 1 Reply Last reply
              0
              • R Rama Krishna Vavilala

                I have been doing this for quite sometime. Can you mail me the project

                N Offline
                N Offline
                Nish Nishant
                wrote on last edited by
                #7

                There is nothing special needed Rama. Just create a new MC++ project. And #include windows.h The default one would do. Now add /subsystem:windows to the linker command line options. The MC++ program should have only a _tmain() and not a WinMain(). The linker would say that, WinMain is missing. The problem is basically with #including windows.h For normal programs, what you say might work. But for MC++ programs that use IJW, your technique won't work Nish


                The posting stats are now in PDF:- http://www.busterboy.org/codeproject/ Feel free to make your comments. Updated - May 04th, Saturday

                R 1 Reply Last reply
                0
                • N Nish Nishant

                  There is nothing special needed Rama. Just create a new MC++ project. And #include windows.h The default one would do. Now add /subsystem:windows to the linker command line options. The MC++ program should have only a _tmain() and not a WinMain(). The linker would say that, WinMain is missing. The problem is basically with #including windows.h For normal programs, what you say might work. But for MC++ programs that use IJW, your technique won't work Nish


                  The posting stats are now in PDF:- http://www.busterboy.org/codeproject/ Feel free to make your comments. Updated - May 04th, Saturday

                  R Offline
                  R Offline
                  Rama Krishna Vavilala
                  wrote on last edited by
                  #8

                  I came to office just to check this out:) Just kidding I came here to complete my screen saver. Anyway you are right about /subsystem but the work around for that is to add the following two settings /substem:windows /entry:mainCRTStartup this would fix the problems. I wanted to write an article about compiler and linker settings since the days of CodeGuru but never got a chance.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups