晕倒,你的dll里的form1都没创建,你show什么啊?当然出错!dll里的form是不会自动创建的!

解决方案 »

  1.   

    上面已经贴出来了啊,我现在没有写代码,只是想实现创建DLL,调用DLL,
    因为初学,不是太会
      

  2.   

    只是想实现创建DLL,调用DLL的话把  form1.Show;改为ShowMessage('esdfdfd')一样能达到目的
      

  3.   

    但是我那么调用,老实出错啊
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation
    procedure some;stdcall;
    begin
      showmessage('sdf');
    {$R *.dfm}end.
    我要在另一个工程里调用它该如何调用:
    unit Unit_dll;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Buttons;type
      TForm1 = class(TForm)
        BitBtn1: TBitBtn;
        procedure BitBtn1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation
    procedure some;external 'project1.dll';
    {$R *.dfm}procedure TForm1.BitBtn1Click(Sender: TObject);
    begin
    some;
    end;end.
    请问出什么错
     
     
      

  4.   

    你的DLL肯定没法编译,我给你贴一些文档:The structure of a DLL is identical to that of a program, except that a DLL begins with the reserved word library (instead of program).
    The following example shows a DLL with two exported functions, Min and Max.library MinMax;
    function Min(X, Y: Integer): Integer; stdcall;begin
      if X < Y then Min := X else Min := Y;
    end;function Max(X, Y: Integer): Integer; stdcall;begin
      if X > Y then Max := X else Max := Y;
    end;exports  Min,
      Max;beginend.If you want your DLL to be available to applications written in other languages, it抯 safest to specify stdcall in the declarations of exported functions. Other languages may not support Object Pascal抯 default register calling convention.
    DLLs can be built from multiple units. In this case, the library source file is frequently reduced to a uses clause, an exports clause, and the DLL抯 initialization code. For example,library Editors;
    uses EdInit, EdInOut, EdFormat, EdPrint;
    exports  InitEditors,
      DoneEditors index 17 name Done,
      InsertText name Insert,
      DeleteSelection name Delete,
      FormatSelection,
      PrintSelection name Print,
       ...
      SetErrorHandler;begin  InitLibrary;
    end.You can put exports clauses in the interface or implementation section of a unit. Any library that includes such a unit in its uses clause automatically exports the routines listed the unit抯 exports clauses梬ithout the need for an exports clause of its own.
    Only routines that a library explicitly exports are available for importing by other libraries or programs.以上内容可在Delphi IDE下键入library,然后按F1得到.
      

  5.   

    另外,在调用Dll时你需要如下单元:
    unit MinMax;
    interface
    function Min(X, Y: Integer): Integer; stdcall;
    function Max(X, Y: Integer): Integer; stdcall;
    implementation
    const DllName='MinMax.DLL';
    function Min; external DllName;
    function Min; external DllName;
    end.
      

  6.   

    我给你写个简单的例子吧library DLLTest;interfaceuses
      Dialogs;procedure Test;
    begin
      ShowMessage('Ok');
    end;exports
      Test;implementation
    end.然后新建一个工程引用这个DLLprocedure Test; external 'DLLTest.dll';另:对于没有参数的过程不必要用stdcall。因为stdcall表示参数以堆栈形式(从右向左)传递,既然没有参数也就没必要用stdcall了