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 挂载windows 共享盘为本地磁盘
    模块
    message 匹配不上grok正则 也会写入到elasticsearch
    【Java】No enclosing instance of type XXX is accessible. Must qualify the allocation with an enclosing instance of type XXX(e.g. x.new A() where x is an instance of XXX).的解决办法
    【Ubuntu】常用软件及其下载地址
    【Java】内存分析
    【Java】利用二维数组进行排版
    【Java】一维数组
    【趣题】用for循环输出菱形
    【趣题】穷举法解决百钱买百鸡
  • 原文地址:https://www.cnblogs.com/yplong/p/2344811.html
Copyright © 2011-2022 走看看