Controlling an Instrument That Requires DLL Functions That Use Pointers to Complex Data Structures

Updated Jul 25, 2018

Reported In

Software

  • LabVIEW

Issue Details

I want to use LabVIEW to control my instrument that requires DLL functions that use pointers to complex data structures (e.g. Smartbits by NetCom).

Solution

The DLLs for the instrument require pointers to complex data structures to be passed in through the Call Library Function Node. You can use LabVIEW clusters to represent each data structure and then type cast them to byte arrays and pass them in the array data pointer. This will work as long as the data structures contain "flat" data (no arrays or strings). In cases where the data structure includes an array of a specific size, use an embedded cluster containing the specific number of elements. (see attached ETHTransmit.llb inside Commlib.zip). 
There is a problem, however, with a data structure that includes a variable sized array. The data structure may be declared as follows for instance: 

typedef struct { int Configuration; int Range; int Offset; int* Data; int DataCount; } HTVFDStructure; 

The challenge is to create a cluster that contains the address of the array (int* Data). DLLs are typically written for C programmers, and they do not usually know how to deal with LabVIEW array handles (so you can't simply place an array in the cluster and pass the cluster directly into the Call Library Function using Adapt to Type). You must write a 'wrapper' DLL for the call to your specific function. You can either pass the structure from LabVIEW as a cluster handle and manipulate it before sending it to the 3rd party DLL, or you can pass the individual elements out of LabVIEW and build the necessary structure in the wrapper DLL before calling the 3rd party DLL. For this instance, the included LabVIEW and CVI files illustrate how this is done in mydll.zip.

WAS THIS ARTICLE HELPFUL?

Not Helpful