Skip to content

Commit

Permalink
Merge pull request #496 from JinShil/master
Browse files Browse the repository at this point in the history
Moved 'How-tos/D for Win32' to wiki
  • Loading branch information
AndrejMitrovic committed Feb 23, 2014
2 parents 5740e69 + f8f5352 commit 4ae368b
Showing 1 changed file with 2 additions and 135 deletions.
137 changes: 2 additions & 135 deletions windows.dd
Expand Up @@ -2,141 +2,8 @@ Ddoc

$(D_S D for Win32,

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

$(P Instead of the:)

$(CCODE
#include <windows.h>
)
$(P of C, in D there is:)


--------------------
import core.sys.windows.windows;
--------------------


$(H2 Calling Conventions)

$(P In C, the Windows API calling conventions are $(CODE __stdcall).
In D, it is simply:
)

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


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

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

--------------------
export void func(int foo);
--------------------

$(P If no function body is given, it's imported. If a function body
is given, it's exported.
)

$(H2 Windows Executables)

$(P Windows GUI applications can be written with D.
A sample such can be found in $(D $(DMDDIR)\samples\d\winsamp.d)
)

$(P These are required:)

$(OL

$(LI Instead of a $(CODE main) function serving as the entry point,
a $(CODE WinMain) function is needed.
)

$(LI $(CODE WinMain) must follow this form:

--------------------
import core.runtime;
import core.sys.windows.windows;
import std.string;

extern (Windows)
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
int result;

void exceptionHandler(Throwable e) {
throw e;
}

try
{
Runtime.initialize(&exceptionHandler);
result = myWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
Runtime.terminate(&exceptionHandler);
}
catch (Throwable e) // catch any uncaught exceptions
{
MessageBoxA(null, e.toString().toStringz(), "Error",
MB_OK | MB_ICONEXCLAMATION);
result = 0; // failed
}

return result;
}

int myWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
// ... insert user code here ...
return 0;
}
--------------------


The $(D myWinMain()) function is where the user code goes, the
rest of $(D WinMain) is boilerplate to initialize and shut down
the D runtime system.
)

$(LI A $(CODE .def)
($(LINK2 http://www.digitalmars.com/ctg/ctgDefFiles.html, Module Definition File))
with at least the following
two lines in it:

$(MODDEFFILE
EXETYPE NT
SUBSYSTEM WINDOWS
)

Without those, Win32 will open a text console window whenever
the application is run.
)

$(LI The presence of $(D WinMain()) is recognized by the compiler
causing it to emit a reference to
$(LINK2 http://www.digitalmars.com/ctg/acrtused.html, __acrtused_dll)
and the phobos.lib runtime library.
)

)

$(H2 Windows Programming Examples)

A collection of over 140 Windows D programming code examples is available at
$(LINK2 https://github.com/AndrejMitrovic/DWindowsProgramming, this Github repository.)
This page has been moved to
$(LINK2 http://wiki.dlang.org/D_for_Win32, http://wiki.dlang.org/D_for_Win32)

)

Expand Down

0 comments on commit 4ae368b

Please sign in to comment.