Topic: Handling exception in DLL
Respected , kind day.
Faced a problem:
The project: Delphi XE + FireBird.
I use in the program dynamic library which itself and I develop.
The code of a call of library:
var DLLRoutine: function (AppHandle:HWND; HostDb: TIBDatabase): Boolean; stdcall; DLLHandle: THandle; ... DLLHandle: = LoadLibrary (PChar (lib)); try @DLLRoutine: = GetProcAddress (DLLHandle, PChar (func)); if Assigned (DLLRoutine) then DLLRoutine (Application. Handle, Base.ibCon) else MessageDlg (' Dynamic function ' + aRunStr + ' is not found ', mtInformation, [mbOK], 0); finally FreeLibrary (DLLHandle); end;
The handling code at outswapping DLL:
procedure MainDllProc (Reason: integer); var i: integer; begin //At loading DLL if (Reason = windows. DLL_PROCESS_ATTACH) then begin Base: = TBase. Create (Application); Res: = TRes. Create (Application); dxInitializeGDIPlus; end; //At outswapping DLL if (Reason = windows. DLL_PROCESS_DETACH) then begin ReleaseExceptionObject; dxFinalizeGDIPlus; with Application do begin for i: = ComponentCount - 1 downto 0 do try if (Components [i] is TForm) then Components [i].Free; except end; for i: = ComponentCount - 1 downto 0 do try if (Components [i] is TDataModule) then begin Components [i].Free; end; except end; end; end; end;
If by call DLL in the output agent works exception which sends FireBird (handling of stored procedures and a call in procedure)
begin exception xxx_xxx; end
at end of operation with DLL the runtime program hangs up.
Noted one singularity of behavior of the program by an exception call:
Module Load: OLEACC.dll. No Debug Info. Base Address: $6CC30000. Process XXX.exe (7884) Thread Start: Thread ID: 5796. Process XXX.exe (7884)
There is a separate flow which then at DLL_PROCESS_DETACH is not killed.
What to do in the present state of affairs?