• D语言 在ms-coff文件格式下使用DGUI库


            如果你使用DGUI库,同时又需要使用ms-coff格式的lib文件,那么你需要注意一些事情。

           在Visual-D中使用MS-COFF库文件格式需要选中以下两个选项:

    image      使用以下代码,编译时会出错

    import std.stdio;
    import dgui.all;
    import core.sys.windows.windows;
    import core.runtime;
    
    int main(string[] args)
    {
        Form f = new Form();
        f.size = Size(300,300);
        Application.run(f);
    }

    image

         错误提示找不到WinMain函数,这是因为使用微软的连接器,如果子系统为Windows时,会选择连接WinMain函数作为入口函数。

         处理这个问题有两个办法:

    一、把子系统改为 Console子系统

          image     这时候运行出来的程序会有一个命令行。  这个办法并不是很好。

    二、使用WinMain函数

    import std.stdio;
    import dgui.all;
    import core.sys.windows.windows;
    import core.runtime;
    
    extern (Windows)
        int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
        Form f = new Form();
        f.size = Size(300,300);
        Application.run(f);
        return 0;
    }

         使用以上代码编译,会通过,再运行出来没有窗口出来。这是为什么呢??

         这是因为D语言运行时库没有初始化。需要修改代码如下:

    import std.stdio;
    import dgui.all;
    import core.sys.windows.windows;
    import core.runtime;
    
    extern (Windows)
        int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
        Runtime.initialize();
        scope(exit)Runtime.terminate();
    
        Form f = new Form();
        f.size = Size(300,300);
        Application.run(f);
        return 0;
    }

          OK,搞定,运行出来了

  • 相关阅读:
    HDU 3085 Nightmare Ⅱ[双向广搜]
    HDU 4028 The time of a day [离散化DP]
    HDU4027 Can you answer these queries? [线段树]
    HDU 4331 Image Recognition [边上全为1构成的正方形个数]
    HDU4026 Unlock the Cell Phone [状态压缩DP]
    HDU 4333 Revolving Digits [扩展KMP]
    HDU4335 What is N? [数论(欧拉函数)]
    工程与管理
    项目管理笔记一
    通过100个单词掌握英语语法(七)ask
  • 原文地址:https://www.cnblogs.com/wanhongnan/p/5774943.html
Copyright © 2020-2023  润新知