I am trying to update some DLL definitions from a .h file for C.
The source in the C is :
int EXTCCONV cbGetDaqDeviceInventory(INT32 InterfaceType, DaqDeviceDescriptor* Inventory, INT* NumberOfDevices);
...
typedef struct
{
CHAR ProductName[64];
UINT ProductID; // product ID
DaqDeviceInterface Int32; // USB, BLUETOOTH, ...
CHAR DevString[64];
CHAR UniqueID[64]; // unique identifier for device. Serial number for USB deivces and MAC address for bth and net devices
ULONGLONG NUID; // numeric representation of uniqueID
CHAR Reserved[512]; // reserved for the future.
} DaqDeviceDescriptor;
I did it the following way in Lazarus (attached in file
MCCULDynBind.pas):
type
...
pdaqDeviceDescriptor = ^daqDeviceDescriptor;
...
daqDeviceDescriptor = record
ProductName : array [0..63] of char;
ProductID : UInt32;
InterfaceType: Int32; //USB_IFC= 1; BLUETOOTH_IFC = 2; ETHERNET_IFC = 4; ANY_IFC = 7;
DevString: array [0..63] of char;
UniqueId: array [0..63] of char;
NUID: UInt64;
Reserved: array [0..511] of char;
end;
...
TcbGetDaqDeviceInventory = function (InterfaceType : integer; var Invertory: PdaqDeviceDescriptor; var NumberOfDevices : Integer) : Longint; StdCall;
...
var
...
cbGetDaqDeviceInventory : TcbGetDaqDeviceInventory;
...
implementation
...
function LoadMCCLib: Boolean; //True if successful
begin
if DllHandle = NilHandle then DllHandle := SafeLoadLibrary(libname);
if DLLHandle <> NilHandle then
begin
...
cbGetDaqDeviceInventory := TcbGetDaqDeviceInventory (GetProcedureAddress (DLLHandle, 'cbGetDaqDeviceInventory'));
...
end;
I call the function the following way:
procedure TForm1.Button1Click(Sender: TObject);
var
ULStat : integer = 0;
i : integer = 0;
ProductName : string = '';
ProductID : UInt32;
Inventory : ^DaqDeviceDescriptor;
NumberOfDevices : Integer = -1;
begin
cbErrHandling(PRINTALL, STOPALL);
//ULval := cbIgnoreInstaCal;
//SetLength (Inventory,100);
ULStat := cbGetDaqDeviceInventory(7,Inventory,NumberOfDevices);
ProductName := Inventory[0].ProductName;
ProductID := Inventory[0].ProductID;
ShowMessage(IntToStr (i) + '; ' + IntToStr(ULStat) + '; ' + IntToStr (NumberOfDevices ));
end;
A sample app in C works (solution attached), but it does not work in Lazarus -sometimes it crashes, sometimes it returns a correct value in NumberOfDevices, but DaqDeviceDescriptor contains no data or shit.
ULStat becomes 154 (BADBUFFERSIZE (Buffer is too small for operation)).
The function shall return an array of DaqDeviceDescriptor, but the definition in the C header is not for an array, which really confuses me.
I have little hope that someone could help, because a device is used to debug, but anyway...