82.4.4 Creating RIFF Chunks

To create a new chunk, use mmioCreateChunk to write a chunk header at the current position in an open file. The mmioCreateChunk function has the following syntax:

UINT mmioCreateChunk(hmmio, lpmmckinfo, wFlags)

The hmmio parameter specifies the file handle for an open RIFF file.

The lpmmckinfo parameter specifies a far pointer to an MMCKINFO structure containing information about the new chunk.

The wFlags parameter specifies option flags for creating the new chunk. To create a “RIFF” chunk, specify the MMIO_CREATERIFF flag. To create a “LIST” chunk, specify the MMIO_CREATELIST flag.

The return value is zero if the chunk is successfully created; otherwise, if there is an error creating the chunk, the return value specifies an error code.

The following example creates a new chunk with a chunk ID of “RIFF” and a form type of “RDIB”:

HMMIO hmmio;

MMCKINFO mmckinfo;

.

.

.

mmckinfo.fccType = mmioFOURCC('R', 'D', 'I', 'B');

mmioCreateChunk(hmmio, &mmckinfo, MMIO_CREATERIFF);

If you're creating a “RIFF” or “LIST” chunk, you must specify the form type in the fccType field of the MMCKINFO structure. In the previous example, the form type is “RDIB”.

If you know the size of the data field in a new chunk, you can set the cksize field in the MMCKINFO structure when you create the chunk. This value will be written to the data size field in the new chunk. If this value is not correct when you call mmioAscend to mark the end of the chunk, it will be automatically rewritten to reflect the correct size of the data field.

After you create a new chunk using mmioCreateChunk, the file position is set to the data field of the chunk (8 bytes from the beginning of the chunk). If the chunk is a “RIFF” or “LIST” chunk, the file position is set to the location following the form type or list type (12 bytes from the beginning of the chunk).