www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - [Win32 API] MessageBox Example without MSVCR120.dll dependency

reply BoQsc <vaidas.boqsc gmail.com> writes:
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)
Dec 25 2022
next sibling parent Adam D Ruppe <destructionator gmail.com> writes:
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.
Dec 25 2022
prev sibling next sibling parent novice2 <sorry noem.ail> writes:
to avoid special compile command just add one code line:

pragma(lib, "user32.lib");
Dec 25 2022
prev sibling parent RTM <riven baryonides.ru> writes:
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
Dec 25 2022