Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Using External Code in LabVIEW.pdf
Скачиваний:
49
Добавлен:
29.05.2015
Размер:
1.85 Mб
Скачать

Chapter 2 Shared Libraries (DLLs)

When you use a C++ compiler, you export functions with the extern "C"{} statement in your header file in order to prevent name mangling.

For a DLL that you have written, you never recompile the DLL while the DLL is loaded into memory by another application, for example, by your VI. Before recompiling a DLL, make sure that all applications making use of the DLL are unloaded from memory. This ensures that the DLL itself is not loaded into memory during a recompile. The DLL might fail to rebuild correctly if you forget this point and your compiler does not warn you.

You tested the DLL with another program to ensure that the function (and the DLL) behave correctly. Testing it with the debugger of your compiler or a simple C program in which you can call a function in a DLL will help you identify whether possible difficulties are inherent to the DLL or are related to LabVIEW.

Module Definition Files

In the Building a Shared Library (DLL) section, you configure LabVIEW to use the C calling convention in the .c source file you build with the LabVIEW Call Library Function. In contrast, you use the __stdcall calling convention when you call the Win32 API. When you build a shared library (DLL) with __stdcall, you normally use a module definition (.def) file to export the functions in your DLL. In the absence of a .def file, __stdcall might truncate function names in an unpredictable pattern, so the actual function name would be unavailable to applications that call the DLL.

You can associate a module definition (.def) file with a DLL. The .def file contains the statements for defining a DLL, such as the name of the DLL and the functions that it exports, as shown in the following example.

LIBRARY myshared

EXPORTS

avg_num

The preceding code example demonstrates key requirements for .def files:

The only mandatory entries in the .def files are the LIBRARY statement and the EXPORT statement.

The LIBRARY statement must be the first statement in the file.

© National Instruments Corporation

2-29

Using External Code in LabVIEW

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]