www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - static constructor not working with WinMain GUI app

reply Andrej Mitrovic <none none.none> writes:
maintest.def:
EXETYPE NT
SUBSYSTEM WINDOWS

maintest.d:
http://pastebin.com/3c4CKDG1

Compiled with DMD 2.050: 
dmd maintest.d maintest.def

The output in the log file is "Lenght: 0". The static constructor is never
called when using WinMain.

But if I use a normal "void main()" function instead of WinMain, then the
static constructor does get called. Here's a working example that tests a GUI
dialogbox and outputs "Length: 4" in the log file:

maintest.def:
EXETYPE NT
SUBSYSTEM WINDOWS

maintest.d:
http://pastebin.com/3UDKmxJ1

dmd maintest.d maintest.def

This looks like a bug to me..
Nov 23 2010
next sibling parent reply "Simen kjaeraas" <simen.kjaras gmail.com> writes:
Andrej Mitrovic <none none.none> wrote:

 maintest.def:
 EXETYPE NT
 SUBSYSTEM WINDOWS

 maintest.d:
 http://pastebin.com/3c4CKDG1

 Compiled with DMD 2.050:
 dmd maintest.d maintest.def

 The output in the log file is "Lenght: 0". The static constructor is  
 never called when using WinMain.

 But if I use a normal "void main()" function instead of WinMain, then  
 the static constructor does get called. Here's a working example that  
 tests a GUI dialogbox and outputs "Length: 4" in the log file:

 maintest.def:
 EXETYPE NT
 SUBSYSTEM WINDOWS

 maintest.d:
 http://pastebin.com/3UDKmxJ1

 dmd maintest.d maintest.def

 This looks like a bug to me..
Looking at http://digitalmars.com/d/2.0/windows.html, it seems your template for WinMain is outdated. You should use the template on that page, but beware that exceptionHandler should take a Throwable, not an Exception, like the example says. This error is reported: http://d.puremagic.com/issues/show_bug.cgi?id=5261 -- Simen
Nov 23 2010
next sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
This means the windows sample code that comes with DMD in the samples
folder has to be updated, that's where I took the template from.

Thanks.

On 11/23/10, Simen kjaeraas <simen.kjaras gmail.com> wrote:
 Andrej Mitrovic <none none.none> wrote:

 maintest.def:
 EXETYPE NT
 SUBSYSTEM WINDOWS

 maintest.d:
 http://pastebin.com/3c4CKDG1

 Compiled with DMD 2.050:
 dmd maintest.d maintest.def

 The output in the log file is "Lenght: 0". The static constructor is
 never called when using WinMain.

 But if I use a normal "void main()" function instead of WinMain, then
 the static constructor does get called. Here's a working example that
 tests a GUI dialogbox and outputs "Length: 4" in the log file:

 maintest.def:
 EXETYPE NT
 SUBSYSTEM WINDOWS

 maintest.d:
 http://pastebin.com/3UDKmxJ1

 dmd maintest.d maintest.def

 This looks like a bug to me..
Looking at http://digitalmars.com/d/2.0/windows.html, it seems your template for WinMain is outdated. You should use the template on that page, but beware that exceptionHandler should take a Throwable, not an Exception, like the example says. This error is reported: http://d.puremagic.com/issues/show_bug.cgi?id=5261 -- Simen
Nov 24 2010
prev sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
Ok I've filed a bug report and the fix:
http://d.puremagic.com/issues/show_bug.cgi?id=5268

On 11/24/10, Andrej Mitrovic <andrej.mitrovich gmail.com> wrote:
 This means the windows sample code that comes with DMD in the samples
 folder has to be updated, that's where I took the template from.

 Thanks.

 On 11/23/10, Simen kjaeraas <simen.kjaras gmail.com> wrote:
 Andrej Mitrovic <none none.none> wrote:

 maintest.def:
 EXETYPE NT
 SUBSYSTEM WINDOWS

 maintest.d:
 http://pastebin.com/3c4CKDG1

 Compiled with DMD 2.050:
 dmd maintest.d maintest.def

 The output in the log file is "Lenght: 0". The static constructor is
 never called when using WinMain.

 But if I use a normal "void main()" function instead of WinMain, then
 the static constructor does get called. Here's a working example that
 tests a GUI dialogbox and outputs "Length: 4" in the log file:

 maintest.def:
 EXETYPE NT
 SUBSYSTEM WINDOWS

 maintest.d:
 http://pastebin.com/3UDKmxJ1

 dmd maintest.d maintest.def

 This looks like a bug to me..
Looking at http://digitalmars.com/d/2.0/windows.html, it seems your template for WinMain is outdated. You should use the template on that page, but beware that exceptionHandler should take a Throwable, not an Exception, like the example says. This error is reported: http://d.puremagic.com/issues/show_bug.cgi?id=5261 -- Simen
Nov 24 2010
prev sibling parent Michal Minich <michal.minich gmail.com> writes:
On Tue, 23 Nov 2010 15:23:12 -0500, Andrej Mitrovic wrote:

 The static constructor is never called when using WinMain.
Make sure you use newest DMD, I think in 2.048 or 49 there was bug that module constructors were not called.
Nov 23 2010