[Win32 API] MessageBox Example without MSVCR120.dll dependency

BoQsc vaidas.boqsc at gmail.com
Sun Dec 25 18:30:12 UTC 2022


This is a working Hello World example without dependency on 
Microsoft C Runtime Library, I couldn't find anything by 
searching around the forums or search engines, so I'm posting it 
here. Please provide improvements if you feel like something is 
missing or incorrect.

**How to Compile:**
`dmd "./MessageBox_HelloWorld.d" "user32.lib"`

**Note:** This example can only be compiled with a 32 bit dmd 
compiler that exists in `.\dmd2\windows\bin\dmd.exe`

**Observations:**
* This example will generate a 208kb MessageBox_HelloWorld.exe 
binary
* This example is independent of MSVCR120.dll
* This example will open additional Command Prompt Window 
alongside the MessageBox_HelloWorld.exe

**MessageBox_HelloWorld.d**
```
module MessageBox_HelloWorld;

// A Win32 API Hello World MessageBox Example without 
MSVCR120.dll dependency

// Tested on Windows 10, 2022.12.25
// DMD32 D Compiler v2.101.1-dirty


import core.sys.windows.winuser : MessageBoxA, MB_OK;

void main()
{
     MessageBoxA(null, "Hello, World!", "My Win32 App", MB_OK);
}
```

![Screenshot](https://i.ibb.co/bvJ392k/Screenshot-1.png)



More information about the Digitalmars-d-learn mailing list