能吗?

解决方案 »

  1.   

    这样的:
          file--new- others-选择dll wizard 
       这时候就是dll 的代码模式, 最上面时library而不是program
    build后就是.dll结尾的文件.输出的函数要有STDCALL;
      例如:  
     function Pinc_36(SN:string):string; STDCALL;
    begin
    end; exports
        Pinc_36;
      

  2.   

    晕,我敢说delphi做的dll是兼容性最好的
      

  3.   

    当然可以了  
    dll 就是动态连接库
    给你点代码:
    调用一个DLL比写一个DLL要容易一些。首先给大家介绍的是静态调用方法,稍后将介绍动态调用方法,并就两种方法做一个比较。同样的,我们先举一个静态调用的例子。  unit Unit1;  interface  uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;  type TForm1 = class(TForm) Edit1: TEdit; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;  var Form1: TForm1;  implementation  {$R *.DFM}  //本行以下代码为我们真正动手写的代码  function TestDll(i:integer):integer;stdcall; external ’Delphi.dll’;  procedure TForm1.Button1Click(Sender: TObject); begin Edit1.Text:=IntToStr(TestDll(1)); end;  end.  上面的例子中我们在窗体上放置了一个编辑框(Edit)和一个按钮(Button),并且书写了很少的代码来测试我们刚刚编写的Delphi.dll。大家可以看到我们唯一做的工作是将TestDll函数的说明部分放在了implementation中,并且用external语句指定了Delphi.dll的位置。(本例中调用程序和Delphi.dll在同一个目录中。)让人兴奋的是,我们自己编写的TestDll函数很快被Delphi认出来了。您可做这样一个实验:输入“TestDll(”,很快Delphi就会用fly-by提示条提示您应该输入的参数是什么,就像我们使用Delphi中定义的其他函数一样简单。注意事项有以 下一些:  一、调用参数用stdcall。 和前面提到的一样,当引用DLL中的函数和过程时也要使用stdcall参数,原因和前面提到的一样。  二、用external语句指定被调用的DLL文件的路径和名称。 正如大家看到的,我们在external语句中指定了所要调用的DLL文件的名称。没有写路径是因为该DLL文件和调用它的主程序在同一目录下。如果该DLL文件在C:\,则我们可将上面的引用语句写为external ’C:\Delphi.dll’。注意文件的后缀.dll必须写上。  三、不能从DLL中调用全局变量。 如果我们在DLL中声明了某种全局变量,如:var s:byte 。这样在DLL中s这个全局变量是可以正常使用的,但s不能被调用程序使用,既s不能作为全局变量传递给调用程序。不过在调用程序中声明的变量可以作为参数传递给DLL。  四、被调用的DLL必须存在。 这一点很重要,使用静态调用方法时要求所调用的DLL文件以及要调用的函数或过程等等必须存在。如果不存在或指定的路径和文件名不正确的话,运行主程序时系统会提示“启动程序时出错”或“找不到*.dll文件”等运行错误。  第四章 在Delphi中动态调用DLL top  动态调用DLL相对复杂很多,但非常灵活。为了全面的说明该问题,这次我们举一个调用由C++编写的DLL的例子。首先在C++中编译下面的DLL源程序。  #include  extern ”C” _declspec(dllexport) int WINAPI TestC(int i) { return i; }  编译后生成一个DLL文件,在这里我们称该文件为Cpp.dll,该DLL中只有一个返回整数类型的函数TestC。为了方便说明,我们仍然引用上面的调用程序,只是将原来的Button1Click过程中的语句用下面的代码替换掉了。  procedure TForm1.Button1Click(Sender: TObject); type TIntFunc=function(i:integer):integer;stdcall; var Th:Thandle; Tf:TIntFunc; Tp:TFarProc; begin Th:=LoadLibrary(’Cpp.dll’); {装载DLL} if Th>0 then try Tp:=GetProcAddress(Th,PChar(’TestC’)); if Tp<>nil then begin Tf:=TIntFunc(Tp); Edit1.Text:=IntToStr(Tf(1)); {调用TestC函数} end else ShowMessage(’TestC函数没有找到’); finally FreeLibrary(Th); {释放DLL} end else ShowMessage(’Cpp.dll没有找到’); end;  大家已经看到了,这种动态调用技术很复杂,但只要修改参数,如修改LoadLibrary(’Cpp.dll’)中的DLL名称为’Delphi.dll’就可动态更改所调用的DLL。  一、定义所要调用的函数或过程的类型。 在上面的代码中我们定义了一个TIntFunc类型,这是对应我们将要调用的函数TestC的。在其他调用情况下也要做同样的定义工作。并且也要加上stdcall调用参数。 
      

  4.   

    // DLL示例library DLLINC;{ Important note about DLL memory management: ShareMem must be the
      first unit in your library's USES clause AND your project's (select
      Project-View Source) USES clause if your DLL exports any procedures or
      functions that pass strings as parameters or function results. This
      applies to all strings passed to and from your DLL--even those that
      are nested in records and classes. ShareMem is the interface unit to
      the BORLNDMM.DLL shared memory manager, which must be deployed along
      with your DLL. To avoid using BORLNDMM.DLL, pass string information
      using PChar or ShortString parameters. }uses
      SysUtils,
      Classes;{$R *.res}  function AsmInc(const A: Integer): Integer; stdcall;
      asm
        MOV  EAX, A
        INC EAX
      end;exports
      AsmInc;begin
    end.
    // 调用示例unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;  function AsmInc(const A: Integer): Integer; stdcall;var
      Form1: TForm1;implementation{$R *.dfm}
     function AsmInc; external 'DLLINC.DLL' name 'AsmInc';procedure TForm1.Button1Click(Sender: TObject);
    begin
      ShowMessage(IntToStr(AsmInc(122)));
    end;end.