PutBinary


The PutBinary method writes binary data sequence to file and returns number of elements actually written. File position is moved forward by the number of bytes written.
C++
long PutBinary(
  void *BinaryBuffer,              // buffer that contains data
  long NumberOfElements,           // number of elements to write
  long SizeOfElement,              // size of each element
  long FilePosition = -1           // position of data in file
);

Parameters

BinaryBuffer
Pointer to buffer that contains data.
NumberOfElements
Number of elements in data sequence to write.
SizeOfElement
Size of each element, in bytes.
FilePosition
Position in file to write data at.
If this parameter is -1 data is written at current file position.

Return Values

If the method succeeds, the return value is the number of elements actually written.
If the method fails, the return value is failure code and error code is set. Call GetError to get error code.

Remarks

Method can be used for writing structured data with fields of various types. In such case entire structure should be treated as a sequence of bytes (SizeOfElement should be 1) whose length is equal to total size of the structure and is specified in NumberOfElements. File data, however, is always written in machine (little-endian) byte order because there is no way to determine sizes of each field in the structure for big-endian conversion. Method can be also used for writing data of simple types that are not directly supported like Boolean, Date, Currency or Decimal; in such case size of elements must be specified to properly handle big-endian conversion.

Method is available only in C++ component because binary (user defined) data types are not allowed in COM. Visual Basic developers should use PutVariant method for writing structured data.

See Also

GetBinary, PutBit, PutByte, PutShort, PutLong, PutFloat, PutDouble, PutText, PutUnicodeText, PutVariant, Reading and Writing Data