I/O Format Specifiers for Reading Raw Binary Data
Raw Binary Data — %y
Section titled “Raw Binary Data — %y”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
| Modifier | Interpretation |
|---|---|
| Default Functionality | The 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 size | Specifies 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. |
$S | The argument is assumed to be a SAFEARRAY. |
!ob | Data 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. |
!ol | Data is expected to be in little endian format. |
length modifier | If 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. |
Example — Raw binary data
Section titled “Example — Raw binary data”HRESULT hr = S_OK;
short rgData[100];
// Raw binary block of 100 16-bit words, big endian byte orderinghr = io.Scanf(_T("%100hy"), rgData);
// Raw binary block of 100 16-bit words, little endian byte ordering// Number of elements specified as a variableint 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 memoryhr = io.Scanf(_T("%$Sly"), &psa);
// ... use SAFEARRAY result
// IMPORTANT: SAFEARRAY must be destroyedhr = ::SafeArrayDestroy(psa);