Share via


IWMSDataContainer::Read

banner art

Previous Next

IWMSDataContainer::Read

The server calls the Read method to read data from the data container into a buffer.

Syntax

  HRESULT Read(
  BYTE*  pbBuffer,
  QWORD  qwOffset,
  DWORD  dwMaxDataSize,
  DWORD  dwFlags,
  IWMSDataContainerCallback*  pCallback,
  QWORD  qwContext
);

Parameters

pbBuffer

[in] Pointer to a BYTE identifying the buffer to be filled with data from the data container.

qwOffset

[in] QWORD value specifying the offset in bytes from which the data should be read. This must be WMS_DATA_CONTAINER_NONSEEKABLE for data containers that do not support seeking. For example, a live source cannot be seekable, but a file can be.

dwMaxDataSize

[in] DWORD value specifying the maximum data size in bytes to be read from the data container.

dwFlags

[in] Reserved for future use.

pCallback

[in] Pointer to the IWMSDataContainerCallback interface. The plug-in calls IWMSDataContainerCallback::OnRead to respond to the server.

qwContext

[in] QWORD containing a value defined by the server to identify which Read request the plug-in is responding to when it calls IWMSDataContainerCallback::OnRead. The plug-in must pass this value back unaltered.

Return Values

If the method succeeds, the plug-in must return S_OK. To report an error, the plug-in can return any HRESULT other than S_OK. If the plug-in uses the IWMSEventLog interface to log error information directly to the Windows Event Viewer, it is recommended that it return NS_E_PLUGIN_ERROR_REPORTED. Typically, the server attempts to make plug-in error information available to the server object model, the Windows Event Viewer, and the troubleshooting list in the details pane of the Windows Media Services MMC. However, if the plug-in uses the IWMSEventLog interface to send custom error information to the Windows Event Viewer, returning NS_E_PLUGIN_ERROR_REPORTED stops the server from also logging to the event viewer. For more information about retrieving plug-in error information, see Identifying Plug-in Errors.

Example Code

The following example illustrates a possible implementation of a data source plug-in that reads from a file system.

HRESULT STDMETHODCALLTYPE 
CDataContainer::Read( 
                        BYTE *pbBuffer,
                        QWORD qwReadPosition,
                        DWORD dwMaxDataSize,
                        IWMSDataContainerCallback *pCallback,
                        QWORD qwContext
                        )
{
    HRESULT hr = S_OK;

    // If this data container is not open, then quit.
    if( ( INVALID_HANDLE_VALUE == m_hFile )
    {
        hr = E_UNEXPECTED;
        return ( hr );
    }

    // TODO: Allocate (not shown) and initialize an OVERLAPPED
    // structure. The pOverLapped variable is a pointer to
    // this structure. See the CreateFile() documentation in
    // the MSDN Library for more information.
    // If you opened the container by using the
    // FILE_FLAG_OVERLAPPED flag, an OVERLAPPED structure is 
    // required for a read operation.
    pOvrlp->Offset = LODWORD( qwReadPosition );
    pOvrlp->OffsetHigh = ( LONG ) HIDWORD( qwReadPosition );
    pOvrlp->hEvent = NULL;

    // Read the file.
    fSuccess = ReadFile( 
                    m_hFile, 
                    pbBuffer, 
                    dwMaxDataSize, 
                    m_dwBytesTransferred ),
                    ( LPOVERLAPPED ) pOvrlp
                    );

    return( hr );
}

Requirements

Header: datacontainer.h.

Library: WMSServerTypeLib.dll.

Platform: Windows Server 2003, Enterprise Edition; Windows Server 2003, Datacenter Edition; Windows Server 2008.

See Also

Previous Next