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;

  • 相关阅读:
    PHP标准库 (SPL) 笔记
    PHP反射
    PHPer书单
    深入理解面向对象——六大基本原则
    Session自定义存储及分布式存储
    06- Shell脚本学习--其它
    05- Shell脚本学习--函数
    04- Shell脚本学习--条件控制和循环语句
    03- Shell脚本学习--字符串和数组
    02- Shell脚本学习--运算符
  • 原文地址:https://www.cnblogs.com/samsonleung/p/1241472.html
Copyright © 2011-2022 走看看