大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> 程序开发 -> DLL文件在Delphi的创建及调用

DLL文件在Delphi的创建及调用

时间: 2021-07-31 作者:daque

    当前体例的开拓,普遍都在几人之上的拉拢,工协作办法开拓,如许也简单体例的赶快开拓手段。而dll的本领最为简单。我现整治了我的少许这上面材料,蓄意能扶助少许有须要的同业。一.因变量进程的写法:library firstdll;uses  sysutils,  classes;{$r *.res}// 1.设置因变量简直进程和输入接口办法// --------------------------------// 因变量 1// 功效:事数据3倍夸大因变量// --------------------------------function penniestosoins(sourceresult:integer):integer;stdcall;begin  if sourceresult>0 then    result:=sourceresult*3 //截止寄存于result  else    result:=sourceresult;end;exports   penniestosoins; //2.因变量输入口设置  end.====二.在dll中创造form=======================1.一步,创造dll工程,及介入树立好的formlibrary mgrpersn;uses  sysutils,  classes,  mgrperfm in 'mgrperfm.pas' {formperson};//1.form的代码(与普遍的form一律){$r *.res}exports   showpersn;//2.因变量输入口设置beginend.2. 在dll设定的form的树立 ===========================================unit mgrperfm;interfaceuses  windows, messages, sysutils, classes, graphics, controls, forms, dialogs,  comctrls, toolwin, imglist;type  tformperson = class(tform)  private    { private declarations }  public    { public declarations }  end;//些处的变量不复用,给其改个场合,如次(变换之一)//var //  formperson: tformperson;{ declare the export function 颁布form因变量出口}//变换之二function showpersn(ahandle: thandle; acaption: string):bool; stdcall;implementation{$r *.dfm}//因变量据进程设置function showpersn(ahandle: thandle; acaption: string):bool;var  formperson: tformperson; //设置窗体类(上头的放到了此处)begin  // copy application handle to dll's tapplication object  //正片运用程式句柄给dll的应有程式东西  application.handle := ahandle;  formperson := tformperson.create(application);//创造控件tform  try    formperson.caption := acaption;    formperson.showmodal;//表露此form    // pass the date back in result    result := false; //反回胜利值  finally    formperson.free;  end;end;三.dll中因变量及窗体的挪用==========================1.挪用本领一--------------implementation //在此的下方写明挪用因变量的dll{$r *.dfm}//dll内因变量挪用function penniestosoins(sourceresult:integer):integer;     stdcall external 'firstdll.dll';........2.挪用本领二==============type  //在此创造一个因变量类  // 1 -------------------------------  { first, define a procedural data type, this should reflect the    procedure that is exported from the dll. }  { create a new exception class to reflect a failed dll load }  tshowpersn = function (ahandle: thandle; acaption: string): bool; stdcall;  edllloaderror = class(exception);//同时间创造一个堕落记载类  // 1 -------------------------------  tmaincltr = class(tform) //这边静止,体例机动天生......procedure tmaincltr.toolbutton1click(sender: tobject);var  //按钮的挪用事变:挪用进程  libhandle: thandle;  showpersn: tshowpersn;begin  application.title:='人工资源处置体例dll文献尝试程式';  { attempt to load the dll 试验装入dll文献}  libhandle := loadlibrary('mgrpersn.dll');  try    if libhandle = 0 then      raise edllloaderror.create('unable to load dll(没辙胜利装入mgrpersn.dll)');    @showpersn := getprocaddress(libhandle, 'showpersn');    if not (@showpersn = nil) then      showpersn(application.handle, '人事材料处置')//呼唤出窗体    else      raiselastwin32error;  finally    freelibrary(libhandle); // unload the dll.  end;end;============== end ==================

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.