Developer Center Resources

cancel
Showing results for 
Search instead for 
Did you mean: 

Tutorial: Configuring the Call Library Function Node to call a Simple DLL

» Calling External Code » Calling C/C++ DLLs » Call Library Function Node

Overview

This tutorial walks you through the process of dropping and configuring a Call Library Function Node to call a simple C/C++ DLL from LabVIEW.

For more details on the options in the Call Library Function Node configuration dialog, refer to:
LabVIEW Help: Configuring the Call Library Function Node

Example DLL

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.

Tutorial

  1. Open a new VI

  2. Switch to the block diagram
    (Window » Show Block Diagram)

  3. Drop in a Call Library Function Node
    (Functions Palette » Connectivity » Libraries & Executables » Call Library Function Node)

  4. 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)


    CallLibraryFunctionNode.png
    1. On the Function tab, click the Browse button next to the Library name or path and browse to the sample DLL, PassingDataSampleDLL.dll.

    2. This will populate the Function name dropdown box with the functions available in this DLL.

    3. Select the PassingParameters_Integer function from the Function name dropdown box.

    4. 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.


      FunctionTab.png
    5. Switch over to the Parameters tab


      ParametersTabEmpty.png
    6. This function returns an integer (the sum), so set the return type to an Int32:

      1. Select return type from the parameter list on the left

      2. In the Current parameter section, pick Numeric from the Type dropdown box

      3. Leave the data type as the default – Signed 32-bit Integer

    7. This function takes in two integers as parameters, so add these as inputs:

      1. Click the Insert button to add a new parameter

      2. 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.

      3. Repeat step 11.a to add another parameter, leave the defaults for this argument as well

    8. Your Parameters tab should look as follows. Note that the function prototype now matches the actual prototype of our function in the DLL.


      ParametersTab.png
    9. Click OK to close the configuration dialog

    10. Set up the front panel inputs and outputs for the Call Library Function Node

      1. Select the Call Library Function Node

      2. Click Ctrl+Space to bring up the Quick Drop menu

      3. Click Ctrl+D to automatically create controls and indicators for the inputs and outputs of the node

    11. Switch to the Front Panel
      (Window » Show Front Panel)

    12. Change the values for the controls arg1 and arg2, and click the Run button.

    13. 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)


      FrontPanel.png

    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.

    The Import Shared Library Wizard can automate a lot of the effort involved in calling C/C++ DLLs by creating wrapper VIs with configured Call Library Function Nodes that you can call from your VIs.
    Tutorial: Creating Wrapper VIs for C/C++ DLL functions using the Import Shared Library Wizard

    For examples on how to configure the Call Library Function Node to handle more complex datatypes, refer to:
    Calling C/C++ DLLs Containing Simple and Complex Datatypes from LabVIEW

    Attachments

    CallingSimpleDLL.vi
    PassingDataSampleDLL.dll

    Jervin Justin
    NI TestStand Product Manager
    Comments
    Member kenniscourant
    Member

    After step 5 I get the following error:

    The library selected is not valid for the current platform. For example, you are running 64-bit LabVIEW and the library might be a 32-bit library.

     

    I am indeed running a 64-bit LabVIEW. Is there also a 64-bit version of the sample DLL 'PassingDataSampleDLL.dll' or does there exists a workaround?

    Knight of NI Knight of NI
    Knight of NI

    Nothing prevents you from also installing LabVIEW 32bit and use that. I guess that's a "workaround". Smiley Very Happy

    (Of course somebody having the source code of the dll could compile it for 64bit.)

     

    Is there any particular reason you absolutely need 64bit? 


    LabVIEW Champion Do more with less code and in less time
    Contributors