Thread overview
Application with WinMain does not start
Mar 05, 2016
Minas Mina
Mar 05, 2016
Mike Parker
Mar 05, 2016
Mike Parker
Mar 05, 2016
Minas Mina
March 05, 2016
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:
March 05, 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.
March 05, 2016
On Saturday, 5 March 2016 at 14:01:11 UTC, Mike Parker wrote:

> If you use WinMain, you do not need that flag.

Actually, I need to amend that. It isn't needed with WinMain when using the Microsoft linker, but it is when using OPTLINK. The MS linker recognizes WinMain and treats it as /SUBSYSTEM:WINDOWS by default.
March 05, 2016
On Saturday, 5 March 2016 at 14:08:28 UTC, Mike Parker wrote:
> On Saturday, 5 March 2016 at 14:01:11 UTC, Mike Parker wrote:
>
>> If you use WinMain, you do not need that flag.
>
> Actually, I need to amend that. It isn't needed with WinMain when using the Microsoft linker, but it is when using OPTLINK. The MS linker recognizes WinMain and treats it as /SUBSYSTEM:WINDOWS by default.

Thanks. I removed the WinMain and it worked.