When using structs in your DLL, in order to ensure that the data being passed between LabVIEW and the DLL is aligned correctly in memory, it may be necessary to create a wrapper DLL around the DLL you want to call.
Create a Wrapper DLL
- Create the LabVIEW cluster that you would like to pass into the DLL and wire it to the input of the Call Library Function Node. Ensure the input being connected to is set to Adapt to Type.
- The input type must be set to Adapt to Type to make the input a void pointer that you can pass any data to.
- Right-click the Call Library Function Node and select Create .c File. This will generate a .c file that contains a structure definition that you can use and is aligned to the LabVIEW’s memory.
- Call the desired DLL from within the .c file by wrapping the function and using the LabVIEW-created datatypes.
- An example of how to set this up with descriptive comments can be found installed with LabVIEW in <labview>\examples\Connectivity\Libraries and Executables\Source C Files\CLUSTERSimpleS_AWrap.c
- Compile the .c file into a DLL using an appropriate toolchain for your system, then call the wrapper function from LabVIEW.
If you have a multidimensional array of data in LabVIEW and need a one-dimensional array, you can use the Reshape Array function to change the dimension of your array. Depending on the format that the DLL expects the data to be in, whether row- or column-major, you may have to transpose the array before reshaping it. This will swap the rows for columns and change the order in which the values appear in the one-dimensional array.
Other Complex Datatypes
For more in-depth help on passing complex datatypes to and from DLLs, see External Code (DLL) Execution.vi in the LabVIEW Example Finder. It has examples on how to configure your Call Library Function Node to pass multiple complex datatypes. For example, there are examples on how to handle up to three-dimensional arrays and complex clusters. Some of these cases involve wrapping the generated DLL with custom C code as shown above.
Example C code for the DLL and requisite wrapper code are included in the <labview>\examples\Connectivity\Libraries and Executables\Source C Files directory.