生成的dll文件,在调用时出现了错误?
library dll_demo1;
uses
  SysUtils,
  Classes,
  forms,
  Unitform1 in 'Unitform1.pas' {Form1};function showform:integer;stdcall;
  var
  form:Tform1;
  begin
  form:=tform1.create(application);
  form1.free;
  end;
  exports
     showform;
{$R *.res}begin
end.

解决方案 »

  1.   

    转载一个前人的例子(具体是谁写的不记得了)type
     TFormPERSON = class(TForm)
     private
       { Private declarations }
     public
       { Public declarations }
     end;
    //些处的变量不再用,给其改个地方,如下(改变之一)
    //var 
    //  FormPERSON: TFormPERSON;
    { Declare the export function 宣布Form函数出口}//改变之二
    function ShowPerSN(AHandle: THandle; ACaption: String):BOOL; StdCall;
    implementation
    {$R *.DFM}
    //函数据过程定义
    function ShowPerSN(AHandle: THandle; ACaption: String):BOOL;
    var
     FormPERSON: TFormPERSON; //定义窗体类(上面的放到了此处)
    begin
     // Copy application handle to DLL's TApplication object
     //拷贝应用程式句柄给DLL的应有程式对象
     Application.Handle := AHandle;
     FormPERSON := TFormPERSON.Create(Application);//创建控件TForm
     try
       FormPERSON.Caption := ACaption;
       FormPERSON.ShowModal;//显示此Form
       // Pass the date back in Result
       Result := False; //反回成功值
     finally
       FormPERSON.Free;
     end;
    end;三.DLL中函数及窗体的调用
    ==========================
    1.调用方法一
    --------------
    implementation //在此的下方写明调用函数的DLL{$R *.DFM}
    //DLL内函数调用
    function PenniesToSoins(SourceResult:Integer):Integer;
        StdCall external 'FIRSTDLL.DLL';........2.调用方法二
    ==============
    type  //在此创建一个函数类
     // 1 -------------------------------
     { First, define a procedural data type, this should reflect the
       procedure that is exported from the DLL. }
     { Create a new exception class to reflect a failed DLL load }
     TShowPerSN = function (AHandle: THandle; ACaption: String): BOOL; StdCall;
     EDLLLoadError = class(Exception);//同时分创建一个出错记录类
     // 1 -------------------------------
     TMAINCLTR = class(TForm) //这里不变,系统自动生成......procedure TMAINCLTR.ToolButton1Click(Sender: TObject);
    var  //按钮的调用事件:调用过程
     LibHandle: THandle;
     ShowPerSN: TShowPerSN;
    begin
     Application.Title:='人力资源管理系统DLL文件测试程式';
     { Attempt to load the DLL 尝试装入DLL文件}
     LibHandle := LoadLibrary('MGRPERSN.DLL');
     try
       if LibHandle = 0 then
         raise EDLLLoadError.Create('Unable to Load DLL(无法成功装入MGRPERSN.DLL)');
       @ShowPerSN := GetProcAddress(LibHandle, 'ShowPerSN');
       if not (@ShowPerSN = nil) then
         ShowPerSN(Application.Handle, '人事资料管理')//呼叫出窗体
       else
         RaiseLastWin32Error;
     finally
       FreeLibrary(LibHandle); // Unload the DLL.
     end;
    end;