Book Image

D Cookbook

By : Adam Ruppe
Book Image

D Cookbook

By: Adam Ruppe

Overview of this book

Table of Contents (21 chapters)
D Cookbook
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Removing the Windows console


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.

How to do it…

Let's remove the Windows console by executing the following steps:

  1. Write your program normally.

  2. While compiling, pass –L/subsystem:windows to dmd.

How it works…

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.

There's more…

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...