Difference between revisions of "D for Win32"

From D Wiki
Jump to: navigation, search
(Created page with " == Windows == This describes the D implementation for 32 bit Windows systems. Naturally, Windows specific D features are not portable to other platforms. Instead of the: #...")
 
(added calling conventions)
Line 5: Line 5:
  
 
Instead of the:
 
Instead of the:
 
+
<syntaxhighlight lang="C">
 
#include <windows.h>
 
#include <windows.h>
 +
</syntaxhighlight>
  
 
of C, in D there is:
 
of C, in D there is:
 +
<syntaxhighlight lang="D">
 +
import core.sys.windows.windows;
 +
</syntaxhighlight>
 +
 +
===Calling Conventions===
 +
In C, the Windows API calling conventions are '''__stdcall'''. In D, it is simply:
 +
 +
<syntaxhighlight lang="C">
 +
extern (Windows)
 +
{
 +
/* ... function declarations ... */
 +
}
 +
</syntaxhighlight>
 +
 +
The Windows linkage attribute sets both the calling convention and the name mangling scheme to be compatible with Windows.
 +
 +
For functions that in C would be '''__declspec(dllimport)''' or '''__declspec(dllexport)''', use the export attribute:
 +
 +
<syntaxhighlight lang="C">
 +
export void func(int foo);
 +
</syntaxhighlight>
  
import core.sys.windows.windows;
+
If no function body is given, it's imported. If a function body is given, it's exported.

Revision as of 09:37, 12 February 2014

Windows

This describes the D implementation for 32 bit Windows systems. Naturally, Windows specific D features are not portable to other platforms.

Instead of the:

#include <windows.h>

of C, in D there is:

import core.sys.windows.windows;

Calling Conventions

In C, the Windows API calling conventions are __stdcall. In D, it is simply:

extern (Windows)
{
	/* ... function declarations ... */
}

The Windows linkage attribute sets both the calling convention and the name mangling scheme to be compatible with Windows.

For functions that in C would be __declspec(dllimport) or __declspec(dllexport), use the export attribute:

export void func(int foo);

If no function body is given, it's imported. If a function body is given, it's exported.