Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Labview Code Interface Reference Manual.pdf
Скачиваний:
35
Добавлен:
29.05.2015
Размер:
1 Мб
Скачать
☆

Chapter 3 CIN Advanced Topics

compiler is not required. For more information on the Call Library Function, see Chapter 11, Advanced Functions, in the LabVIEW Function Reference Manual, and Chapter 24, Calling Code from Other Languages, in your LabVIEW User Manual.

Before attempting to link a dynamic link library with a CIN, you should first write a C program that calls it. The reasons for doing this are to ensure that you are calling the DLL properly, and that the DLL behaves as expected. You can test the C program using the debugging tools supplied by your compiler.

After you are sure that the DLL works and that you are calling it correctly, write the 32-bit CIN that LabVIEW can call. The main purpose of this CIN is to act as a go-between, translating LabVIEW 32bit data to 16-bit data. This CIN will take 32-bit pointers from LabVIEW and then call the DLL with the appropriate arguments.

See the Calling 16-bit DLLs section of Chapter 37, Programming Overview, in the Windows 32-bit Programming Guide section of the

Watcom C/386 User’s Guide for a detailed discussion of how to call a 16-bit DLL.

No special techniques are necessary to call a Windows 95 or Windows

NT DLL.

Calling a 16-Bit DLL

The following steps are a brief summary of how to call a 16-bit DLL from a CIN. If you are not familiar with the functions used in this example, you should refer to Microsoft Windows Programmer’s Reference or the Watcom C/386 User’s Guide.

1. Load the DLL

Load the DLL by calling the function LoadLibrary() with the name of the DLL. For example, the following code returns a handle to a specified library.

HANDLE hDLL;

hDLL = LoadLibrary("library name");

This is a standard Windows function, and is documented in the

Microsoft Windows Programmer’s Reference.

LabVIEW Code Interface Reference Manual

3-14

© National Instruments Corporation

Chapter 3 CIN Advanced Topics

Note: If you do not specify a full path, Windows searches the Windows directory, the Windows system directory, the LabVIEW directory, and the directories listed in the Path variable.

2. Get the address of the desired function

Call GetProcAddress() with the name of the function that you want to call. For example, the following code returns the address of a specified function. This address is a 16-bit pointer, and cannot be called using standard DLL call methods. Instead you have to use the Watcom C method, shown as follows.

FARPROC lpfn;

lpfn = GetProcAddress(hDLL, "function name");

As with LoadLibrary, this function is a standard Windows function, and is documented in the Microsoft Windows Programmer’s Reference.

3. Describe the function

Use GetIndirectFunctionHandle() to describe the function and the types of each parameter that it accepts. This function uses the following format.

HINDIR GetIndirectFunctionHandle(FARPROC proc

[, long param1type,long param2type,

...,] long terminator);

proc is the address of the function that was returned in step 2.

The paramXtype values should be one of the following five constants that describe the parameters for the call to the function.

INDIR_DWORD

The parameter will be a long word

 

value (a 32-bit integer).

INDIR_WORD

The parameter will be a word value (a

 

16-bit integer).

INDIR_CHAR

The parameter will be a byte value (an

 

8-bit integer).

© National Instruments Corporation

3-15

LabVIEW Code Interface Reference Manual

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