$(DDOC $(DDOC_BLANKLINE )
$(DDOC_BLANKLINE )
$(SPEC_S Windows Programming,
$(DDOC_BLANKLINE )
$(HEADERNAV_TOC    $(HEADERNAV_SUBITEMS mscoff, Windows 32 and 64 bit MSCOFF Programs,
        $(HEADERNAV_ITEM mscoff-console, Console Programs)
        $(HEADERNAV_ITEM mscoff-windows, Windows GUI Programs)
        $(HEADERNAV_ITEM mscoff-dlls, DLLs)
    )
)
$(DDOC_BLANKLINE )
$(P This covers Windows programming with 32 bit MSCOFF,
64 bit MSCOFF, console programs, GUI programs, and DLLs.
)
$(DDOC_BLANKLINE )
<h2>All Console Programs</h2>
$(DDOC_BLANKLINE )
    $(P A D console program is specified by having a function with D linkage at module level called <code class="code">main</code>.
    When the compiler sees this, it triggers the mixin template <code class="code">core.internal.entrypoint._d_cmain</code>
    to be added. The <code class="code">_d_cmain</code> template looks like:
    )
$(D_CODE $(D_KEYWORD template) _d_cmain()
{
    $(D_KEYWORD extern)(C)
    {
        $(D_KEYWORD int) _d_run_main($(D_KEYWORD int) argc, $(D_KEYWORD char) **argv, $(D_KEYWORD void)* mainFunc);

        $(D_KEYWORD int) _Dmain($(D_KEYWORD char)[][] args);

        $(D_KEYWORD int) main($(D_KEYWORD int) argc, $(D_KEYWORD char) **argv)
        {
            $(D_KEYWORD return) _d_run_main(argc, argv, &amp;_Dmain);
        }

        $(D_COMMENT // Solaris, for unknown reasons, requires both a main$(LPAREN)$(RPAREN ) and an _main$(LPAREN)$(RPAREN )
)        $(D_KEYWORD version) (Solaris)
        {
            $(D_KEYWORD int) _main($(D_KEYWORD int) argc, $(D_KEYWORD char)** argv)
            {
                $(D_KEYWORD return) main(argc, argv);
            }
        }
    }
}
)
    $(P The <code class="code">main</code> function in it, because it is marked as <code class="code">extern(C)</code>, is the entry point of a
    C console program. The executable starts up as a C executable, with the C runtime library
    initialization and then the C main() function is called.)
    $(P The C runtime library runs any D functions tagged with <code class="code">pragma(crt_constructor)</code> as
    part of its initialization, and before it calls C <code class="code">main()</code>. The order in which these
    are run is not specified.)
    $(P The C <code class="code">main</code> function then calls the D runtime library function <code class="code">_d_run_main</code>, passing it
    <code class="code">argc</code> and <code class="code">argv</code>, and the address of <code class="code">_Dmain</code>. The compiler renames the D <code class="code">main</code> function in
    the source code to <code class="code">_Dmain</code>.)
    $(P <code class="code">_d_run_main</code> then initializes the D runtime library, converts <code class="code">argc</code> and <code class="code">argv</code> to <code class="code">args</code>,
    and calls the D <code class="code">main</code> function.)
    $(P When the D <code class="code">main</code> function returns, control is back in <code class="code">_d_run_main</code> which shuts down the
    D runtime library, and then returns to the C <code class="code">main</code>, which then returns to the C library
    which shuts down the C runtime library, then exits the program.)
    $(P The C runtime library runs any D functions tagged with <code class="code">pragma(crt_destructor)</code> as
    part of its shutdown, in the reverse order that the <code class="code">pragma(crt_constructor)</code>s were run.
    )
$(DDOC_BLANKLINE )
<h2>$(LNAME2 mscoff, Windows 32 and 64 bit MSCOFF Programs)</h2>
$(DDOC_BLANKLINE )
    $(P 32 bit and 64 bit MSCOFF programs use the Microsoft Visual C/C++ compiler as the $(ACC ),
    generate object files in the MSCOFF format, and use the Microsoft linker
    to link them.
    )
$(DDOC_BLANKLINE )
<h3>$(LNAME2 mscoff-console, Console Programs)</h3>
$(DDOC_BLANKLINE )
<h3>$(LNAME2 mscoff-windows, Windows GUI Programs)</h3>
$(DDOC_BLANKLINE )
<h3>$(LNAME2 mscoff-dlls, DLLs)</h3>
$(DDOC_BLANKLINE )
$(SPEC_SUBNAV_PREV ob, Live Functions)
)

)