When you write a GUI program on Windows, you'll often want to suppress the automatic allocation of a console window while building the release executable.
Let's remove the Windows console by executing the following steps:
–L/subsystem:windows
to dmd
.A D program compiles the program to an .exe
file, which means it can use all the same linker capabilities as a program in C, including subsystems, 16-bit stubs (though D itself cannot be compiled to 16 bits), resources, and manifests.
The –L
option of dmd
forwards the given option to the linker. This can be used to pass any command to the linker, including the platform-specific ones, such as /subsystem
, seen here. By choosing the Windows subsystem, the operating system will not allocate a console.
It is also possible to write a WinMain
function in D. If you write WinMain
instead of main
, the linker will automatically mark it as using the Windows subsystem, without having to use the /subsystem
switch. If you do, be sure to call Runtime.initalize()
before doing anything. However, it is generally better to write programs with a normal main
function and use the linker switch since this ensures the runtime functions are always called correctly without the boilerplate. If you need the module handle or command line in a main
function, use GetModuleHandle(null)
and GetCommandLineW
, respectively.
18.190.156.93