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

Chapter 2 Shared Libraries (DLLs)

t e x t \00

string data

NULL

Character

Figure 2-11. The C String Format

When you pass string data to a DLL, you must follow the same guidelines as for arrays:

Never resize a string, concatenate a string, or perform operations that may increase the length of string data passed from LabVIEW if you are using the C or Pascal string pointers.

If you must return data as a string, you should first allocate a string of the appropriate length in LabVIEW, and pass this string into the DLL to act as a buffer.

If you pass a LabVIEW String Handle from Call Library Function to the DLL, then you can use the LabVIEW CIN functions like DSSetHandleSize to resize the LabVIEW string handle.

Note To use the LabVIEW CIN function calls you must add labview.lib to a Visual C++ project, labview.export.stub to a CodeWarrior project, and labview.sym.lib to a Symantec project.

Array and String Tip

When you are not passing LabVIEW handles and your DLL function must create an array, change its size, or resize a string of data, you should break the function into two steps:

1.Determine the number of elements that the array requires, or the length of the string to be returned. Have this first function return the desired size to LabVIEW.

2.In LabVIEW, initialize an array or string with default values, and pass this array to a second function in your DLL, which actually places the data into the array. If you are working with string-based instrument control, it may be easier to pass an array of 8-bit integers than C strings because of the possibility of having NULL values in the string.

When you are passing a LabVIEW Array Handle or LabVIEW String Handle from the Call Library Function object to your DLL, you can use the LabVIEW CIN functions to resize or create an array or string. Refer to the Required Libraries section for more information about this set of functions.

© National Instruments Corporation

2-33

Using External Code in LabVIEW

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