Create Windows Program with GUI but use 'main()' (in D)?

570 views Asked by At

Is it possible, to in Windows, create a GUI program, which has it's entry point in 'main()'? How do I do this?

My use for this is that I want a cross-platform application, with one uniform entry point.

1

There are 1 answers

4
Ben Voigt On BEST ANSWER
  1. Write your application using main() and all the GUI calls in there that you would have used in WinMain. This will create an application with both a GUI and a console window.
  2. Use the Windows SDK tool editbin /SUBSYSTEM:WINDOWS appname.exe to change the subsystem flag in the PE header, so Windows won't create a console window automatically.
  3. If you want to have a working stdout for debug message or the like, you can either use freopen to direct stdout to a file, or AllocConsole when you decide a console window is needed (for example, after an error occurs).

BTW: This thread indicates that the DMD compiler will prefer main() over WinMain() anyway if it finds both.