How Do I Use "Adapt To Type" For Call Library Function Nodes?

Updated Aug 31, 2023

Environment

Software

  • LabVIEW

Other

Primary Software: LabVIEW Development Systems>>LabVIEW Full Development System 6.1
 

What does Adapt to Type do in the context of a Call Library Function Node? How do I use it?

Adapt to Type allows you to pass complex data structures such as clusters (structures in C) into DLLs. You can only use Adapt to Type with function arguments. You cannot use it with return type - only strings and numeric data types can be set as return types.
To use Adapt to Type:
  1. Place a Call Library Function Node on your block diagram.
  2. Right-click the Call Library Function Node and select Configure.
  3. Select the appropriate DLL and function you wish to use - this step can be skipped if you are simply inquiring into which C data types to use.
  4. Click Add a Parameter After.
  5. For the Type, select Adapt to Type.
  6. On your block diagram, you can now wire a cluster into an input terminal of your Call Library Function Node as shown below.



When passing complex data types to C, LabVIEW has a built-in feature that automatically generates the function prototype and structure definitions for you. After you wire your cluster into a Call Library Function Node, right-click the Call Library Function Node and select Create .c File. Save this file. You can now view this .c file in your C/C++ IDE or with Notepad. The example generates the following C code:
/* Call Library Source File */
  
#include "extcode.h"
  
/* Typedefs */
typedef struct {
	int32 dimSize;
	int32 elt[1];
	} TD2;
typedef TD2 **TD2Hdl;
  
typedef struct {
	int32 Numeric;
	TD2Hdl Array;
	int32 Numeric2;
	} TD1;
  
void funcName(TD1 *arg1);
  
void funcName(TD1 *arg1)
{
  
	/* Insert Code Here */
  
}

This code creates the appropriate data types that you must use to interface your LabVIEW cluster with a C/C++ structure. When building your DLL, you must include extcode.h , fundtypes.h, and platdefines.h in your C/C++ project. These header files are located in the C:\Program Files\National Instruments\LabVIEW 6.1\cintools directory. You can access individual elements of your LabVIEW cluster using the following syntax:
arg1->Numeric = 5;

One thing to remember, LabVIEW is passing handles to your DLL - a handle is a pointer to a pointer.

For more information in LabVIEW 7.1 or earlier, refer to the Using External Code in LabVIEW manual (linked below). In LabVIEW 8.0 or later, refer to the Configuring the Call Library Function Node topic in the LabVIEW Help (linked below) for more information.