LabVIEW中如何调用DLL
2015-09-22 22:14
381 查看
How Do I Call a Dynamic Link Library (DLL) from LabVIEW?
Hardware: PXI/CompactPCI>>ControllersHow 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
相关文章推荐
- FREEBASIC 编译可被python调用的dll函数示例
- DLL(Dynamic Linkable Library) 详解说明
- delphi中一个值得大家来考虑的DLL问题
- 将ocx文件转换成C#程序引用的DLL文件的办法
- C++与C#互调dll的实现步骤
- C++调用C#的DLL实现方法
- 自己写的文件操作的function和Sub vb.net dll
- C# 调用C++写的dll的实现方法
- 使用 JScript 创建 .exe 或 .dll 文件的方法
- c#中xml文档注释编译dll引用到其它项目示例
- .dll 文件反编译的工具软件集合
- C#调用C++版本dll时的类型转换需要注意的问题小结
- java使用JNA(Java Native Access)调用dll的方法
- Python 调用DLL操作抄表机
- C#调用Matlab生成的dll方法的详细说明
- C#将dll打包到程序中的具体实现
- VC程序在Win32环境下动态链接库(DLL)编程原理
- Lua5.1中加载dll动态链接库的方法
- C#生成DLL文件的方法