Thread overview
[Win32 API] MessageBox Example without MSVCR120.dll dependency
Dec 25, 2022
BoQsc
Dec 25, 2022
Adam D Ruppe
Dec 26, 2022
novice2
Dec 26, 2022
RTM
December 25, 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

December 25, 2022

On Sunday, 25 December 2022 at 18:30:12 UTC, BoQsc wrote:

>

This is a working Hello World example without dependency on Microsoft C Runtime Library

you might also consider using -m32omf switch to dmd which will make it bundle the old digital mars c lib. this is generally worse but since it is bundled it can be convenient.

December 26, 2022

to avoid special compile command just add one code line:

pragma(lib, "user32.lib");

December 26, 2022

On Sunday, 25 December 2022 at 18:30:12 UTC, BoQsc wrote:

>

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.

My solution, 1068 bytes :)

https://forum.dlang.org/post/trsunkhmxurvvsrsxvgq@forum.dlang.org