Movatterモバイル変換


[0]ホーム

URL:


D Logo
Menu
Search

Language Reference

table of contents

Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.Requires a signed-in GitHub account. This works well for small changes.If you'd like to make larger changes you may want to consider usinga local clone.

Windows Programming

Contents
  1. Windows 32 and 64 bit MSCOFF Programs
    1. Console Programs
    2. Windows GUI Programs
    3. DLLs

This covers Windows programming with 32 bit MSCOFF,64 bit MSCOFF, console programs, GUI programs, and DLLs.

All Console Programs

A D console program is specified by having a function with D linkage at module level calledmain. When the compiler sees this, it triggers the mixin templatecore.internal.entrypoint._d_cmain to be added. The_d_cmain template looks like:

template _d_cmain(){extern(C)    {int _d_run_main(int argc,char **argv,void* mainFunc);int _Dmain(char[][] args);int main(int argc,char **argv)        {return _d_run_main(argc, argv, &_Dmain);        }// Solaris, for unknown reasons, requires both a main() and an _main()version (Solaris)        {int _main(int argc,char** argv)            {return main(argc, argv);            }        }    }}

Themain function in it, because it is marked asextern(C), 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.

The C runtime library runs any D functions tagged withpragma(crt_constructor) as part of its initialization, and before it calls Cmain(). The order in which these are run is not specified.

The Cmain function then calls the D runtime library function_d_run_main, passing itargc andargv, and the address of_Dmain. The compiler renames the Dmain function in the source code to_Dmain.

_d_run_main then initializes the D runtime library, convertsargc andargv toargs, and calls the Dmain function.

When the Dmain function returns, control is back in_d_run_main which shuts down the D runtime library, and then returns to the Cmain, which then returns to the C library which shuts down the C runtime library, then exits the program.

The C runtime library runs any D functions tagged withpragma(crt_destructor) as part of its shutdown, in the reverse order that thepragma(crt_constructor)s were run.

Windows 32 and 64 bit MSCOFF Programs

32 bit and 64 bit MSCOFF programs use the Microsoft Visual C/C++ compiler as theAssociated C Compiler, generate object files in the MSCOFF format, and use the Microsoft linker to link them.

Console Programs

Windows GUI Programs

DLLs

Live Functions
Copyright © 1999-2026 by theD Language Foundation | Page generated byDdoc on Fri Feb 20 01:00:04 2026

[8]ページ先頭

©2009-2026 Movatter.jp