- •Important Information
- •Warranty
- •Copyright
- •Trademarks
- •Organization of This Manual
- •Conventions Used in This Manual
- •Related Documentation
- •Customer Communication
- •Introduction
- •Classes of External Code
- •Supported Languages
- •Macintosh
- •Microsoft Windows 3.1
- •Microsoft Windows 95 and Windows NT
- •Solaris
- •Steps for Creating a CIN
- •1. Place the CIN on a Block Diagram
- •2. Add Input and Output Terminals to the CIN
- •Input-Output Terminals
- •Output-Only Terminals
- •3. Wire the Inputs and Outputs to the CIN
- •4. Create .c File
- •Special Macintosh Considerations
- •5. Compile the CIN Source Code
- •Macintosh
- •THINK C for 68K (Versions 5-7)
- •Symantec C++ 8.0 for Power Macintosh
- •Metrowerks CodeWarrior for 68K
- •Metrowerks CodeWarrior for Power Macintosh
- •Microsoft Windows 3.x
- •Watcom C Compiler
- •Microsoft Windows 95 and Windows NT
- •Microsoft SDK C/C++ Compiler
- •Visual C++ for Windows 95 or Windows NT
- •Solaris 1.x
- •Solaris 2.x
- •6. Load the CIN Object Code
- •LabVIEW Manager Routines
- •Online Reference
- •Pointers as Parameters
- •Debugging External Code
- •DbgPrintf
- •Debugging CINs Under Windows 95 and Windows NT
- •Debugging CINs Under Sun or Solaris
- •Debugging CINs Under HP-UX
- •Introduction
- •CIN .c File
- •How LabVIEW Passes Fixed Sized Data to CINs
- •Scalar Numerics
- •Scalar Booleans
- •Refnums
- •Clusters of Scalars
- •Return Value for CIN Routines
- •Examples with Scalars
- •1. Place the CIN on the Block Diagram
- •2. Add Two Input and Output Terminals to the CIN
- •3. Wire the Inputs and Outputs to the CIN
- •4. Create the CIN Source Code
- •5. Compile the CIN Source Code
- •Macintosh
- •THINK C for 68K and Symantec C++
- •Microsoft Windows 3.x
- •Watcom C Compiler
- •Microsoft Windows 95 and Windows NT
- •Microsoft SDK Compiler
- •Microsoft Visual C++ Compiler
- •Solaris 1.x, Solaris 2.x, and HP-UX
- •6. Load the CIN Object Code
- •Comparing Two Numbers, Producing a Boolean Scalar
- •How LabVIEW Passes Variably Sized Data to CINs
- •Alignment Considerations
- •Arrays and Strings
- •Paths (Path)
- •Clusters Containing Variably Sized Data
- •Resizing Arrays and Strings
- •SetCINArraySize
- •NumericArrayResize
- •Examples with Variably Sized Data
- •Concatenating Two Strings
- •Working with Clusters
- •CIN Routines
- •Data Spaces and Code Resources
- •CIN Routines: The Basic Case
- •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
- •Reentrancy
- •Code Globals and CIN Data Space Globals
- •Examples
- •Using Code Globals
- •Using CIN Data Space Globals
- •Calling a Windows 3.1 Dynamic Link Library
- •Calling a 16-Bit DLL
- •1. Load the DLL
- •2. Get the address of the desired function
- •3. Describe the function
- •4. Call the function
- •Example: A CIN that Displays a Dialog Box
- •The Block Diagram
- •The CIN Code
- •Compiling the CIN
- •Optimization
- •Introduction
- •Creating Shared External Subroutines
- •External Subroutine
- •Macintosh
- •THINK C Compiler and CodeWarrior 68K Compiler
- •MPW Compiler
- •Solaris 1.x, Solaris 2.x, and HP-UX
- •Calling Code
- •Macintosh
- •THINK C Compiler
- •CodeWarrior 68K Compiler
- •MPW Compiler
- •Solaris 1.x, Solaris 2.x, and HP-UX
- •Simple Example
- •External Subroutine Example
- •Compiling the External Subroutine
- •Macintosh
- •THINK C Compiler and CodeWarrior 68K Compiler
- •MPW Compiler
- •Microsoft Windows 3.1
- •Watcom C Compiler
- •Microsoft Windows 95 and Windows NT
- •Solaris 1.x, Solaris 2.x, and HP-UX
- •Calling Code
- •Compiling the Calling Code
- •Macintosh
- •THINK C Compiler
- •CodeWarrior 68K Compiler
- •MPW Compiler
- •Microsoft Windows 3.1
- •Watcom C Compiler
- •Microsoft Windows 95 and Windows NT
- •Solaris 1.x, Solaris 2.x, and HP-UX
- •Introduction
- •Basic Data Types
- •Scalar Data Types
- •Booleans
- •Numerics
- •Complex Numbers
- •char Data Type
- •Dynamic Data Types
- •Arrays
- •Strings
- •C-Style Strings (CStr)
- •Pascal-Style Strings (PStr)
- •LabVIEW Strings (LStr)
- •Concatenated Pascal String (CPStr)
- •Paths (Path)
- •Memory-Related Types
- •Constants
- •Memory Manager
- •Memory Allocation
- •Static Memory Allocation
- •Dynamic Memory Allocation: Pointers and Handles
- •Memory Zones
- •Using Pointers and Handles
- •Simple Example
- •Reference to the Memory Manager
- •Memory Manager Data Structures
- •File Manager
- •Introduction
- •Identifying Files and Directories
- •Path Specifications
- •Conventional Path Specifications
- •Empty Path Specifications
- •LabVIEW Path Specification
- •File Descriptors
- •File Refnums
- •Support Manager
- •Allocating and Releasing Handles
- •Allocating and Releasing Pointers
- •Manipulating Properties of Handles
- •AZHLock
- •AZHPurge
- •AZHNoPurge
- •AZHUnlock
- •Memory Utilities
- •ClearMem
- •MoveBlock
- •SwapBlock
- •Handle and Pointer Verification
- •Memory Zone Utilities
- •File Manager Data Structures
- •File/Directory Information Record
- •File Type Record
- •Path Data Type
- •Permissions
- •Volume Information Record
- •File Manager Functions
- •Performing Basic File Operations
- •FCreate
- •FCreateAlways
- •FMClose
- •FMOpen
- •FMRead
- •FMWrite
- •Positioning the Current Position Mark
- •FMSeek
- •FMTell
- •Positioning the End-Of-File Mark
- •FGetEOF
- •FSetEOF
- •Flushing File Data to Disk
- •FFlush
- •FExists
- •FGetAccessRights
- •FGetInfo
- •FGetVolInfo
- •FSetAccessRights
- •FSetInfo
- •Getting Default Access Rights Information
- •FGetDefGroup
- •FListDir
- •FNewDir
- •Copying Files
- •FCopy
- •Moving and Deleting Files and Directories
- •FMove
- •FRemove
- •Locking a File Range
- •FLockOrUnlockRange
- •Matching Filenames with Patterns
- •FStrFitsPat
- •Creating Paths
- •FAddPath
- •FAppendName
- •FAppPath
- •FEmptyPath
- •FMakePath
- •FNotAPath
- •FRelPath
- •Disposing Paths
- •FDisposePath
- •Duplicating Paths
- •FPathCpy
- •FPathToPath
- •Extracting Information from a Path
- •FDepth
- •FDirName
- •FName
- •FNamePtr
- •FVolName
- •FArrToPath
- •FFlattenPath
- •FPathToArr
- •FPathToAZString
- •FPathToDSString
- •FStringToPath
- •FTextToPath
- •FUnFlattenPath
- •Comparing Paths
- •FIsAPath
- •FIsAPathOrNotAPath
- •FIsEmptyPath
- •FPathCmp
- •Determining a Path Type
- •FGetPathType
- •FIsAPathOfType
- •FSetPathType
- •Manipulating File Refnums
- •FDisposeRefNum
- •FIsARefNum
- •FNewRefNum
- •FRefNumToFD
- •FRefNumToPath
- •Byte Manipulation Operations
- •Mathematical Operations
- •For THINK C Users
- •RandomGen
- •String Manipulation
- •BlockCmp
- •CPStrCmp
- •CPStrIndex
- •CPStrInsert
- •CPStrRemove
- •CPStrReplace
- •CPStrSize
- •CToPStr
- •HexChar
- •IsAlpha
- •IsDigit
- •IsLower
- •IsUpper
- •LStrCmp
- •LToPStr
- •PPStrCaseCmp
- •PPStrCmp
- •PStrCaseCmp
- •PStrCat
- •PStrCmp
- •PStrCpy
- •PStrNCpy
- •PToCStr
- •PToLStr
- •StrCat
- •StrCmp
- •StrCpy
- •StrLen
- •StrNCaseCmp
- •StrNCmp
- •StrNCpy
- •ToLower
- •ToUpper
- •Utility Functions
- •BinSearch
- •QSort
- •Time Functions
- •ASCIITime
- •DateCString
- •DateToSecs
- •MilliSecs
- •SecsToDate
- •TimeCString
- •TimeInSecs
- •Microsoft Windows 3.1, Windows 95, and Windows NT
- •Macintosh
- •How do I debug my CIN?
- •Can LabVIEW be used to call a DLL in Windows?
- •Glossary
- •Index
Chapter 5 Manager Overview
File Refnums
In the file manager, LabVIEW accesses open files using file descriptors. On the front panel and block diagram, however, LabVIEW accesses open files through file refnums. A file refnum contains a file descriptor for use by the file manager, and additional information used by LabVIEW.
LabVIEW specifies file refnums using the LVRefNum data type, the exact structure of which is private to the file manager. If you want to pass references to open files into or out of a CIN, use the functions in the Manipulating File Refnums topic of the Online Reference to convert file refnums to file descriptors, and to convert file descriptors to file refnums.
Support Manager
The support manager is a collection of constants, macros, basic data types, and functions that perform operations on strings and numbers. The support manager also has functions for determining the current time in a variety of formats.
Note: This section gives only a brief overview of the support manager. For descriptions of specific support manager functions, see the Function and VI Reference topic in LabVIEW’s Online Reference, or the Code Interface Node Reference online manual.
The support manager’s string functions contain much of the functionality of the string libraries supplied with standard C compilers, such as string concatenation and formatting. You can use variations of many of these functions with LabVIEW strings (4-byte length field followed by data, generally stored in a handle), Pascal strings (1-byte length field followed by data), and C strings (data terminated by a null character).
With the utility functions you can sort and search on arbitrary data types, using quicksort and binary search algorithms.
The support manager contains transcendental functions for many complex and extended floating-point operations.
Certain routines specify time as a data structure with the following form.
© National Instruments Corporation |
5-17 |
LabVIEW Code Interface Reference Manual |
Chapter 5 Manager Overview
typedef struct {
int32 |
sec;/* 0:59 */ |
int32 |
min;/* 0:59 */ |
int32 |
hour;/* 0:23 */ |
int32 |
mday;/* day of the month, 1:31 */ |
int32 |
mon;/* month of the year, 1:12 */ |
int32 year;/* year, 1904:2040 */ |
|
int32 |
wday;/* day of the week, 1:7 for Sun:Sat */ |
int32 |
yday;/* day of year (julian date), 1:366 */ |
int32 |
isdst;/* 1 if daylight savings time */ |
} DateRec;
LabVIEW Code Interface Reference Manual |
5-18 |
© National Instruments Corporation |
Memory Manager Functions |
Chapter |
|
6 |
Allocating and Releasing Handles |
|
AZDisposeHandle
DSDisposeHandle
syntax |
MgErr |
AZDisposeHandle(h); |
MgErr DSDisposeHandle(h);
XXDisposeHandle releases the memory referenced by the specified handle.
|
Parameter |
Type |
Description |
|
h |
UHandle |
Handle you want to dispose of. |
returns |
MgErr, which can contain the errors in the following list. |
||
|
Error |
Description |
|
|
noErr |
No error. |
|
|
mZoneErr |
Handle or pointer not in specified zone. |
|
|
|
|
|
AZEmptyHandle
DSEmptyHandle
syntax |
MgErr |
AZEmptyHandle(h); |
|
MgErr |
DSEmptyHandle(h); |
XXEmptyHandle releases the memory referenced by a handle, and replaces the handle's master pointer with NULL.
The master pointer is set to NULL, but remains a valid master pointer after this call. All handle-based references to the block of memory point to the NULL handle. If you reallocate space for the handle using XXReallocHandle, all references to the old handle will reference the new block of memory.
Parameter |
Type |
Description |
|
h |
UHandle |
Handle to empty. |
|
© National Instruments Corporation |
|
6-1 |
LabVIEW Code Interface Reference Manual |
Chapter 6 Memory Manager Functions
returns |
MgErr, which can contain the errors in the following list. |
|
|
Error |
Description |
|
noErr |
No error. |
|
mZoneErr |
Handle or pointer not in specified zone. |
|
|
|
AZGetHandleSize
DSGetHandleSize
syntax |
int32 |
AZGetHandleSize(h); |
|||
|
|
int32 |
DSGetHandleSize(h); |
||
|
XXGetHandleSize returns the size of the block of memory referenced by the |
||||
|
specified handle. |
|
|
|
|
|
Parameter |
Type |
|
Description |
|
|
h |
UHandle |
Handle whose size you want to determine. |
||
returns |
The size in bytes of the relocatable block referenced by the handle h. If an error |
||||
|
|
occurs, XXGetHandleSize returns a negative number. |
|||
|
|
|
|
|
|
AZNewHandle
DSNewHandle
syntax |
UHandle |
ZNewHandle(size); |
|
UHandle |
DSNewHandle(size); |
XXNewHandle creates a new handle to a relocatable block of memory of the specified size. The routine aligns all handles and pointers in DS to accommodate the largest possible data representations for the platform in use.
|
Parameter |
Type |
Description |
|
size |
int32 |
Size, in bytes, of the handle to create. |
returns |
A handle of the specified size. Returns NULL if the routine fails. |
||
|
|
|
|
AZNewHClr
DSNewHClr
LabVIEW Code Interface Reference Manual |
6-2 |
© National Instruments Corporation |
Chapter 6 Memory Manager Functions
syntax |
UHandle |
AZNewHClr(size); |
|
UHandle |
DSNewHClr(size); |
XXNewHClr creates a new handle to a relocatable block of memory of the specified size and initializes the memory to zero.
|
Parameter |
Type |
Description |
|
size |
int32 |
Size, in bytes, of the handle to create. |
returns |
A handle of the specified size, where the block of memory is set to all zeros. |
||
|
|
Returns NULL if the routine fails. |
|
|
|
|
|
AZReallocHandle
DSReallocHandle
syntax |
MgErr |
AZReallocHandle(h, |
size); |
|
MgErr |
DSReallocHandle(h, |
size); |
XXReallocHandle creates a new block of memory and sets the specified handle to reference the block of memory.
If h is not already an empty handle, the function releases the block of memory referenced by h before creating the new block. A handle is an empty handle if you called XXEmptyHandle on the handle, or if you marked the handle as purgeable and the memory manager purged it from memory.
|
Parameter |
Type |
Description |
|
h |
UHandle |
Handle to recover. |
|
size |
int32 |
New size, in bytes, of the handle. |
returns |
MgErr, which can contain the errors in the following list. |
||
|
Error |
Description |
|
|
noErr |
No error. |
|
|
mgArgErr |
Invalid argument. |
|
|
mFullErr |
Not enough memory to perform operation. |
|
|
mZoneErr |
Handle or pointer not in specified zone. |
|
|
|
|
|
AZRecoverHandle
DSRecoverHandle
© National Instruments Corporation |
6-3 |
LabVIEW Code Interface Reference Manual |
Chapter 6 Memory Manager Functions
syntax |
UHandle |
AZRecoverHandle(p); |
|
UHandle |
DSRecoverHandle(p); |
Given a pointer to a block of memory that was originally declared as a handle, XXRecoverHandle returns a handle to the block of memory.
This function is useful when you have the address of a block of memory that you know is a handle, and you need to get a true handle to the block of memory.
|
Parameter |
Type |
Description |
|
p |
UPtr |
Pointer to a relocatable block of memory. |
returns |
A handle to the block of memory to which p refers. Returns NULL if the |
||
|
|
routine fails. |
|
|
|
|
|
AZSetHandleSize
DSSetHandleSize
syntax |
MgErr |
AZSetHandleSize(h, |
size); |
|
MgErr |
DSSetHandleSize(h, |
size); |
XXSetHandleSize changes the size of the block of memory referenced by the specified handle.
While LabVIEW arrays are stored in DS handles, you should not use this function to resize array handles. Many platforms have memory alignment requirements that make it difficult to determine the correct size for the resulting array. Instead, you should use either NumericArrayResize or SetCINArraySize, which are described in the
Resizing Arrays and Strings section of Chapter 2, CIN Parameter Passing. You should not use these functions on a locked handle.
|
Parameter |
Type |
Description |
|
h |
UHandle |
Handle to resize. |
|
size |
int32 |
New size, in bytes, of the handle. |
returns |
MgErr, which can contain the errors in the following list. |
||
|
Error |
Description |
|
|
noErr |
No error. |
|
|
mFullErr |
Not enough memory to perform operation. |
|
|
mZoneErr |
Handle or pointer not in specified zone. |
|
|
|
|
|
LabVIEW Code Interface Reference Manual |
6-4 |
© National Instruments Corporation |