https://wiki.dlang.org/api.php?action=feedcontributions&user=Boqsc&feedformat=atomD Wiki - User contributions [en]2024-03-29T09:20:28ZUser contributionsMediaWiki 1.31.2https://wiki.dlang.org/?title=Terminology&diff=10205Terminology2023-12-20T16:42:55Z<p>Boqsc: </p>
<hr />
<div>Function is an input and output statement.<br />
* Taking input using function parameters or global variables.<br />
* And returning output using '''return''' statement or by modifying a global variable.</div>Boqschttps://wiki.dlang.org/?title=Terminology&diff=10204Terminology2023-12-20T16:42:27Z<p>Boqsc: </p>
<hr />
<div>Function is an input and output statement.<br />
* Taking input using function parameters or global variables.<br />
* And returning output using **return** statement or by modifying a global variable.</div>Boqschttps://wiki.dlang.org/?title=Terminology&diff=10203Terminology2023-12-20T16:39:33Z<p>Boqsc: </p>
<hr />
<div>Function is an input and output statement.</div>Boqschttps://wiki.dlang.org/?title=Terminology&diff=10202Terminology2023-12-20T16:37:26Z<p>Boqsc: Created page with "Function"</p>
<hr />
<div>Function</div>Boqschttps://wiki.dlang.org/?title=D_for_Win32&diff=10044D for Win322021-12-12T16:02:39Z<p>Boqsc: </p>
<hr />
<div>= Introduction =<br />
This describes the D implementation for 32 bit Windows systems. Naturally, Windows specific D features are not portable to other platforms.<br />
<br />
Instead of the:<br />
<syntaxhighlight lang="C"><br />
#include <windows.h><br />
</syntaxhighlight><br />
<br />
of C, in D there is:<br />
<syntaxhighlight lang="D"><br />
import core.sys.windows.windows;<br />
</syntaxhighlight><br />
<br />
= Calling Conventions =<br />
In C, the Windows API calling conventions are [https://stackoverflow.com/questions/297654/what-is-stdcall/297661#297661 '''__stdcall''']. In D, it is simply:<br />
<br />
<syntaxhighlight lang="C"><br />
extern (Windows)<br />
{<br />
/* ... function declarations ... */<br />
}<br />
</syntaxhighlight><br />
<br />
The Windows linkage attribute sets both the calling convention and the name mangling scheme to be compatible with Windows.<br />
<br />
For functions that in C would be '''__declspec(dllimport)''' or '''__declspec(dllexport)''', use the export attribute:<br />
<br />
<syntaxhighlight lang="C"><br />
export void func(int foo);<br />
</syntaxhighlight><br />
<br />
If no function body is given, it's imported. If a function body is given, it's exported.<br />
<br />
= Windows Executables =<br />
Windows GUI applications can be written with D. A sample such can be found in \samples\d\winsamp.d<br />
<br />
These are required:<br />
<br />
1. Instead of a '''main''' function serving as the entry point, a '''WinMain''' function is needed.<br />
<br />
2. '''WinMain''' must follow this form:<br />
<br />
<syntaxhighlight lang="D"><br />
import core.runtime;<br />
import core.sys.windows.windows;<br />
import std.string;<br />
<br />
extern (Windows)<br />
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,<br />
LPSTR lpCmdLine, int nCmdShow)<br />
{<br />
int result;<br />
<br />
try<br />
{<br />
Runtime.initialize();<br />
result = myWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow);<br />
Runtime.terminate();<br />
}<br />
catch (Throwable e) <br />
{<br />
MessageBoxA(null, e.toString().toStringz(), null,<br />
MB_ICONEXCLAMATION);<br />
result = 0; // failed<br />
}<br />
<br />
return result;<br />
}<br />
<br />
int myWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,<br />
LPSTR lpCmdLine, int nCmdShow)<br />
{<br />
// ... insert user code here ...<br />
return 0;<br />
}<br />
</syntaxhighlight><br />
<br />
The '''myWinMain()''' function is where the user code goes, the rest of '''WinMain''' is boilerplate to initialize and shut down the D runtime system.<br />
<br />
3. A '''.def''' ([http://www.digitalmars.com/ctg/ctgDefFiles.html Module Definition File]) with at least the following two lines in it:<br />
<pre><br />
EXETYPE NT<br />
SUBSYSTEM WINDOWS<br />
</pre><br />
Without those, Win32 will open a text console window whenever the application is run.<br />
<br />
4. The presence of '''WinMain()''' is recognized by the compiler causing it to emit a reference to [http://www.digitalmars.com/ctg/acrtused.html __acrtused_dll] and the phobos.lib runtime library.<br />
<br />
= Windows Programming Examples =<br />
A collection of over 140 Windows D programming code examples is available at [https://github.com/AndrejMitrovic/DWinProgramming this Github repository].<br />
<br />
<br />
[[Category:HowTo]]<br />
[[Category:Windows]]</div>Boqsc