# mmWriteStream

Writes media data either into an intermediate holding area or directly into the specified stream at the current position.

#### Prototype

DWORD mmWriteStream ( MMSTREAM *pMMStream, BYTE *pBuffer, unsigned bufferSize, unsigned writeFlags, unsigned *pByteCount, unsigned *pSampleIdx, unsigned *pTime)

Argument | Description
pMMStream | Returns a pointer to the object that controls the stream.
pBuffer | A pointer to the buffer that contains the media data to write.
bufferSize | The size of the buffer, in bytes.
writeFlags | Controls the write command. Use 0 (zero) for this field.
pByteCount | A pointer to the returned number of bytes written. This value is NULL if no bytes were written.
pSampleIdx | A pointer to the index of the next sample in the stream. Specify NULL, if you do not need this value.
pTime | A pointer to the returned current time position within the stream, in ms. Specify NULL, if you do not need this value.

#### Return values

Return value | Description
SUCCESS |
MMERR_BUFFER_TOO_SMALL | No entire media sample found in pBuffer. You need to provide a larger buffer.
MMERR_INCOMP_ACCESS_MODE | Stream was not opened for read operation.
MMERR_INTERNAL_RESOURCE | Error on internal resource.
MMERR_INVALID_STREAM | pMMStream is invalid.
MMERR_INVALID_POINTER | pBuffer is null.
MMERR_MEDIA_FORMAT | Error in media data format.

### Details

The mmWriteStream function writes stream data to an intermediate holding area if the file that will contain the stream was opened with one of these settings:

- FORMAT_FLAG_WR_NORMAL

- FORMAT_FLAG_TEMP_MEM

- FORMAT_FLAG_TEMP_FILE

In this situation, the stream data is copied from the intermediate holding area to the file when you invoke mmCloseFile.

If the file was opened with the FORMAT_FLAG_WR_DIRECT setting, then the data is written to the media stream directly when you invoke mmWriteStream. For information about opening a file, see mmOpenStream.

#### Example

DWORD ret;
ret = mmWriteStream(&mmStream, pBuffer, wrSize, NULL, &byteCount, NULL, NULL);
if (ret != SUCCESS)
{
printf("\nERROR: failed to write the stream into the file. ret (%d)\n", ret);
}