zoukankan      html  css  js  c++  java
  • 学习DLL1

    一个简单地DLL例子:

    //Dll文件
    Library MyDll
     
    function max(a,b:integer):integer;stdcall;
     
    begin
     
    if a>then
       result:
    =a
       
    else
       result:
    =b;
      
    end;
     
    function min(a,b:integer):integer;stdcall;
     
    begin 
        
    if a>b
          
    then result:=
         
    else result:=a;
       
    end
    exports max,min;
     
    //调用DLL之一:动态调用
     
    type
     Tmax
    = function (x,y:integer):Integer;stdcall; 
     Tmin
    = function (x,y:integer):Integer;stdcall; 
    procedure TForm2.Button1Click(Sender: TObject); 
    var
     i,j,k:integer;
     hd:thandle;
     imax:Tmax;
    //通过类来使用 
     imin:Tmin;
    begin
     hd:
    =LoadLibrary('Mydll.dll'); 
      i:
    =strtoint(edit1.Text);
      j:
    =strtoint(edit2.Text); 
      
    if (Sender as TButton).Caption='Button1'  then 
      
    begin 
         imax:
    =GetProcAddress(hd,'max');     
         k:
    =imax(i,j); 
      
    end
       
    else
         
    begin
          imin:
    =GetProcAddress(hd,'min'); 
          k:
    =imin(i,j);
         
    end;
       Edit3.Text:
    =IntToStr(k);
       FreeLibrary(hd);
     
    end
    //静态调用
    implementation
    function max(a,b:integer):integer;stdcall;external 'Mydll'
    function min(a,b:integer):integer;stdcall;external 'Mydll';
     
    var 
       x,y,z:integer;
     
    begin
      x:
    =strtoint(edit1.text); 
      y:
    =strtoint(edit2.Text);
      z:
    =max(x,y);
      edit3.Text:
    =inttostr(z);
     
    end;

  • 相关阅读:
    汇编(一)续
    汇编(一)
    Ubuntu 安装配置Dosbox
    Linux系统安装Dos系统(虚拟机里装)
    .bundle文件如何安装
    Linux(Fedora)系统下配制8086汇编环境
    Linux常用命令
    linux下安装nginx
    缓存雪崩、缓存穿透、缓存击穿是什么?如何解决?
    Maven 实战
  • 原文地址:https://www.cnblogs.com/samsonleung/p/1241472.html
Copyright © 2011-2022 走看看