由于好几个EXE都有ABOUT窗体。就想把ABOUT做成DLL然后给EXE调用。建立了一个ABOUT.DLL,工程文件代码如下
library About;uses
  SysUtils,
  Classes,
  AboutFrm in 'AboutFrm.pas' {FormAbout},
  PubUnit in 'PubUnit.pas';{$R *.res}exports
  ShowAboutFrm;beginend.
AboutFrm是窗体,其中没有加任何代码PubUnit是自己加的一个UNIT,代码如下unit PubUnit;interface
Uses Forms;procedure ShowAboutFrm(AHandle: THandle; ACaption: String);stdcall;implementation
Uses AboutFrm;procedure ShowAboutFrm(AHandle: THandle; ACaption: String);
var
  AboutFrm: TFormAbout;
begin
  Application.Handle := AHandle;
  AboutFrm := TFormAbout.Create(Application); //创建并显示窗体
  try
    AboutFrm.Caption :=ACaption;
    AboutFrm.ShowModal;                       //显示方式为模式化
  finally
    AboutFrm.Free;                            //用完后卸载该窗体
  end;
end;
end.
程序调用的地方是这么写的
var
  OneHandle:THandle;
  ShowAboutFrm:procedure(AHandle: THandle; ACaption: String);stdcall;
begin  try
    try
      OneHandle:=LoadLibrary('About.Dll');
      if OneHandle<>0 then
        @ShowAboutFrm := GetProcAddress(OneHandle,'ShowAboutFrm');
      if Not (@ShowAboutFrm<>nil) then
        ShowAboutFrm(Application.Handle,'关于')
      else
        RaiseLastWin32Error;
      except
    On E:Exception do
      ShowMSG(E.Message);
    end;
  finally
    FreeLibrary(OneHandle);
  end;
end;程序运行时总报 A call to an OS function failed谢谢

解决方案 »

  1.   

    >>ACaption: String
    改為:  ACaption: pchar;或者在代碼中修改如下:uses
      ShareMem,
      SysUtils,
      Classes,
    ...兩邊都要加上這個 ShareMem
      

  2.   

    else
            RaiseLastWin32Error;
          except
        On E:Exception do
          ShowMSG(E.Message);
        end;這部分代碼, 好象沒什麼用
      

  3.   

    if (@ShowAboutFrm<>nil) then  //这里把NOT去掉就可以了,只有不等于NIL时候才显示,你写反了
            ShowAboutFrm(Application.Handle,'关于')
          else
            RaiseLastWin32Error;