大概的一个过程,从生成到调用
一. Dll的生成:
 1 把工程文件中的Programe 改为library 
 2 加输出函数:如:
library myDll;uses
  SysUtils,
  Classes,
  Base64 in 'Base64.pas';{$R *.RES}
  exports
    enCode,Decode;//此两函数已经在单元文件中定义,不需要带调用时的参数二.Dll的调用:var
  Form1: TForm1;
    function    Encode(s:PChar;d:PChar;var dn:integer;flg:boolean):boolean; stdcall;external                 'myDll.dll' ;
    function Decode(s:PChar;d:PChar;
                      var dn:integer;flg:boolean):boolean; stdcall;external   'myDll.dll';
implementation然后就可以调用普通过程一样调用了

解决方案 »

  1.   

    下在的调用方法出错:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
       TGetDouble=function(i:string): string;stdcall;
    var
      Form1: TForm1;implementation{$R *.dfm}
    //在delphi中动态调用DLL
    procedure TForm1.Button1Click(Sender: TObject);
    var
        DLLHandle: THandle;
        Func: TGetDouble;
        D:string;
    begin
     Try
      DLLHandle := LoadLibrary('zmjpass.dll');
      if DLLHandle <> null then
        begin
          @Func := GetProcAddress(DLLHandle, 'pass');
          //if Assigned(@Func) then
          if @Func<>nil then
            begin
               D := Func('abc');
               showmessage(D);
            end;
        end
      else
        begin
          showmessage('无法回放,不能调用DLL库!,请仔细检查相关设置!');
        end;
      finally
        FreeLibrary(DLLHandle);
      end;
    end;end.
      

  2.   

    出什么错误?
    输入参数是(userid:int;pass:string)
    方法是inpass,输出参数是(istrue:int;outpass:string);是什么意思?
    DLL引出的函数(引出的方法见Delphi Help中exports的帮助)最好不要用缺省调用方式,建议使用stdcall,cdecl也可以.
    尽可能不使用变长字符串、动态数组等需要内存管理模块的变量作为参数和返回值。
    不要把局部的字符串变量转换为Pchar返回,因为它将被释放。
    调用方法(以stdcall方式为例):
    1:DLL:
    library TestDll
    uses
      SysUtils,
      Classes;{$R *.RES}
    function SafeStrCpy(Dest:PChar;Source:PChar;MaxLen:Integer):Integer;stdcall;
    begin
      if MaxLen >StrLen(Source) then
        MaxLen := StrLen(Source);
      Move(Source^,Dest^,MaxLen);0D
      Result := MaxLen;
    end;exports
      SafeStrCpy;
    begin
    end.
    2:静态调用
    ...
      function SafeStrCpy(Dest:PChar;Source:PChar;MaxLen:Integer):Integer;stdcall;external 'TestDll.Dll';
    ...
    var
      Dest:String;
      CopyLen:Integer;
    begin
      Dest := StringOfChar(' ',100);
      CopyLen := SafeStrCpy(PChar(Dest),Edit1.Text,100);
      Dest := Copy(Dest,1,CopyLen);
    end;
    3:动态调用:
    ...
    type
      TSafeStrCpy=function(Dest:PChar;Source:PChar;MaxLen:Integer):Integer;stdcall;
    ...
    var
      SafeStrCpy:TSafeStrCpy;
    0A  DllHandle:THandle;
      Dest:String;
      CopyLen:Integer;
    begin
      DllHandle := LoadLibrary(PChar('TestDll.Dll'));
      if DllHandle = 0 then
        raise Exception.Create('加载TestDll.DLL失败');
      SafeStrCpy := TSafeStrCpy(GetProcAddress(DllHandle,PChar('SafeStrCpy')));
      if not Assigned(SafeStrCpy) then
        raise Exception.Create('在TestDll.dll中找不到入口SafeStrCpy');
      Dest := StringOfChar(' ',100);
      CopyLen := SafeStrCpy(PChar(Dest),PChar(Edit1.Text),100);
      Dest := Copy(Dest,1,CopyLen);
    end;
          ____     ____
         \ p \   / g /
          \ l \_/ n /
           \ a   o /
            \ i s /
             \ n /
              \_/