Click or drag to resize

I/O Format Specifiers for Writing Raw Binary Data

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 sent as raw binary data. The array size field specifies the number of elements (by default, bytes) in the block.

array size

Specifies the number of elements in the associated array argument. If the argument is a SAFEARRAY, then the array size may be omitted, in which case the number of elements sent is determined from the size of the SAFEARRAY itself.

An asterisk (*) 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 interpreted as a SAFEARRAY of integers, as dictated by the length modifier field.

!ob

Data is sent 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 sent in little endian format.

length modifier

If no length modifier is specified, then the argument is assumed to be an array 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

C++
HRESULT hr = S_OK;

short rgShortData[] = { 100, 200, 300 };

// Raw binary block of 3 16-bit words, big endian byte ordering
hr = io.Printf(_T("%3hy"), rgShortData);            

// Raw binary block of 5 16-bit words, little endian byte ordering
// Number of elements specified as a variable
int nCount = 3;
hr = io.Printf(_T("%*!olhy"), nCount, rgShortData);            

CComSafeArray<long> saData;
saData.Add(100);
saData.Add(200);
saData.Add(300);
saData.Add(400);
saData.Add(500);

// Raw binary block of 5 32-bit long words. Argument is a SAFEARRAY.
// No field width supplied, so count is determined from the SAFEARRAY itself.
hr = io.Printf(_T("%$Sly"), saData.m_psa);
See Also

Other Resources

Download a complete CHM version of this documentation here.