zoukankan      html  css  js  c++  java
  • 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,搞定,运行出来了

  • 相关阅读:
    VirtualBox 给虚拟机绑定IP
    【转】 wget 命令用法详解
    [转]python -m SimpleHTTPServer
    longene QQ 安装目录
    查看mininet交换机中的流表
    aircrack-ng 字典破解WPA / WPA2
    Win7 64 安装Visual Studio 2010和SQL Server 2008 R2
    Floodlight 防火墙是如何起作用的
    小米2000万买域名mi.com
    Windows JDK环境变量的配置
  • 原文地址:https://www.cnblogs.com/wanhongnan/p/5774943.html
Copyright © 2011-2022 走看看