Create a Graphical Win32 Window in a Console Application (VS 2015)

This sample demonstrates how you can get all of the WinMain parameter values from a Console application. It also shows how to use "main" instead of "wmain" or "wWinMain" as the entry point for a Unicode application for ISO C++ compliance.

C++ (33.0 KB)
4.5 Star
3,913 times
Add to favorites
E-mail Twitter Digg Facebook
Sign in to ask a question

  • Functionality
    4 Posts | Last post February 21, 2017
    • When i run the program, it just presents a console window with that prints "press any key..." and exits.
      When i step through the program, it throws an error when it gets to this point:
      HACCEL hAccelTable;
      	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
      cant seem to figure it out.
    • I just tried it on Windows 10 with VS 2017 RC. I created it on Windows 8.1 using VS 2015. Can you give me details about what OS you're using and what version of Visual Studio?
      When you first open the solution it will warn about it being untrusted. I've never tried telling VS that I don't trust it (I wrote it so of course I trust it). Did you click on the don't trust option? If so, I'll try that and see what happens. I tried both stepping through the program using the Debug/Win32 configuration and also setting a break point on the line you mentioned and I couldn't get it to trigger a problem.
      The more details you can provide, the better I can try to figure out what's going on and why it isn't working as expected for you. If you'd like, feel free to run "Clean Solution" under the "Build" menu and then zip up the folder. My email address is my username here (lowercase) at gmail dot com. Seeing the solution and project files may help me figure out the issue.
      Best regards and thank you for the report,
    • Thanks for the quick response Mike! I'm using VS 2015 RC...with update 2 I believe, on a Windows 10 Box.
      When opening the solution I didn't run into any issues or questions about trusting.
      As for the issue now, I was playing with it and commented out both lines listed above (seperatly and also together), and since I've uncommented them i cannot recreate the error. However the program now displays the console for a second, and then the program exits with code 0.
      I will try cleaning the solution and sending it your way.
    • Not sure if this helps as well, but when I stepped through it again, it takes me to the exe_common.inl and the last lines it goes through are:
       if (!__scrt_is_managed_app())
      it then takes me to the disassembly page and goes through this:
       259:         if (!__scrt_is_managed_app())
      00362993 E8 CB E7 FF FF       call        ___scrt_is_managed_app (0361163h)
      seems to bounce back and forth between the inl and the disassembly page going through these couple lines.