LabVIEW中如何调用DLL

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:
  1. Find the header file (*.h) or function prototype definitions.
  2. 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.
  3. 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.
  4. 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.
  5. 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 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值