
- •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 6 Function Descriptions
FMRead
MgErr FMRead(fd, inCount, outCountp, buffer);
Purpose
Reads inCount bytes from the file specified by the file descriptor fd. The function starts from the current position mark and reads the data into memory, starting at the address specified by buffer. Refer to the FMSeek and FMTell functions for more information about the current position mark.
The function stores the actual number of bytes read in *outCountp. The number of bytes can be less than inCount if the function encounters end-of-file before reading inCount bytes. The number of bytes is zero if any other error occurs.
Parameters
Name |
Type |
Description |
|
|
|
|
|
|
fd |
File |
File descriptor associated with the file from |
|
|
which you want to read. |
|
|
|
inCount |
int32 |
Number of bytes you want to read. |
|
|
|
outCountp |
int32 * |
Address at which FMRead stores the number |
|
|
of bytes read. FMRead does not store any |
|
|
value if NULL is passed. Refer to the Pointers |
|
|
as Parameters section in Chapter 3, CINs, |
|
|
for more information about using this |
|
|
parameter. |
|
|
|
buffer |
Uptr |
Address where FMRead stores the data. |
|
|
|
Return Value
mgErr, which can contain the following errors:
mgArgErr |
Not a valid file descriptor or inCount < 0. |
FEOF |
EOF encountered. |
fIOErr |
Unspecified I/O error. |
Using External Code in LabVIEW |
6-92 |
www.ni.com |

Chapter 6 Function Descriptions
FMSeek
MgErr FMSeek(fd, ofst, mode);
Purpose
Sets the current position mark for a file to the specified point, relative to the beginning of the file, the current position in the file, or the end of the file. If an error occurs, the current position mark does not move.
Parameters
Name |
Type |
Description |
|
|
|
|
|
|
fd |
File |
File descriptor associated with the file. |
|
|
|
ofst |
int32 |
New position of the current position mark. |
|
|
The position is the number of bytes from the |
|
|
beginning of the file, the current position |
|
|
mark, or the end of the file, as determined by |
|
|
mode. |
|
|
|
mode |
int32 |
Position in the file relative to which FMSeek |
|
|
sets the current position mark for a file, using |
|
|
the following values: |
|
|
• fStart—Current position mark |
|
|
moves to ofst bytes relative to the |
|
|
start of the file (ofst must be greater |
|
|
than or equal to 0). |
|
|
• fCurrent—Current position mark |
|
|
moves ofst bytes from the current |
|
|
position mark (ofst can be positive, |
|
|
0, or negative). |
|
|
• fEnd—Current position mark |
|
|
moves to ofst bytes from the end of |
|
|
the file (ofst must be less than or |
|
|
equal to 0). |
|
|
|
Return Value
mgErr, which can contain the following errors:
mgArgErr |
The file descriptor is not valid. |
fEOF |
Attempt to seek before the start or after the end of the file. |
fIOErr |
Unspecified I/O error. |
© National Instruments Corporation |
6-93 |
Using External Code in LabVIEW |

Chapter 6 Function Descriptions
FMTell
MgErr FMTell(fd, ofstp);
Purpose
Returns the position of the current position mark in the file.
Parameters
Name |
Type |
Description |
|
|
|
|
|
|
fd |
File |
File descriptor associated with the file. |
|
|
|
ofstp |
int32 * |
Address at which FMTell stores the position |
|
|
of the current position mark, in terms of |
|
|
bytes relative to the beginning of the file. If |
|
|
an error occurs, ofstp is undefined. Refer to |
|
|
the Pointers as Parameters section in |
|
|
Chapter 3, CINs, for more information about |
|
|
using this parameter. |
|
|
|
Return Value
mgErr, which can contain the following errors:
mgArgErr |
The file descriptor is not valid. |
fIOErr |
Unspecified I/O error. |
Using External Code in LabVIEW |
6-94 |
www.ni.com |

Chapter 6 Function Descriptions
FMWrite
MgErr FMWrite(fd, inCount, outCountp, buffer);
Purpose
Writes inCount bytes from memory, starting at the address specified by buffer, to the file specified by the file descriptor fd, starting from the current position mark. Refer to the FMSeek and FMTell functions for more information about the current position mark.
The function stores the actual number of bytes written in *outCountp. The number of bytes stored can be less than inCount if an fDiskFull error occurs before the function writes inCount bytes. The number of bytes stored is zero if any other error occurs.
Parameters
Name |
Type |
Description |
|
|
|
|
|
|
fd |
File |
File descriptor associated with the file from |
|
|
which you want to write. |
|
|
|
inCount |
int32 |
Number of bytes you want to write. |
|
|
|
outCountp |
int32 * |
Address at which FMWrite stores the |
|
|
number of bytes written. FMWrite does not |
|
|
store any value if NULL is passed. Refer to the |
|
|
Pointers as Parameters section in Chapter 3, |
|
|
CINs, for more information about using this |
|
|
parameter. |
|
|
|
buffer |
Uptr |
Address of the data you want to write. |
|
|
|
Return Value
mgErr, which can contain the following errors:
mgArgErr |
Not a valid file descriptor or inCount < 0. |
fDiskFull |
Out of space. |
fNoPerm |
Access was denied. |
fIOErr |
Unspecified I/O error. |
© National Instruments Corporation |
6-95 |
Using External Code in LabVIEW |