Why is the Win32 boilerplate the way it is?

Jacob Carlborg via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jun 29 00:51:44 PDT 2014


On 2014-06-29 06:47, Jeremy Sorensen wrote:
> I found an example of boilerplate code for Win32 programming in D here:
> http://wiki.dlang.org/D_for_Win32
>
> I have some questions.
> 1. It appears that the call to myWinMain from WinMain is to ensure that
> any exception or error is caught. At first glance it looks like this is
> to ensure that runtime.terminate() gets called, but in fact it doesn't,
> the catch block doesn't do it and there is no scope(exit).  Is this a
> problem? (And what would happen if you didn't catch the exception?)
> 2. Why does the boilerplate return 0 on success and failure? (If the
> return code is irrelevant, why the comment that says "failed" next to
> the return code?)
> 3. I can't imagine a technical reason why the myWinMain signature has to
> match the WinMain signature. Wouldn't it be better to omit the
> hPrevInstance since it isn't used? (Or are we preserving backwards
> compatibility with Win16?).
>
> If there is a resource somewhere that explains all this I would happy to
> consult it but I couldn't find anything.

You don't need to use WinMain. You can use a plain D main function and 
add the "-L/SUBSYSTEM:WINDOWS:4.0" link flag to suppress the console. 
There are API's to get access to the arguments passed to WinMain, if 
necessary.

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list