The attached sample DLL, PassingDataSampleDLL.dll, contains multiple functions including the following which we will use for this tutorial: int PassingParameters_Integer (int x, int y) This function returns the sum of the two numbers, x and y, that are passed as parameters.
Open a new VI
Switch to the block diagram (Window » Show Block Diagram)
Drop in a Call Library Function Node (Functions Palette » Connectivity » Libraries & Executables » Call Library Function Node)
Open the Configuration dialog for the Call Library Function Node (Right-click on the Call Library Function Node and click Configure… or double click on the Call Library Function Node)
On the Function tab, click the Browse button next to the Library name or path and browse to the sample DLL, PassingDataSampleDLL.dll.
This will populate the Function name dropdown box with the functions available in this DLL.
Select the PassingParameters_Integer function from the Function name dropdown box.
Your Function tab should look as follows. Note that the function prototype does not match what our function actually accepts. We will fix this in the next couple of steps.
Switch over to the Parameters tab
This function returns an integer (the sum), so set the return type to an Int32:
Select return type from the parameter list on the left
In the Current parameter section, pick Numeric from the Type dropdown box
Leave the data type as the default – Signed 32-bit Integer
This function takes in two integers as parameters, so add these as inputs:
Click the Insert button to add a new parameter
This will create a new parameter called arg1 that defaults to an Int32 passed by value. This is exactly what we want to leave the defaults. Note: You can rename the argument name if you would like, this will not affect the way the DLL is called.
Repeat step 11.a to add another parameter, leave the defaults for this argument as well
Your Parameters tab should look as follows. Note that the function prototype now matches the actual prototype of our function in the DLL.
Click OK to close the configuration dialog
Set up the front panel inputs and outputs for the Call Library Function Node
Select the Call Library Function Node
Click Ctrl+Space to bring up the Quick Drop menu
Click Ctrl+D to automatically create controls and indicators for the inputs and outputs of the node
Switch to the Front Panel (Window » Show Front Panel)
Change the values for the controls arg1 and arg2, and click the Run button.
Notice that the indicator return type 2 updates with the value returned from the DLL function, the sum of arg1 and arg2. (Your front panel may appear different)
Conclusion / Next Steps
You have learned how to call a C/C++ function in a DLL from LabVIEW using the Call Library Function Node. You can call more advanced functions as well using the Call Library Function Node by varying the options in the Call Library Function Node’s configuration dialog.