So, as the title says, I\'m in a struggle with translating a few functions for calling DLL, which I have documentation about in C, but I need to use it in Delphi.
After
It would be more useful to see the DLL's actual .h
file instead of documentation, as documentation tends to not mention what the calling conventions actually are (and this case is no exception). You are declaring your Delphi functions as stdcall
, which may or may not be correct. cdecl
is another commonly used calling convention in DLLs, especially since it is C's default calling convention. So, if the functions are not declared with ANY explicit calling convention in the .h
file, assume cdecl
instead of stdcall
. For this discussion, I will assume cdecl
unless shown otherwise.
int SetAnalogChannels(int CH1Gain, int CH2Gain, bool CH1Couple, bool CH2Couple, bool CH1Multiplier, bool CH2Multiplier)
function SetAnalogChannels(CH1Gain, CH2Gain: Integer; CH1Couple, CH2Couple, CH1Multiplier, CH2Multiplier: Boolean): Integer; cdecl; external 'E_l80.dll';
long RetrieveDSOData(unsigned char whatchannels, double *DSOCH1, double *DSOCH2, unsigned short *LADATA, unsigned char Nth_Sample)
As the documentation says, these are pointers to arrays. I would translate them as-is, don't try to convert them to any fancy Delphi syntax:
function RetrieveDSOData(whatchannels: Byte; DSOCH1, DSOCH2: PDouble; LADATA: PWord; Nth_Sample: Byte): longint; cdecl; external 'E_l80.dll';
float SetUPPS1(float Voltage)
You converted this to Extended
, which is wrong. Delphi's Single
is equivalent to C's float
:
function SetUPPS1(Voltage: Single): Single; cdecl; external 'E_l80.dll';
long SetupAWG(double *AnalogVoltage, short *DigitalData, long BufferSize, double DCOffsetVoltage, double SampleFrequency, long Use4xGain, double OutputImpedance, long Repeat,long Triggered, long OverrideOtherClocks)
Same as above for the arrays:
function SetupAWG(AnalogVoltage: PDouble; DigitalData: PShort; BufferSize: Longint; DCOffsetVoltage, SampleFrequency: Double; Use4xGain: Longint; OutputImpedance: Double; Repeat, Triggered, OverrideOtherClocks: Longint): longint; external 'E_l80.dll';