@@ -4,10 +4,59 @@ $(SPEC_S Windows Programming,
4
4
5
5
$(HEADERNAV_TOC)
6
6
7
- $(P This covers Windows programming with 32 bit OMF, 32 bit Mscoff ,
8
- 64 bit Mscoff , console programs, GUI programs, and DLLs.
7
+ $(P This covers Windows programming with 32 bit MSCOFF ,
8
+ 64 bit MSCOFF , console programs, GUI programs, and DLLs.
9
9
)
10
10
11
+ $(H2 All Console Programs)
12
+
13
+ $(P A D console program is specified by having a function with D linkage at module level called `main`.
14
+ When the compiler sees this, it triggers the mixin template `core.internal.entrypoint._d_cmain`
15
+ to be added. The `_d_cmain` template looks like:
16
+ )
17
+ ---
18
+ template _d_cmain()
19
+ {
20
+ extern(C)
21
+ {
22
+ int _d_run_main(int argc, char **argv, void* mainFunc);
23
+
24
+ int _Dmain(char[][] args);
25
+
26
+ int main(int argc, char **argv)
27
+ {
28
+ return _d_run_main(argc, argv, &_Dmain);
29
+ }
30
+
31
+ // Solaris, for unknown reasons, requires both a main() and an _main()
32
+ version (Solaris)
33
+ {
34
+ int _main(int argc, char** argv)
35
+ {
36
+ return main(argc, argv);
37
+ }
38
+ }
39
+ }
40
+ }
41
+ ---
42
+ $(P The `main` function in it, because it is marked as `extern(C)`, is the entry point of a
43
+ C console program. The executable starts up as a C executable, with the C runtime library
44
+ initialization and then the C main() function is called.)
45
+ $(P The C runtime library runs any D functions tagged with `pragma(crt_constructor)` as
46
+ part of its initialization, and before it calls C `main()`. The order in which these
47
+ are run is not specified.)
48
+ $(P The C `main` function then calls the D runtime library function `_d_run_main`, passing it
49
+ `argc` and `argv`, and the address of `_Dmain`. The compiler renames the D `main` function in
50
+ the source code to `_Dmain`.)
51
+ $(P `_d_run_main` then initializes the D runtime library, converts `argc` and `argv` to `args`,
52
+ and calls the D `main` function.)
53
+ $(P When the D `main` function returns, control is back in `_d_run_main` which shuts down the
54
+ D runtime library, and then returns to the C `main`, which then returns to the C library
55
+ which shuts down the C runtime library, then exits the program.)
56
+ $(P The C runtime library runs any D functions tagged with `pragma(crt_destructor)` as
57
+ part of its shutdown, in the reverse order that the `pragma(crt_constructor)`s were run.
58
+ )
59
+
11
60
$(H2 $(LNAME2 mscoff, Windows 32 and 64 bit MSCOFF Programs))
12
61
13
62
$(P 32 bit and 64 bit MSCOFF programs use the Microsoft Visual C/C++ compiler as the $(ACC),
@@ -21,26 +70,10 @@ $(H3 $(LNAME2 mscoff-windows, Windows GUI Programs))
21
70
22
71
$(H3 $(LNAME2 mscoff-dlls, DLLs))
23
72
24
- $(H2 $(LNAME2 omf, Windows 32 bit OMF Programs))
25
-
26
- $(P 32 bit OMF programs use the
27
- $(LINK2 https://www.digitalmars.com/download/freecompiler.html, Digital Mars C/C++ compiler)
28
- as the $(ACC), generate object files in the OMF format, and use the
29
- $(LINK2 https://www.digitalmars.com/ctg/optlink.html, Optlink linker)
30
- to link them.
31
- )
32
-
33
- $(H3 $(LNAME2 omf-console, Console Programs))
34
-
35
- $(H3 $(LNAME2 omf-windows, Windows GUI Programs))
36
-
37
- $(H3 $(LNAME2 omf-dlls, DLLs))
38
-
39
- $(SPEC_SUBNAV_PREV_NEXT ob, Live Functions, glossary, Glossary)
73
+ $(SPEC_SUBNAV_PREV ob, Live Functions)
40
74
)
41
75
42
76
Macros:
43
77
CHAPTER=44
44
78
TITLE=Windows Programming
45
79
CATEGORY_SPEC=$0
46
-
0 commit comments