下面是动态链接库使用多线程的代码,我在一个单独的应用程序中调用,但当应用程序退出时报地址错误:请高手赐教!
整个DLL中包含一个窗体和一个PAS单元文件:  Unit2 in 'Unit2.pas' {frmMain},
  connDb_U in 'connDb_U.pas'; 窗体只创建而不显示DLL:Library Project1;
uses
  ExceptionLog,
  Windows,
  Messages,
  SysUtils,
  Variants,
  Classes,
  Graphics,
  Controls,
  Forms,
  Dialogs,
  StdCtrls,
  Unit2 in 'Unit2.pas' {frmMain},
  connDb_U in 'connDb_U.pas';var
  DLLApp:TApplication;
  FStartThread :TStartThread;procedure init(App:TApplication);
begin
  Application:=App;  try
    Application.CreateForm(TfrmMain, frmMain); 
  except
    on e: exception do ShowMessage(e.Message);
  end;
   {  if FStartThread=nil  then
    FStartThread := TStartThread.Create(False); }
  //ShowMessage('StartThread');
  
end;procedure threadExit;
begin
  ShowMessage('ExitThread');  if (FStartThread <> nil) then
    FStartThread.Terminate;
end;procedure DLLEntryPoint(dwReson:DWord) ;
begin
  Case dwReson of
    DLL_Process_Attach : //init ;
      begin
        DLLApp := Application;
        //Application.CreateForm(TfrmMain, frmMain);
        //if FStartThread=nil  then
        //  FStartThread := TStartThread.Create(False);      end;
    DLL_Process_Detach : //threadExit;
      begin
        Application := DLLApp;
        //Application.Terminate;
      end;
    //DLL_Thread_Attach  : MessageBeep(0) ;
    //DLL_Thread_Detach  : Application.Terminate;
  end ; // if (Reason = DLL_PROCESS_DETACH) or (Reason = DLL_THREAD_DETACH) thenend ;procedure YK_Excute(sUnitID :String;sEquipmtId:String;iValue:Integer;iType:Integer);stdcall;export;
begin
  connDb_U.YK_Excute(sUnitID,sEquipmtId,iValue,iType);
end;{$R *.res}exports
  init ,
  YK_Excute;
//  DLLEntryPoint 
begin
  DLLApp:=Application;
  DLLProc := @DLLEntryPoint ;
  //DLLEntryPoint(DLL_Process_Attach) ;
  //DLLEntryPoint(DLL_Process_Detach) ;end. 
App:
var
  Form1: TForm1;
  procedure init(App: TApplication) ; Stdcall; external 'Project1.dll';
  procedure YK_Excute(sUnitID :String;sEquipmtId:String;iValue:Integer;iType:Integer) ; Stdcall; external 'Project1.dll';
  
...procedure TForm1.Button1Click(Sender: TObject);
begin
  init(Application) ;
  YK_Excute('BCB04','ZXC01',0,0);
end;