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;

    每天早上敲醒自己的不是闹钟,是夢想!
  • 相关阅读:
    Windows上部署MySql
    LeetCode 将一个按照升序排列的有序数组,转换为一棵高度平衡二叉搜索树
    LeetCode 把二叉搜索树转换为累加树
    Spring Cloud Eureka 分布式开发之服务注册中心、负载均衡、声明式服务调用实现
    mysql事务详解
    Java并发编程之ThreadLocal解析
    redis之mq实现发布订阅模式
    Zookeeper之Leader选举过程
    Spring Boot MyBatis 数据库集群访问实现
    分布式配置中心之spring-cloud-config
  • 原文地址:https://www.cnblogs.com/yplong/p/2344811.html
Copyright © 2011-2022 走看看