哪个可以给个调用外部dll文件的源码,第一次用

解决方案 »

  1.   

    这是DLL代码:
    library AllPublic;uses
      Messages,
      SysUtils,
      Forms,
      Classes,
      Controls,
      Dialogs,
      Inifiles;type
      AFormInfo=array[0..4] of integer;{$R *.res}function GetNextId(Id: string): pchar;stdcall;
    //=====Get a next number=================//
    //=====Input value :   starnumber =======//
    //=====return value:   Nextnumber =======//
    //=====Write by    :   BaoQiongLin=======//
    //=====Date        :   2003/12/07 =======//
    var
      Int_len  :  Integer;
      Int_pos  :  Integer;
      Str_value:  String ;
      Int_char :  Integer;
      Next_flag : Boolean;
      pos2      : Integer;
    begin
      Int_pos:=0;
      pos2:=0;
      Int_len:=Length(Id);
      Str_value:='';   //return value
      Next_flag:=true;
      repeat
         Int_char:=Ord(Id[Int_len-Int_pos]);
         if Next_flag then
         begin
            Next_flag:=false;
            Int_char:=Int_char+1;
            If Int_char<48 then
            begin
               Int_char:=48;
            end
            else
            begin
               if Int_char>57 then
               begin
                  Int_char:=48;
                  Next_flag:=true;
                  pos2:=pos2+1;
               end;
            end;
         end;
         Str_value:=chr(Int_char)+Str_value;
         Int_pos:=Int_pos+1;
      Until Int_pos>Int_len-1;
      if Pos2=Int_pos then
         Str_value:='A' + Str_value;
      GetNextId:=Pchar(Str_value);
    end;
    exports
       GetNextId,
    beginend.下面是调用方法:function GetNextId(Id: string): pchar;stdcall;
             external 'AllPublic.dll';然后在程序中加入  GetNextID(Str)即可
      

  2.   

    implementation{$R *.dfm}function GetDiskSER():string;stdcall;external 'F:\EIMS\stoff\1\diskser.dll';procedure TForm1.Button1Click(Sender: TObject);
    begin
      showmessage(GetDiskSER());
    end;end.上面运行进出错
    在PB里可调用的
    FUNCTION string GetDiskSER() LIBRARY "diskser.dll"