To download NI software, including the products shown below, visit ni.com/downloads.
This example illustrates the concept of sharing LabVIEW code by building a shared library (DLL). Specifically, this example demonstrates that you can reuse LabVIEW code when your main program is written in C. Using this capability, new features and functionality that you create using LabVIEW can easily be added to existing legacy C code. Included in this example are C and LabWindows/CVI applications that acquire, analyze, and present data by calling LabVIEW-built DLLs.
Complete the following steps to run the C code.
Also included in this example is the LabVIEW source code for the DLL and the LabVIEW Project used to create it. More details comparing C and LabVIEW's functionality appear in the "Additional Information" section below.
Note: When running the application from Microsoft Visual C++ 2008, you must include the directory containing the LabVIEW support files in the "directories" section of the environment. From the VC++ environment, select Tools»Options. Expand the Projects and Solutions section and select VC++ Directories. Select “Include files” in the “Show directories for:” drop down and add the \Program Files\National Instruments\LabVIEW 8.5\cintools directory to the list (replace 8.5 in this file path with your LabVIEW version). This will prevent you from receiving the "Cannot find extcode.h" error.
Requirements:
Description-Separate-2
If you have existing code in C and need to reuse it in LabVIEW, one technique is to build the code as a DLL and call it using the Call Library Function Node. In fact, based on the architecture of your C application, you could take advantage of the simpler approach to parallel programming offered by LabVIEW to run two or more existing C routines in parallel without the additional complexity of C-based multithreaded programming.
In this example, linked below, the GenAndSortC VI is identical to the VI from Example 1, with the exception that the random number generation and sorting are not implemented in LabVIEW. These operations are carried out by calling a DLL built in C. The DLL is named GenSort.dll and the functions that LabVIEW calls are named generateRand() and bubbleSort(). Figure 29 shows the LabVIEW code that calls the generateRand() function from a Call Library Function Node and Figure 30 shows the C code that actually generates the random numbers.
To call a DLL from LabVIEW, place a Call Library Function Node on the block diagram and double-click to display the Call Library Function dialog box. Browse for your DLL and then choose your function name from the drop-down list. You can then add parameters, choose their data types, and choose whether to pass by value or reference. Figure 31 shows the Call Library Function dialog box, which can be used to configure DLL function calls. This example is designed to show the power and ease of calling a DLL in LabVIEW, but it is in no way designed to be a full tutorial. For more information on using DLLs and other third party code 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 Fundamentals»Calling Code Written in Text-Based Programming Languages book in the LabVIEW Help (linked below) for more information.
Additional-Separate-2
Related-Separate-2
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.