I have problems with a dynamically linked DLL.
Static bindings are:
function DAQmxGetTaskNumChans(taskHandle:Longint; data:PLongint):Longint; stdcall;
Dynamic bindings are:
type
tDAQmxGetTaskNumChans=function (taskHandle:Longint; data:PLongint):Longint; stdcall;
var
DAQmxSetDIDigFltrMinPulseWidth:tDAQmxSetDIDigFltrMinPulseWidth;
implementation
function LoadNIDAQMXLib: Boolean; //True if successful
begin
if DllHandle = 0 then DllHandle := LoadLibrary('nicaiu.dll');
if DLLHandle <> NilHandle then
begin
DAQmxGetTaskNumChans:=tDAQmxGetTaskNumChans(GetProcedureAddress (DLLHandle, 'DAQmxGetTaskNumChans'));...
end;
Here is the program (procedure), which runs okay with static bindings:
procedure TForm1.Button1Click(Sender: TObject);
var
DAQmxError: integer;
ChannelCount: integer;
SampsPerChannel: integer=5000;
RefreshRate: Integer= 5000;
SamplesCount: integer;
SampsPerChanRead: LongInt;
i,j,k: integer;
LineSeries: array of TLineSeries;
Timeout: Double;
TriggerTimeout:Double =30; //seconds
scount: integer;
begin
TimeOut:=(SampsPerChanRead/RefreshRate)+TriggerTimeout;
DAQmxError:= DAQmxCreateTask ('',@TaskHandle);
if DAQmxError <> 0 then begin Label1.Caption := 'Error №' + IntToStr (DAQmxError); exit; end else Label1.Caption:= 'No error';
DAQmxError:= DAQmxCreateAIVoltageChan (TaskHandle, 'Dev1/ai4:7','',DAQmx_Val_InputTermCfg_NRSE, -10,10,DAQmx_Val_VoltageUnits1_Volts,'');
if DAQmxError <> 0 then begin Label1.Caption := 'Error №' + IntToStr (DAQmxError); exit; end else Label1.Caption:= 'No error';
DAQmxError:=DAQmxCfgSampClkTiming(taskHandle, 'OnboardClock', RefreshRate, DAQmx_Val_Rising, DAQmx_Val_AcquisitionType_FiniteSamps, SampsPerChannel);
if DAQmxError <> 0 then begin Label1.Caption := 'Error №' + IntToStr (DAQmxError); exit; end else Label1.Caption:= 'No error';
DAQmxError:= DAQmxGetTaskNumChans(taskHandle, @ChannelCount);
if DAQmxError <> 0 then begin Label1.Caption := 'Error №' + IntToStr (DAQmxError); exit; end else Label1.Caption:= 'No error';
SamplesCount:= SampsPerChannel * ChannelCount ;
SetLength(DAQData,SamplesCount);
...
end;
Running the app with the dynamically bound libs causes a SIGSEGV exception.
If I comment SetLength(DAQData,SamplesCount); no exception occurs.
So, hopefully s.o. will show me the mistake?
I guess soemethings goes wrong with