When I load a DLL dynamically it works just fine. When I load it dynamically, it generates a exception (
External :SIGSEGV) , but it still works the following way:
I run several functions in a procedure. All of them generate exceptions (or I suppose so,because I added
try....
except to each of them and
except code is executed on each of them) , but the procedure does what it should. Alas, in the end of the procedure I get an exception message and the application closes, and I cannot prevent it from doing so.
I load the DLL statically this way
unit Cbw;
{$MODE Delphi}
{$D+,S+,L+}
interface
const
...
function cbGetStatus (BoardNum:Integer; var Status:SmallInt; var CurCount:Longint; var CurIndex:Longint;FunctionType:Integer):Integer; StdCall;
function cbStopBackground (BoardNum:Integer;FunctionType:Integer):Integer; StdCall;
...
implementation
...
function cbGetStatus; external 'CBW32.DLL' name 'cbGetIOStatus';
function cbStopBackground; external 'CBW32.DLL' name 'cbStopIOBackground';
...
And I load it dynamically this way:
unit cbw_dyn;
{$MODE objfpc}
...
type
...
TcbGetStatus=function (BoardNum:Integer; var Status:SmallInt; var CurCount:Longint; var CurIndex:Longint;FunctionType:Integer):Integer; StdCall;
TcbStopBackground=function (BoardNum:Integer;FunctionType:Integer):Integer; StdCall;
...
var
DllHandle: THandle;
...
cbGetStatus:TcbGetStatus;
cbStopBackground:TcbStopBackground;
...
cbGetStatus:= TcbGetStatus(GetProcedureAddress (DLLHandle, 'cbGetStatus'));
cbStopBackground:= TcbStopBackground(GetProcedureAddress (DLLHandle, 'cbStopBackground'));
...
The loading procedure is:
function LoadMCCLib: Boolean; //True if successful
begin
if DllHandle = NilHandle then DllHandle := SafeLoadLibrary('cbw32.dll');
if DLLHandle <> NilHandle then
begin
...
cbGetStatus:= TcbGetStatus(GetProcedureAddress (DLLHandle, 'cbGetStatus'));
cbStopBackground:= TcbStopBackground(GetProcedureAddress (DLLHandle, 'cbStopBackground'));
...
end;
Am I doing something wrong?
Or at least a hint how to ignore the exception might do.