Application with WinMain does not start

Mike Parker via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Mar 5 06:01:11 PST 2016


On Saturday, 5 March 2016 at 13:16:19 UTC, Minas Mina wrote:
> I added a WinMain function to my application because I don't 
> want it to open a console when running on windows.
>
> But now it doesn't even start...
>
> extern (Windows)
> int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
>               LPSTR lpCmdLine, int nCmdShow)
> {
>     bool b = true;
>     while (b)
>     {
>         sync(Clock.currTime(utcTimeZone()));
>         Thread.sleep(getNextTimeToRun() - 
> Clock.currTime(utcTimeZone()));
>     }
> 	
>     return 0;
> }
>
> And this is my DUB configuration:
>
> name "..."
> description "..."
> copyright "..."
> authors "..."
> targetType "executable"
> lflags "/SUBSYSTEM:windows" "/EXETYPE:NT" platform="windows"
>
> I got those flags from here: http://wiki.dlang.org/D_for_Win32
>
> Any ideas:

When using WinMain, you are bypassing the DRuntime entry point, 
meaning the runtime is never initialized. You need to do it 
manually. However, since you're passing /SUBSYSTEM:windows on the 
command line, you *don't need* WinMain. That flag is for when you 
want to use main, but don't want the console to popup. If you use 
WinMain, you do not need that flag. To keep things simple, I 
recommend you use the /SUBSYSTEM:windows flag together with a 
regular main and drop WinMain completely. You can drop the 
/EXETYPE flag as well.


More information about the Digitalmars-d-learn mailing list