
- •Worldwide Technical Support and Product Information
- •National Instruments Corporate Headquarters
- •Worldwide Offices
- •Important Information
- •Warranty
- •Copyright
- •Trademarks
- •WARNING REGARDING USE OF NATIONAL INSTRUMENTS PRODUCTS
- •Contents
- •About This Manual
- •Conventions
- •Related Documentation
- •Calling Code in Various Platforms
- •Characteristics of the Two Calling Approaches
- •Details of Call Library Function
- •Details of a CIN
- •Calling Shared Libraries
- •Figure 2-1. Call Library Function Dialog Box
- •Calling Conventions (Windows)
- •Parameters
- •Calling Functions That Expect Other Data Types
- •Building a Shared Library (DLL)
- •Task 1: Build the Function Prototype in LabVIEW
- •Task 2: Complete the .c File
- •Required Libraries
- •Task 3: Build a Library Project in an External IDE
- •Figure 2-2. Creating a Project in Visual C++
- •Figure 2-3. Setting the Use run-time library control, Microsoft Visual C++
- •Gnu C or C++ Compilers on Solaris, Linux, or HP-UX
- •Metrowerks CodeWarrior on Power Macintosh
- •Calling External APIs
- •Common Pitfalls with the Call Library Function
- •Incorrect Function Name
- •Data Types
- •Constants
- •Calling Conventions
- •Example 1: Call a Shared Library that You Built
- •Configuration of Call Library Function
- •Create Front Panel
- •Create the Block Diagram
- •Example 2: Call a Hardware Driver API
- •Figure 2-4. VI That Calls Hardware
- •Example 3: Call the Win32 API
- •Table 2-1. Mapping Win32 Data Types to Standard C Data Types
- •Table 2-2. Mapping Win32 Data Types to LabVIEW Data Types
- •Constants
- •Table 2-3. Selected Constants for MessageBox
- •Figure 2-5. Combining Function Constants in LabVIEW
- •Determining the Proper Library and Function Name
- •Unicode Versions and ANSI Versions of Functions
- •Configuring a Call to the Win32 API
- •Figure 2-6. Configuring Call Library Function to call the Win32 API
- •Figure 2-7. Block Diagram for a Call to the Win32 API
- •Figure 2-8. Running a LabVIEW Call to the Win32 API
- •Additional Examples of LabVIEW Calls to DLLs
- •Debugging DLLs and Calls to DLLs
- •Troubleshooting the Call Library Function
- •Troubleshooting your DLL
- •Troubleshooting Checklist
- •Module Definition Files
- •Array and String Options
- •Arrays of Numeric Data
- •String Data
- •Figure 2-9. The LabVIEW String Format
- •Figure 2-10. The Pascal String Format
- •Figure 2-11. The C String Format
- •Array and String Tip
- •Supported Languages
- •Macintosh
- •Microsoft Windows
- •Solaris, Linux, and HP-UX
- •Resolving Multithreading Issues
- •Making LabVIEW Recognize a CIN as Thread Safe
- •Using C Code that is Thread Safe
- •Creating a CIN
- •Step 1. Set Up Input and Output Terminals for a CIN
- •Input-Output Terminals
- •Output-Only Terminals
- •Step 2. Wire the Inputs and Outputs to the CIN
- •Step 3. Create a .c File
- •Step 4. Compile the CIN Source Code
- •Compile on Macintosh
- •Microsoft Windows
- •Solaris 2.x
- •HP-UX and Linux
- •gcc Compiler
- •Step 5. Load the CIN Object Code
- •LabVIEW Manager Routines
- •Pointers as Parameters
- •Debugging External Code
- •DbgPrintf
- •Windows
- •UNIX
- •Passing Parameters
- •Parameters in the CIN .c File
- •Passing Fixed-Size Data to CINs
- •Scalar Numerics
- •Scalar Booleans
- •Refnums
- •Clusters of Scalars
- •Return Value for CIN Routines
- •Examples with Scalars
- •Creating a CIN That Multiplies Two Numbers
- •Passing Variably Sized Data to CINs
- •Alignment Considerations
- •Arrays and Strings
- •Paths
- •Clusters Containing Variably Sized Data
- •Resizing Arrays and Strings
- •SetCINArraySize
- •NumericArrayResize
- •Examples with Variably Sized Data
- •Concatenating Two Strings
- •Working with Clusters
- •Manager Overview
- •Basic Data Types
- •Scalar
- •char
- •Dynamic
- •Memory-Related
- •Constants
- •Memory Manager
- •Memory Allocation
- •Memory Zones
- •Using Pointers and Handles
- •File Manager
- •Identifying Files and Directories
- •Path Specifications
- •File Descriptors
- •File Refnums
- •Support Manager
- •CIN Routines
- •Data Spaces and Code Resources
- •One Reference to the CIN in a Single VI
- •Loading a VI
- •Unloading a VI
- •Loading a New Resource into the CIN
- •Compiling a VI
- •Running a VI
- •Saving a VI
- •Aborting a VI
- •Multiple References to the Same CIN in a Single VI
- •Multiple References to the Same CIN in Different VIs
- •Single-Threaded Operating Systems
- •Multithreaded Operating Systems
- •Code Globals and CIN Data Space Globals
- •Examples
- •Memory Manager Functions
- •Support Manager Functions
- •Mathematical Operations
- •ASCIITime
- •AZCheckHandle/DSCheckHandle
- •AZCheckPtr/DSCheckPtr
- •AZDisposeHandle/DSDisposeHandle
- •AZDisposePtr/DSDisposePtr
- •AZGetHandleSize/DSGetHandleSize
- •AZHandAndHand/DSHandAndHand
- •AZHandToHand/DSHandToHand
- •AZHeapCheck/DSHeapCheck
- •AZHLock
- •AZHNoPurge
- •AZHPurge
- •AZHUnlock
- •AZMaxMem/DSMaxMem
- •AZMemStats/DSMemStats
- •AZNewHandle/DSNewHandle
- •AZNewHClr/DSNewHClr
- •AZNewPClr/DSNewPClr
- •AZNewPtr/DSNewPtr
- •AZPtrAndHand/DSPtrAndHand
- •AZPtrToHand/DSPtrToHand
- •AZPtrToXHand/DSPtrToXHand
- •AZRecoverHandle/DSRecoverHandle
- •AZSetHandleSize/DSSetHandleSize
- •AZSetHSzClr/DSSetHSzClr
- •BinSearch
- •BlockCmp
- •Cat4Chrs
- •ClearMem
- •CPStrBuf
- •CPStrCmp
- •CPStrIndex
- •CPStrInsert
- •CPStrLen
- •CPStrRemove
- •CPStrReplace
- •CPStrSize
- •CToPStr
- •DateCString
- •DateToSecs
- •FAddPath
- •FAppendName
- •FAppPath
- •FArrToPath
- •FCopy
- •FCreate
- •FCreateAlways
- •FDepth
- •FDirName
- •FDisposePath
- •FDisposeRefNum
- •FEmptyPath
- •FExists
- •FFlattenPath
- •FFlush
- •FGetAccessRights
- •FGetDefGroup
- •FGetEOF
- •FGetInfo
- •FGetPathType
- •FGetVolInfo
- •FileNameCmp
- •FileNameIndCmp
- •FileNameNCmp
- •FIsAPath
- •FIsAPathOfType
- •FIsAPathOrNotAPath
- •FIsARefNum
- •FIsEmptyPath
- •FListDir
- •FLockOrUnlockRange
- •FMakePath
- •FMClose
- •FMOpen
- •FMove
- •FMRead
- •FMSeek
- •FMTell
- •FMWrite
- •FName
- •FNamePtr
- •FNewDir
- •FNewRefNum
- •FNotAPath
- •FPathCmp
- •FPathCpy
- •FPathToArr
- •FPathToAZString
- •FPathToDSString
- •FPathToPath
- •FRefNumToFD
- •FRefNumToPath
- •FRelPath
- •FRemove
- •FSetAccessRights
- •FSetEOF
- •FSetInfo
- •FSetPathType
- •FStrFitsPat
- •FStringToPath
- •FTextToPath
- •FUnFlattenPath
- •FVolName
- •GetALong
- •HexChar
- •HiByte
- •HiNibble
- •IsAlpha
- •IsDigit
- •IsLower
- •IsUpper
- •LoByte
- •Long
- •LoNibble
- •LStrBuf
- •LStrCmp
- •LStrLen
- •LToPStr
- •MilliSecs
- •MoveBlock
- •NumericArrayResize
- •Offset
- •PPStrCaseCmp
- •PPStrCmp
- •Printf
- •PStrBuf
- •PStrCaseCmp
- •PStrCat
- •PStrCmp
- •PStrCpy
- •PStrLen
- •PStrNCpy
- •PToCStr
- •PToLStr
- •QSort
- •RandomGen
- •SecsToDate
- •SetALong
- •SetCINArraySize
- •StrCat
- •StrCmp
- •StrCpy
- •StrLen
- •StrNCaseCmp
- •StrNCmp
- •StrNCpy
- •SwapBlock
- •TimeCString
- •TimeInSecs
- •ToLower
- •ToUpper
- •Unused
- •Word
- •Glossary

Chapter 4 Programming Issues for CINs
Note LabVIEW 4.x stored Boolean arrays in memory as a series of bits packed to
the nearest 16-bit word. LabVIEW 4.x ignored unused bits in the last word. LabVIEW 4.x ordered the bits from left to right; that is, the most significant bit (MSB) is index 0. As with other arrays, a 4-byte dimension size preceded Boolean arrays. The dimension size for LabVIEW 4.x Boolean arrays indicates the number of valid bits contained in the array.
Paths
The exact structure for Path data types is subject to change in future versions of LabVIEW. A Path is a dynamic data structure LabVIEW passes the same way it passes arrays. LabVIEW stores the data for Paths in an application zone handle. Refer to Refer to Chapter 6, Function Descriptions, for more information about the functions that manipulate
Paths.
Clusters Containing Variably Sized Data
For cluster arguments, LabVIEW passes a pointer to a structure containing the elements of the cluster. LabVIEW stores scalar values directly as components inside the structure. If a component is another cluster, LabVIEW stores this cluster value as a component of the main cluster. If a component is an array or string, LabVIEW stores a handle to the array or string component in the structure.
Resizing Arrays and Strings
To resize return arrays and strings you pass to a CIN, use the LabVIEW SetCINArraySize routine. Pass to the function the handle you want to resize, information describing the data structure, and the desired size of the array or handle. The function takes into account any padding and alignment needed for the data structure. However, the function does not update the dimension fields in the array. If you successfully resize the array, you need to update the dimension fields to correctly reflect the number of elements in the array.
You can resize numeric arrays more easily with NumericArrayResize. Pass to this function the array you want to resize, a description of the data structure, and information about the new size of the array.
© National Instruments Corporation |
4-9 |
Using External Code in LabVIEW |
Chapter 4 Programming Issues for CINs
When you resize arrays of variably sized data (for example, arrays of strings) with the SetCINArraySize or NumericArrayResize routines, consider the following issues:
•If the new size of the array is smaller, LabVIEW disposes of the handles used by the disposed element. Neither function sets the dimension field of the array. You must do this in your code after the function call.
•If the new size of the array is larger, LabVIEW does not automatically create the handles for the new elements. You have to create these handles after the function returns.
The following sections describe the SetCINArraySize and
NumericArrayResize routines.
Using External Code in LabVIEW |
4-10 |
www.ni.com |

Chapter 4 Programming Issues for CINs
SetCINArraySize
MgErr SetCINArraySize (UHandle dataH, int32 paramNum, int32 newNumElmts);
Purpose
SetCINArraySize resizes a data handle based on the data structure of an argument you pass to the CIN. It does not set the array dimension field.
Parameters
Name |
Type |
Description |
|
|
|
|
|
|
dataH |
UHandle |
Handle you want to resize. |
|
|
|
paramNum |
int32 |
Number for this parameter in the argument |
|
|
list to the CIN. The leftmost parameter has a |
|
|
parameter number of 0, and the rightmost |
|
|
has a parameter number of n – 1, where n is |
|
|
the total number of parameters. |
|
|
|
newNumElmts |
int32 |
New number of elements to which the handle |
|
|
should refer. For a one-dimensional array |
|
|
of five values, pass a value of 5. For a |
|
|
two-dimensional array of two rows by |
|
|
three columns, pass a value of 6. |
|
|
|
Return Value
MgErr, which can contain the errors in the following list. Refer to the Manager Overview section later in this chapter for more information about MgErr.
noErr |
No error. |
mFullErr |
Not enough memory to perform operation. |
mZoneErr |
Handle is not in specified zone. |
© National Instruments Corporation |
4-11 |
Using External Code in LabVIEW |

Chapter 4 Programming Issues for CINs
NumericArrayResize
MgErr NumericArrayResize(int32 typeCode, int32 numDims, UHandle *dataHP, int32 totalNewSize);
Purpose
NumericArrayResize resizes a data handle referring to a numeric array. This routine also accounts for alignment issues. It does not set the array dimension field. If *dataHP is NULL, LabVIEW allocates a new array handle in *dataHP.
Parameters
Name |
Type |
Description |
|
|
|
|
|
|
typeCode |
int32 |
Data type for the array you want to resize. The header file |
|
|
extcode.h defines the following constants for this argument: |
|
|
iB Array of signed 8-bit integers |
|
|
iW Array of signed 16-bit integers |
|
|
iL Array of signed 32-bit integers |
|
|
uB Array of unsigned 8-bit integers |
|
|
uW Array of unsigned 16-bit integers |
|
|
uL Array of unsigned 32-bit integers |
|
|
fS Array of single-precision (32-bit) numbers |
|
|
fD Array of double-precision (64-bit) numbers |
|
|
fX Array of extendedprecision numbers |
|
|
cS Array of single-precision complex numbers |
|
|
cD Array of double-precision complex numbers |
|
|
cX Array of extended-precision complex numbers |
|
|
|
numDims |
int32 |
Number of dimensions in the data structure to which the handle |
|
|
refers. Thus, if the handle refers to a two-dimensional array, |
|
|
pass a value of 2. |
|
|
|
Using External Code in LabVIEW |
4-12 |
www.ni.com |
|
|
Chapter 4 Programming Issues for CINs |
|
|
|
Name |
Type |
Description |
|
|
|
|
|
|
*dataHP |
UHandle |
Pointer to the handle you want to resize. If this is a pointer |
|
|
to NULL, LabVIEW allocates and sizes a new handle |
|
|
appropriately and returns the handle in *dataHP. |
|
|
|
totalNewSize |
int32 |
New number of elements to which the handle should refer. For |
|
|
a unidimensional array of five values, pass a value of 5. For a |
|
|
two-dimensional array of two rows by three columns, pass a |
|
|
value of 6. |
|
|
|
Return Values
MgErr, which can contain the errors in the following list. Refer to the Manager Overview section later in this chapter for more information about MgErr.
noErr |
No error. |
mFullErr |
Not enough memory to perform operation. |
mZoneErr |
Handle is not in specified zone. |
© National Instruments Corporation |
4-13 |
Using External Code in LabVIEW |