Abstractioning away main/winMain

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Sep 4 18:49:20 PDT 2015


On Saturday, 5 September 2015 at 01:43:43 UTC, Prudence wrote:
> extern (Windows) int WinMain(...)

If you use WinMain in D, you'll also have to initialize the D 
runtime yourself, which will call static constructors and such.

You'd be better off just using a regular main() function, then 
passing the `-L/SUBSYSTEM:WINDOWS:5.0` option to dmd when 
building (at least on 32 bit, not sure if it is the same on 64 
bit or not) so the linker makes a gui app - same as it does when 
it detects a WinMain in the program.


> const MyApp = Application.New({ std.stdio.writeln("MY APP IS 
> COOL"); });

Remember, gui apps don't necessarily have a console, so writeln 
may fail!

> (The main reason for doing this is to make it easier for 
> writing portable apps)


Just using a regular main function is the most portable solution. 
Then just offer helper functions or something to help with the 
boilerplate.


More information about the Digitalmars-d-learn mailing list