MsiRecordReadStream Function

Windows Installer

MsiRecordReadStream Function

The MsiRecordReadStream function reads bytes from a record stream field into a buffer.

Syntax

C++UINT MsiRecordReadStream(
  __in     MSIHANDLE hRecord,
  __in     UINT iField,
  __out    char *szDataBuf,
  __inout  DWORD *pcbDataBuf
);

Parameters

hRecord [in]

Handle to the record.

iField [in]

Specifies the field of the record.

szDataBuf [out]

A buffer to receive the stream field. You should ensure the destination buffer is the same size or larger than the source buffer. See the Remarks section.

pcbDataBuf [in, out]

Specifies the in and out buffer count. On input, this is the full size of the buffer. On output, this is the number of bytes that were actually written to the buffer. See the Remarks section.

Return Value

ERROR_INVALID_DATATYPE

The field is not a stream column.

ERROR_INVALID_HANDLE

An invalid or inactive handle was supplied.

ERROR_INVALID_PARAMETER

An invalid parameter was passed to the function.

ERROR_SUCCESS

The function succeeded.

Remarks

To read a stream, set pcbDataBuf to the number of bytes that are to be transferred from stream to buffer each time the function is called. On return, the MsiRecordReadStream resets pcbDataBuf to the number of bytes that were actually transferred. If the buffer is smaller than the stream, the stream is repositioned when the buffer becomes full such that the next data in the stream is transferred by the next call to the function. When no more bytes are available, MsiRecordReadStream returns ERROR_SUCCESS.

If you pass 0 for szDataBuf then pcbDataBuf is reset to the number of bytes in the stream remaining to be read.

The following code sample reads from a stream that is in field 1 of a record specified by hRecord and reads the entire stream 8 bytes at a time.

char szBuffer[8];
PMSIHANDLE hRecord;
DWORD cbBuf = sizeof(szBuffer);
do 
{
    if (MsiRecordReadStream(hRecord, 1, szBuffer, 
		&cbBuf) != ERROR_SUCCESS)
        break; /* error */
}
while (cbBuf == 8);  //continue reading the stream while you receive a full buffer
//cbBuf will be less once you reach the end of the stream and cannot fill your 
//buffer with stream data

See also OLE Limitations on Streams.

Requirements

VersionWindows Installer 5.0 on Windows Server 2008 R2 or Windows 7. Windows Installer 4.0 or Windows Installer 4.5 on Windows Server 2008 or Windows Vista. Windows Installer on Windows Server 2003, Windows XP, and Windows 2000
HeaderMsiquery.h
LibraryMsi.lib
DLLMsi.dll

See Also

Record Processing Functions

Send comments about this topic to Microsoft

Build date: 8/13/2009

© 2009 Microsoft Corporation. All rights reserved.