www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Application with WinMain does not start

reply Minas Mina <minas_0 hotmail.co.uk> writes:
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:
Mar 05 2016
parent reply Mike Parker <aldacron gmail.com> writes:
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.
Mar 05 2016
parent reply Mike Parker <aldacron gmail.com> writes:
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.
Mar 05 2016
parent Minas Mina <minas_0 hotmail.co.uk> writes:
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.
Mar 05 2016