[원문] http://zone.ni.com/devzone/cda/tut/p/id/3927

LabVIEW 6i can create DLLs that can be used in other programming environments. This document demonstrates how to use Microsoft Visual C++ to call a simple function in a DLL that was generated by LabVIEW 6i. The first two steps in this process are to create the VI and then create a DLL from LabVIEW 6i. The document linked at the bottom of the page shows how this is done.

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.


[+] 크게 보기

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.


[+] 크게 보기

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.



[+] 크게 보기

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.


[+] 크게 보기

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.


[+] 크게 보기


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


[+] 크게 보기

10. You can now compile and build the executable.


[+] 크게 보기


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.



[+] 크게 보기


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.


[+] 크게 보기



-The link shows how the DLL called in this Microsoft Visual C++ example was created in LabVIEW 6i.

+ Recent posts