IMFByteStream::Write Method
Writes data to the stream.
Syntax
HRESULT Write(
[in] const BYTE *pb,
[in] ULONG cb,
[out] ULONG *pcbWritten
);
Parameter
pb [in]
Pointer to a buffer that contains the data to write.cb [in]
Size of the buffer in bytes.pcbWritten [out]
Receives the number of bytes that are written.
Rückgabewert
Ist Methode erfolgreich, wird "S_OK" zurückgegeben. Andernfalls wird ein HRESULT-Fehlercode zurückgegeben.
Hinweise
This method writes the contents of the pb buffer to the stream, starting at the current stream position. The number of bytes that were written is returned in the pcbWritten parameter.
This method is synchronous. It blocks until the write operation completes.
This interface is available on the following platforms if the Windows Media Format 11 SDK redistributable components are installed:
- Windows XP mit Service Pack 2 (SP2) und höher.
- Windows XP Media Center Edition 2005 with KB900325 (Windows XP Media Center Edition 2005) and KB925766 (Oktober 2006 Updaterollup für Windows XP Media Center Edition) installed.
Beispiele
The following example writes data from a media buffer to a byte stream. For more information about media buffers, see Media Buffers.
//-------------------------------------------------------------------
// WriteBufferToByteStream
//
// Writes data from a media buffer to a byte stream.
//-------------------------------------------------------------------
HRESULT WriteBufferToByteStream(
IMFByteStream *pStream, // Pointer to the byte stream.
IMFMediaBuffer *pBuffer, // Pointer to the media buffer.
DWORD *pcbWritten // Receives the number of bytes written.
)
{
HRESULT hr = S_OK;
DWORD cbData = 0;
DWORD cbWritten = 0;
BYTE *pMem = NULL;
hr = pBuffer->Lock(&pMem, NULL, &cbData);
if (SUCCEEDED(hr))
{
hr = pStream->Write(pMem, cbData, &cbWritten);
}
if (SUCCEEDED(hr))
{
if (pcbWritten)
{
*pcbWritten = cbWritten;
}
}
if (pMem)
{
pBuffer->Unlock();
}
return hr;
}
The following function template writes a typed variable to a byte stream.
template <class T>
HRESULT WriteToStream(
IMFByteStream *pStream, // Pointer to the byte stream.
const T* p, // Data to write to the stream.
ULONG cb = sizeof(T) // Size of the data in bytes.
)
{
ULONG cbWritten = 0;
HRESULT hr = S_OK;
hr = pStream->Write((const BYTE*)p, cb, &cbWritten);
if (SUCCEEDED(hr) && (cbWritten != cb))
{
hr = E_FAIL;
}
return hr;
}
Anforderungen
Mindestens unterstützter Client |
Windows Vista |
Mindestens unterstützter Server |
Windows Server 2008 |
Header |
Mfobjects.h (include Mfidl.h) |
Bibliothek |
Mfuuid.lib |