D语言中国主页  D语言编辑器SciTE4D   DWin库 D语言官方网站
D语言编译器1.x最新版 OpenSource   Tango   webnews  Wiki

查看完整版本: 41 D for Win32

yidabu 2007-4-26 17:18

41 D for Win32

41 D for Win32知识若不分享 实在没有意义 http://www.d-programming-language-china.org 20070426点击下面网址查看原文:http://www.d-programming-language-china.org        by:        D语言论坛 http://www.d-programming-language-china.org        from:        http://www.digitalmars.com/d/windows.html        version:        基于D 1.012        (Apr 12, 2007)        本节描述了 32 位 Windows 系统下的 D 实现。自然,Windows 专用的 D 特性对其他平台是不可移植的。        在 C 语言中,我们这样做:        [Copy to clipboard] [ - ]CODE:                                #include <windows.h>                而在 D 中,我们这样做:        [Copy to clipboard] [ - ]CODE:                                import std.c.windows.windows;        Calling Conventions调用惯例        C调用Windows API用__stdcall,在D里很简单:        [Copy to clipboard] [ - ]CODE:                                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.( 本文出处: http://www.d-programming-language-china.org )Windows ExecutablesWindows 可执行程序        你可以使用 D 编写 Windows GUI 应用程序。一个简单的例子是 \dmd\samples\d\winsamp.d 。( 本文出处: http://www.d-programming-language-china.org )        编写Windows可执行程序需要这样做:        需要用WinMain函数代替main作为入口        WinMain 必须是以下格式:        [Copy to clipboard] [ - ]CODE:                                import std.c.windows.windows;                                extern (C) void gc_init();                extern (C) void gc_term();                extern (C) void _minit();                extern (C) void _moduleCtor();                extern (C) void _moduleDtor();                extern (C) void _moduleUnitTests();                                extern (Windows)                int WinMain(HINSTANCE hInstance,                    HINSTANCE hPrevInstance,                    LPSTR lpCmdLine,                    int nCmdShow)                {                    int result;                                    gc_init();            // initialize garbage collector                    _minit();            // initialize module constructor table                                    try                    {                    _moduleCtor();        // call module constructors                    _moduleUnitTests();    // run unit tests (optional)                                    result = myWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow);                                    _moduleDtor();        // call module destructors                    }                                    catch (Object o)        // catch any uncaught exceptions                    {                    MessageBoxA(null, cast(char *)o.toString(), "Error",                            MB_OK | MB_ICONEXCLAMATION);                    result = 0;        // failed                    }                                    gc_term();            // run finalizers; terminate garbage collector                    return result;                }                                int myWinMain(HINSTANCE hInstance,                    HINSTANCE hPrevInstance,                    LPSTR lpCmdLine,                    int nCmdShow)                {                    /* ... insert user code here ... */                }                The myWinMain() function is where the user code goes, the rest of WinMain is boilerplate to initialize and shut down the D runtime system.        A .def (Module Definition File) with at least the following two lines in it:        http://www.digitalmars.com/ctg/ctgDefFiles.html( 本文出处: http://www.d-programming-language-china.org )        QUOTE:                                EXETYPE NT                SUBSYSTEM WINDOWS                Without those, Win32 will open a text console window whenever the application is run.        The presence of WinMain() is recognized by the compiler causing it to emit a reference to __acrtused_dll and the phobos.lib runtime library.        http://www.digitalmars.com/ctg/acrtused.html( lastupdate:20070426 最新文章请访问http://www.d-programming-language-china.org )关于一大步成功社区:yidabu提倡在交流中学习,在分享中提高收集感兴趣的知识,写下心得,通过网络与别人一起分享理解一点就实践一步,收获什么就分享什么,成功就是这样一点点一步步累积起来的网络只是一个工具,只有自己身心提高才是实实在在的。d-programming-language-china.org为大家提供一个学习交流各种知识的平台
页: [1]
查看完整版本: 41 D for Win32