您的位置:首页 > 其它

LabVIEW中如何调用DLL

2015-09-22 22:14 381 查看

How Do I Call a Dynamic Link Library (DLL) from LabVIEW?

Hardware: PXI/CompactPCI>>Controllers

Problem: 

How do I call a DLL from LabVIEW?

Solution: 

To call a Dynamic Link Library (DLL) from LabVIEW see the help section Calling Code Written in Text-Based Programming
Languages.  The help section contains additional information not included in this document.  To call a DLL,  you first must identify what type of DLL it is.  There are essentially two types of DLL's to consider: C/C++ DLL and a Microsoft .NET assembly. 
A C/C++ DLL can be generated from C, C++, or any other programming language (besides .NET languages) such as Java, Fortran, or Visual Basic 6.0.  A .NET DLL is also called a .NET assembly or just assembly.  The reason for this terminology difference is that
a .NET DLL does not work the same way as other DLL's.  A .NET DLL uses the Common Language Runtime (CLR) and the .NET Framework to manage the functions within the DLL.

If the DLL is a C/C++ DLL:
Find the header file (*.h) or function prototype definitions.
Identify the function(s) you wish to call.  Notice whether the parameters for the function contain primitive data type parameters such as int, char, double, etc or whether they contain complex data types such as structs, arrays or vectors.
If the function does not contain any complex data types and you have a header file (*.h), a great tool in LabVIEW can help you easily import the DLL (and it will create an entire library for the DLL).  You can find this option in Tools»Import»Shared
Library (.dll)...
  Continue with the wizard.
If the function does not contain any complex data types and you do not have a header file (*.h), first ensure that you are dealing with a C/C++ DLL as most programming environments will generate a header file along with the DLL.  If you are in fact dealing
with a C/C++ DLL, find the documentation for the function as you will need to identify the parameters for the function you wish to call inside of the DLL.  Once you have identified the parameters, use the Call Library Function Node function
in LabVIEW to manually call the function.
If the function(s) you wish to call contains complex data types, you need to manually use a Call Library Function Node function in LabVIEW to directly call the DLL, defining the prototype within the configuration dialog (if the DLL has
been compiled with a Type Library, parameter data and return types will be defined automatically).  Note that if your complex data type is a struct with more than primitive data types (int, double, char), it is easiest to create a wrapper DLL from a C-based
language.  

Since C/C++ constructs do not always directly correlate to LabVIEW data types, a wrapper DLL can appropriately extract the contents of the complex structure and translate them to primitive terms.  For instance, if you have a struct in C which contains a char
* (a string or character array), you can create a wrapper function which LabVIEW will call that takes in a char * type directly, puts that into a structure, and then in turn calls the DLL.  Note that if you have the DLL source code, you can directly modify
the DLL so that it takes in a char * instead of the struct.
Note: There is a very helpful example in the Labview Example finder that explains how to handle several different data types to be used with the Call Library Function Node. The example is named Call DLL.vi.
Refer to this example when dealing with complex data types such as arrays or structs. To Find this example go to the LabVIEW Example Finder (Help»Find Examples) and select the Directory Structure radio button. In the directories
list, select dll and then data passing then Call Native Code.llb. The Call DLL.vi example is under that directory.  

To view the example for a data type, select the data type in the Data Type list.  Then 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  LabVIEW DLL