zoukankan      html  css  js  c++  java
  • dll窗体的创建与调用

    建立DLL项目:

    library ShowDllForm;
    ....
    Uses ...
    Exports //输出引用
    ShowDllModalForm, //显示模态窗体
    ShowDllForm; //显示非模态窗体
    begin
    end.

    加入DLL窗体:

    Unit DllFrm; //DllFrm表单源码
    interface
    ...
    ...
    private
    ...
    public
    ...
    end.
    //声明过程
    Procedure ShowDllModalForm(aHandle:THandle);stdcall;
    Procedure ShowDllForm(aHandle:THandle);stdcall;
    ......
    implementation
    ....
    procedure ShowDllModalForm(aHandle:THandle);
    begin
       application.handle:=ahandle;
       with TDllFrm.create(application) do
       begin
            try
               showmodal;
            finally
               free;
            end;
       end;
    end;
    Procedure ShowDllForm(aHandle:THandle);
    begin
       application.handle:=ahandle;
       with tdllfrm.create(application) do
             show;
    end;
    .....
    end.

    静态调用:

    //声明过程:
    Unit ...
    Interface ...
    uses ...
       //声明静态链接DLL引出的过程
       procedure ShowDllModalForm(aHandle:tHandle);stdcall external '.\ShowDllForm.dll';
       procedure ShowDllForm(aHandle:thandle);stdcall external '.\showdllform.dll';
    type...
    .....
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    //按声明的函数调用DLL引出的过程,参数是当前应用程序的句柄
    showdllmodalform(application.Handle);
    end;

    procedure TForm1.Button2Click(Sender: TObject);
    begin
    //按声明的函数调用DLL引出的过程,参数是当前应用程序的句柄
    showdllform(application.Handle);
    end;

    end.

    动态调用:

    unit ...
    interface ...
    uses
        ....
    type
        .....
    private
        DllHandle:THandle; //DLL句柄

        TShowDllForm=procedure(aHandle:THandle);stdcall; //类定义,DLL引出的过程类型

        ....
    //表单建立时装入DLL文件
    procedure TForm1.FormCreate(sender:tobject);
    begin
       DllHandle:=LoadLibrary('.\dll\DllShowForm.dll');
       if DllHandle=0 then
          showmessage('无法装入DLL文件.');
    end;
    //表单释放时,同时释放Dll
    procedure TForm1.FormDestroy(sender:Tobject);
    begin
       freelibrary(dllhandle);
    end;

    //显示模态窗体
    var
       ShowModalForm:TShowDllForm;
    begin
       @ShowModalForm:=GetProcAddress(dllhandle,'ShowDllModalForm');
       showModalForm(application.handle);
    end;

    //显示非模态窗体
    var
       showFrm:TshowDllForm;
    begin
       @showfrm:=GetProcAddress(dllHandle,'ShowDllForm'); //注意DLL内函数名的大小写
       showfrm(application.handle);
    end;

    每天早上敲醒自己的不是闹钟,是夢想!
  • 相关阅读:
    asp.net中Session过期设置方法
    SQL server的一道入门面试题背后的思考
    SQL Server 2008中SQL应用之-“阻塞(Blocking)”
    win2003+vs2010下安装asp.net MVC3正式版失败经历
    WinForm下ComboBox设定SelectedValue总结
    SQL Server 2008中的代码安全(四):主密钥
    【译】SQL Server误区30日谈Day12TempDB的文件数和需要和CPU数目保持一致
    西雅图SQL PASS之旅
    【译】SQL Server误区30日谈Day10数据库镜像在故障发生后,马上就能发现
    Ado.net的连接池
  • 原文地址:https://www.cnblogs.com/yplong/p/2344811.html
Copyright © 2011-2022 走看看