Sie sind auf Seite 1von 4

Calling a DLL from Microsoft Visual Basic That Was Generated By LabVIEW 6i

Publish Date: Dec 06, 2006


LabVIEW can create DLLs that can be used in other programming environments. This document demonstrates how to use Visual Basic
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. The document linked at the bottom of the page shows how this is done.
1. Open a new project for Visual Basic by selecting File>>New Project.
2. Select the Standard EXE project and click OK.
3. Write the following code, which corresponds to the object front panel.
Note: To view the top line in full, see Step 5.
[+] Enlarge Image
4. The boxes that contain the degrees F and degrees C are Textboxes, and the Start and Quit buttons are CommandButtons. Create
them by double-clicking their respective symbols in the left front panel.
5. The top line of the code is the most critical to successfully calling the LabVIEW DLL that you created. The line in its entirety reads as
follows:
Private Declare Sub DegFtoDegC Lib "C:\Temp\app\Convert_Temp.dll" Alias "F_to_C" (ByVal degF As Double, ByRef degC As Double)
-DegFtoDegC is the name that you use to call your function from the Visual Basic code, which is demonstrated above. Call
DegFtoDegC(DegreeF, DegreeC)
-"C:\Temp\app\Convert_Temp.dll" is the location of the DLL that you created using LabVIEW. Recall that you set this up as the
destination directory. (See below)

-"F_to_C" is the Alias name of your function. This Alias name corresponds to the function name that was on the Define VI Prototype front
panel when you created the DLL in LabVIEW.
-(ByVal degF As Double, ByRef degC As Double) As Double defines the parameters that correspond to the function that you are calling
from the DLL. Recall that your function prototype was "float64 (float64 DegF, float64 *DegC) (see above). Therefore, degF is specified
as being passed by value (ByVal) since it is defined as a float64 value in your function prototype. DegC is specified as being passed by
reference (ByRef) since it is defined as a pointer to a value in your function prototype. Remember you can also return a value, so in this
case the Celsius temperature is returned from the function as a float64 or Double.
Note: The variable names in your declaration of the function in Visual Basic are simply place holders, so they do not have to match the
names in the function prototype. However, they must be the same type.
6. The main code for the Visual Basic program reads as follows:
Private Sub Start_Click()
Dim DegreeF As Double
Dim DegreeC As Double
Dim ret As Double
DegreeF = FTextBox.Text
ret = DegFtoDegC(DegreeF, DegreeC)
CTextBox.Text = DegreeC
End Sub
Private Sub Quit_Click()
End
End Sub
-This simply defines two Double variables and places the value that is in the FTextBox in the DegreeF input variable. It calls the function
that places the Celsius temperature in the DegreeC output variable that corresponds to the Fahrenheit temperature in the DegreeF
input variable. It also returns the Celsius temperature into the variable "ret". Then the Celsius output temperature is placed in the
CTextBox. It repeats this process each time you press the Start button. The program ends when you press the Quit button. The final
object front panel looks like the following illustration when the program runs:
Hot Deals!
<
Powered by HulaToo
Djeco Jewels from the
Islands
Rs. 1,124
Djeco
JG Shoppe DLL
executive Medium...
Rs. 1,042
JG Shoppe
B
e
s
t

D
e
a
l
Microsoft Small
Business Premi...
Rs. 12,999
Microsoft
Microsoft Wired
Controller For...
Rs. 2,299
Microsoft

Related Searches
Embedded Software
Development
Embedded Software
National Instruments
Online Bachelor
Degree
Easy Appetizer
Recipes
Free Foreclosure
Listings
Best Cell Phone
NI LabVIEW
Embedded Systems
Programming
Hardware Drivers
?
Hul aToo
H
u
l
a
T
o
o

A
d
s
Trust Rating
94
%
ni .com
H
u
l
a
T
o
o

A
d
s
-The link below shows how the DLL called in this Microsoft Visual Basic example was created in LabVIEW 6i.
Related Links:
Creating DLLs Using LabVIEW 6i

Das könnte Ihnen auch gefallen