1. Open up a new Visual C++ project by selecting File>>Menu and then selecting the Projects tab. Select the Win32 Console Application and enter a project name and location for it to be stored.

[+] Enlarge Image
2. Open up a new Visual C++ Source File by selecting File>>Menu and then selecting the Files tab. Select the C++ Source File and enter a file name and location for it to be stored.

[+] Enlarge Image
3. Type the source code as shown below. Make sure to include the header file that was created by LabVIEW (Convert_Temp.h). Remember that the function prototype for the DLL that you created was “float64 F_to_C(float64 DegF, float64 *DegC). This code simply calls the temperature conversion VI (F_to_C) and then prints the input (F), output (C), and return (ret) value. Notice that the address of the output (C) must be passed to the function, since it was defined as a Pointer to a Value.

[+] Enlarge Image
4. Now add the header file that was created by LabVIEW (Convert_Temp.h) to your project. Select Project>>Add To Project>>Files as shown below.

[+] Enlarge Image
5. Select the header file and click OK.

6. Repeat Steps 4 & 5 for the library file (Convert_Temp.lib).

7. Make sure the compiler knows where to locate the header file you added in steps 4 and 5. To let the compiler know where to look for this file, select Tools>>Options from the menu bar.

[+] Enlarge Image
8. Select the Directories tab and select Include files in the Show directories for field. If the path where the header file is located is not listed, add it by clicking the dotted box above the Directories box. The header file that was created by LabVIEW references another header file called extcode.h. This header file contains LabVIEW defined datatypes that you need to call the DLL. It is generally located in the LabVIEW file under cintools, as shown below.

9. Your DLL must be in the same folder as the project, so in this case you must move Convert_Temp.dll from C:\TEMP\app\ to C:\TEMP\FtoC\.

[+] Enlarge Image
10. You can now compile and build the executable.

[+] Enlarge Image
11. Troubleshooting
If you get the following error when you compile, add the path to the header file. See steps 7 & 8.
c:\temp\ftoc\deg.c(2) : fatal error C1083: Cannot open include file: 'Convert_Temp.h': No such file or directory
Error executing cl.exe.
If you get the following error when you try to run the executable, the DLL file is probably not in the same directory as your project. See step 9.

12. Run the executable.

[+] Enlarge Image
13. Notice that the 75 degrees Fahrenheit was converted to 23.9 degrees Celsius. Also, notice that the return value is equal to 23.9. This is because you set the return value equal to DegC when the DLL was built in LabVIEW.

[+] Enlarge Image
-The link shows how the DLL called in this Microsoft Visual C++ example was created in LabVIEW 6i.
Related Links:
Creating DLLs Using LabVIEW 6i
Reader Comments | Submit a comment »
Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).
