Skip to content

I/O Format Specifiers for Reading Raw Binary Data

An array argument formatted as raw binary data has a format specifier of the following form:

%[*] [array size] [!ob | !ol] [$S] [b | h | l | I] y

ModifierInterpretation
Default FunctionalityThe data block is received as raw binary data.
* (asterisk)An asterisk acts as the assignment suppression character. The input is scanned but not assigned to any parameters and is discarded.
array sizeSpecifies the maximum number of elements to read from the device. If the argument is a SAFEARRAY, then the array size may be omitted. A # may be present in lieu of an integer array size modifier, in which case an extra int argument supplies the value.
$SThe argument is assumed to be a SAFEARRAY.
!obData is expected to be in standard IEEE 488.2 (big endian) format. This is the default behavior if neither !ob nor !ol is present. Byte-swapping is automatically performed on all elements in the array argument.
!olData is expected to be in little endian format.
length modifierIf no length modifier is specified, then the argument is assumed to be an array (or SAFEARRAY if $S is used) of BYTE (8-bit) integer.
b - argument is an array of BYTE (8-bit) integer.
h - argument is an array of short (16-bit) integer.
The array size indicates the number of 16-bit words, rather than the number of bytes.
l - argument is an array of long (32-bit) integer.
The array size indicates the number of 32-bit words, rather than the number of bytes.
I - argument is an array of __int64 (64-bit) integer.
The array size indicates the number of 64-bit words, rather than the number of bytes.
HRESULT hr = S_OK;
short rgData[100];
// Raw binary block of 100 16-bit words, big endian byte ordering
hr = io.Scanf(_T("%100hy"), rgData);
// Raw binary block of 100 16-bit words, little endian byte ordering
// Number of elements specified as a variable
int nCount = 100;
hr = io.Scanf(_T("%#!olhy"), &nCount, rgData);
// nCount updated with actual number of 16-bit words read
SAFEARRAY* psa = NULL;
// Raw binary block of 100 32-bit long words. Argument is a SAFEARRAY.
// No field width is needed as Scanf allocates the SAFEARRAY memory
hr = io.Scanf(_T("%$Sly"), &psa);
// ... use SAFEARRAY result
// IMPORTANT: SAFEARRAY must be destroyed
hr = ::SafeArrayDestroy(psa);