LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Call a Borland Delphi DLL with Structs from LabView

Hello,

I have a problem to build an equivalent Struct in Labview to the following Struct which I want to retrieve from a DLL.

type
TM2DScanline=record
YWert:double;
XWert:array[0..raster] of double;
ZWert:array[0..raster] of double;
IWert:array[0..raster] of byte;
end;
M2DScanArea =array[0..maxScans] of TM2DScanline;
PointerToScanArea=^M2DScanArea;

PointerToScanArea is the parameter I want to retrieve.

If anybody knows a way for doing this, help would be very appreciated

Thanks

Peter
0 Kudos
Message 1 of 2
(3,667 Views)
Are raster and maxScans both constant? If I recall correctly, many dialects of Pascal just lay the elements of a fixed-size array out in memory with no size parameter; if this is the case with Delphi, then you may be able to do the following (in my example, I'll assume "raster" is a constant set to 40, and maxScans is a constant set to 5):


  1. Create a cluster called XWert with 40 Numeric elements (representation: DBL).
  2. Copy XWert and name the copy ZWert.
  3. Create a cluster called IWert with 40 Numeric elements (representation: U8).
  4. Create a cluster called TM2DScanline.
  5. Create a Numeric inside TM2DScanline called YWert (representation: DBL).
  6. Drag XWert, then ZWert, then IWert into TMD2Scanline.
  7. Create a cluster called ScanArea and drag 5 copies of TMD2Scanline into it.
  8. Create a Call Library node on your block diagram, give it your DLL and function name, and set the return value to whatever your Delphi function returns. You probably want the WINAPI calling convention.
  9. Add a parameter and make it "Adapt to Type: Pointers to Handles". Close the node and wire the ScanArea cluster to the input.
  10. Right-click on the Call Library Node and select "Create .c file...." Read through the C file to make sure its structure is similar to your Delphi record: you should see five copies of the TM2DScanline structure, each of which contains a double followed by two fixed 40-element structures of double and a fixed 40-element structure of unsigned char. You should see no reference to the word "Hdl" anywhere in the code.


This strategy will only work if the arrays in your records are fixed at a constant size, and if Delphi lays out the arrays in memory as described above. Instead of doing all this work, you may want to write a small C or Pascal wrapper around your Delphi function. This wrapper could take simpler parameter types (which are easier to use from LabVIEW) and bundle them into the cluster before calling your Delphi function.
Message 2 of 2
(3,667 Views)