www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - make D windows-aware

reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
DMD is Windows-aware in the sense that if you have a WinMain(), it emits a 
reference to acrtused or whatever, but what I mean is make it so we don't 
have to manually put all the D init / deinit code in the WinMain().  I mean, 
when we define main() for a console program, it automatically calls dmain() 
which calls main().  Why not make it so when we define WinMain(), it 
automatically calls DWinMain() before our WinMain() or something?

I can only see this as an advantage, as well, as then any fancy things 
Walter puts into dmain (like exception stack traces and just exception 
handling in general) will be put into DWinMain as well, instead of the 
"WinMain" living in (of all places) the docs and having to be copied into 
any Windows programs. 
Mar 22 2006
next sibling parent reply Sean Kelly <sean f4.ca> writes:
Jarrett Billingsley wrote:
 DMD is Windows-aware in the sense that if you have a WinMain(), it emits a 
 reference to acrtused or whatever, but what I mean is make it so we don't 
 have to manually put all the D init / deinit code in the WinMain().  I mean, 
 when we define main() for a console program, it automatically calls dmain() 
 which calls main().  Why not make it so when we define WinMain(), it 
 automatically calls DWinMain() before our WinMain() or something?
This thread seems pertinent: http://www.digitalmars.com/d/archives/digitalmars/D/learn/1815.html Sean
Mar 22 2006
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Sean Kelly" <sean f4.ca> wrote in message 
news:dvsgih$1rhe$1 digitaldaemon.com...
 This thread seems pertinent:

 http://www.digitalmars.com/d/archives/digitalmars/D/learn/1815.html

 Sean
I'll try that, though it makes it a bit awkward to get the hInstance parameter which I need.
Mar 22 2006
parent reply "Chris Miller" <chris dprogramming.com> writes:
On Wed, 22 Mar 2006 19:34:19 -0500, Jarrett Billingsley  
<kb3ctd2 yahoo.com> wrote:

 "Sean Kelly" <sean f4.ca> wrote in message
 news:dvsgih$1rhe$1 digitaldaemon.com...
 This thread seems pertinent:

 http://www.digitalmars.com/d/archives/digitalmars/D/learn/1815.html

 Sean
I'll try that, though it makes it a bit awkward to get the hInstance parameter which I need.
Can just use GetModuleHandleA(null)
Mar 22 2006
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Chris Miller" <chris dprogramming.com> wrote in message 
news:op.s6uctr1mpo9bzi moe...
 Can just use GetModuleHandleA(null)
Why thank you. I was wondering if there was an API call to get that. Now the only problem is that exceptions are displayed on the command line instead of popping up.. which may be a problem for the other programmers in my little group..
Mar 22 2006
next sibling parent reply "Regan Heath" <regan netwin.co.nz> writes:
On Wed, 22 Mar 2006 20:27:04 -0500, Jarrett Billingsley  
<kb3ctd2 yahoo.com> wrote:
 "Chris Miller" <chris dprogramming.com> wrote in message
 news:op.s6uctr1mpo9bzi moe...
 Can just use GetModuleHandleA(null)
Why thank you. I was wondering if there was an API call to get that. Now the only problem is that exceptions are displayed on the command line instead of popping up.. which may be a problem for the other programmers in my little group..
Can you catch them all in WinMain i.e. try { ..main.. } catch(Object o) { MessageBox(... } Regan
Mar 22 2006
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Regan Heath" <regan netwin.co.nz> wrote in message 
news:ops6uelhqc23k2f5 nrage.netwin.co.nz...
 Can you catch them all in WinMain i.e.

 try {
   ..main..
 } catch(Object o) {
   MessageBox(...
 }
If I use the method proposed by Sean, I'd have to catch the exceptions in my own main function, as the dmain catches them and prints them to the console. i.e. extern(C) main(..) int WinMain(..) { return main(1, &cmdline); } void main() { try { crap } catch(Exception e) { MessageBox("oh man" ~ e.toString()); } } Pretty ugly.
Mar 22 2006
next sibling parent reply kris <foo bar.com> writes:
Jarrett Billingsley wrote:
 "Regan Heath" <regan netwin.co.nz> wrote in message 
 news:ops6uelhqc23k2f5 nrage.netwin.co.nz...
 
Can you catch them all in WinMain i.e.

try {
  ..main..
} catch(Object o) {
  MessageBox(...
}
If I use the method proposed by Sean, I'd have to catch the exceptions in my own main function, as the dmain catches them and prints them to the console. i.e. extern(C) main(..) int WinMain(..) { return main(1, &cmdline); } void main() { try { crap } catch(Exception e) { MessageBox("oh man" ~ e.toString()); } } Pretty ugly.
You might ask Sean to decouple the default exception-handler from the runtime support in Ares. The idea would be that you could provide your own default-handler, and then the linker would bind that instead. Sean is already doing a lot of things like that with Ares, so it may not be too much of a stretch.
Mar 22 2006
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"kris" <foo bar.com> wrote in message 
news:dvsum5$2du4$1 digitaldaemon.com...
 You might ask Sean to decouple the default exception-handler from the 
 runtime support in Ares. The idea would be that you could provide your own 
 default-handler, and then the linker would bind that instead. Sean is 
 already doing a lot of things like that with Ares, so it may not be too 
 much of a stretch.
Not using Ares, sorry.
Mar 22 2006
prev sibling next sibling parent reply Hasan Aljudy <hasan.aljudy gmail.com> writes:
Jarrett Billingsley wrote:
 "Regan Heath" <regan netwin.co.nz> wrote in message 
 news:ops6uelhqc23k2f5 nrage.netwin.co.nz...
 
Can you catch them all in WinMain i.e.

try {
  ..main..
} catch(Object o) {
  MessageBox(...
}
If I use the method proposed by Sean, I'd have to catch the exceptions in my own main function, as the dmain catches them and prints them to the console. i.e. extern(C) main(..) int WinMain(..) { return main(1, &cmdline); } void main() { try { crap } catch(Exception e) { MessageBox("oh man" ~ e.toString()); } } Pretty ugly.
I think you can use the new scope(failure) construct!
Mar 22 2006
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Hasan Aljudy" <hasan.aljudy gmail.com> wrote in message 
news:dvsvif$2f4p$1 digitaldaemon.com...
 I think you can use the new scope(failure) construct!
I had a fleeting thought about that, then realized that scope(failure) doesn't let you actually catch the offending exception.
Mar 22 2006
prev sibling parent reply "Regan Heath" <regan netwin.co.nz> writes:
On Wed, 22 Mar 2006 20:42:57 -0500, Jarrett Billingsley  
<kb3ctd2 yahoo.com> wrote:
 "Regan Heath" <regan netwin.co.nz> wrote in message
 news:ops6uelhqc23k2f5 nrage.netwin.co.nz...
 Can you catch them all in WinMain i.e.

 try {
   ..main..
 } catch(Object o) {
   MessageBox(...
 }
If I use the method proposed by Sean, I'd have to catch the exceptions in my own main function, as the dmain catches them and prints them to the console. i.e. extern(C) main(..) int WinMain(..) { return main(1, &cmdline); } void main() { try { crap } catch(Exception e) { MessageBox("oh man" ~ e.toString()); } } Pretty ugly.
Yeah, though if you add 1 more layer, i.e. extern(C) main(..) int WinMain(..) { return main(1, &cmdline); } void main() { try { real_main(); } catch(Exception e) { MessageBox("oh man" ~ e.toString()); } } void real_main() { ..crap.. } it's not so bad. Regan
Mar 22 2006
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Regan Heath" <regan netwin.co.nz> wrote in message 
news:ops6uf9kzv23k2f5 nrage.netwin.co.nz...
 Yeah, though if you add 1 more layer, i.e.
 it's not so bad.
Well then.. :)
Mar 22 2006
prev sibling parent reply Sean Kelly <sean f4.ca> writes:
Jarrett Billingsley wrote:
 "Chris Miller" <chris dprogramming.com> wrote in message 
 news:op.s6uctr1mpo9bzi moe...
 Can just use GetModuleHandleA(null)
Why thank you. I was wondering if there was an API call to get that. Now the only problem is that exceptions are displayed on the command line instead of popping up.. which may be a problem for the other programmers in my little group..
Why not catch all exceptions in main, display them as appropriate, and then rethrow: void main( char[][] args ) { try { ... } catch( Exception e ) { // display dialog throw e; } catch( Object o ) { // display dialog } } Passing exceptions completely through the runtime would be a bit weird, as by the time the exception reached WinMain module dtors would have been called, the GC would have been terminated, etc. Sean
Mar 22 2006
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Sean Kelly" <sean f4.ca> wrote in message 
news:dvt5j1$2n35$1 digitaldaemon.com...
 Why not catch all exceptions in main, display them as appropriate, and 
 then rethrow:
Because that's ugly ;) Seriously, though, I'm working with some more novice programmers, and I want to make this as easy as possible for them. So I'd like to be able to say "just put everything in this function and don't worry about it." I think the extra layer of main like Regan suggested is what I'll do.
 Passing exceptions completely through the runtime would be a bit weird, as 
 by the time the exception reached WinMain module dtors would have been 
 called, the GC would have been terminated, etc.
They'd never make it all the way back to WinMain; they get caught by dmain and printed to the console. It's a consequence of dmain being meant for console apps.
Mar 22 2006
prev sibling parent "Chris Miller" <chris dprogramming.com> writes:
On Wed, 22 Mar 2006 14:30:29 -0500, Jarrett Billingsley  
<kb3ctd2 yahoo.com> wrote:

 DMD is Windows-aware in the sense that if you have a WinMain(), it emits  
 a
 reference to acrtused or whatever, but what I mean is make it so we don't
 have to manually put all the D init / deinit code in the WinMain().  I  
 mean,
 when we define main() for a console program, it automatically calls  
 dmain()
 which calls main().  Why not make it so when we define WinMain(), it
 automatically calls DWinMain() before our WinMain() or something?

 I can only see this as an advantage, as well, as then any fancy things
 Walter puts into dmain (like exception stack traces and just exception
 handling in general) will be put into DWinMain as well, instead of the
 "WinMain" living in (of all places) the docs and having to be copied into
 any Windows programs.
I just always use a D main and tell the linker what type of exe to make (pass -L/exet:nt/su:windows:4.0 or similar to DMD). I think this is how it always should have been. This lets you use D main char[][]args and/or WinMain args via GetCommandLine().
Mar 22 2006