Previous | Next |
The GetMediaType method retrieves a WM_MEDIA_TYPE structure describing the media type.
Syntax
HRESULT GetMediaType(
WM_MEDIA_TYPE* pType,
DWORD* pcbType
);
Parameters
pType
[out] Pointer to a variable containing one member of the WM_MEDIA_TYPE enumeration type. For an exception to this, see the following Remarks section.
pcbType
[in, out] On input, specifies the size of the pType buffer. On output, and if the method succeeds, specifies a pointer to a count of the actual number of bytes in pType that are filled in by the method. For an exception to this, see the following Remarks section.
Return Values
If the method succeeds, it returns S_OK. If it fails, it returns an HRESULT error code.
Return code | Meaning |
E_INVALIDARG | The pcbType parameter is NULL. |
ASF_E_BUFFERTOOSMALL | The pcbType parameter is not large enough. |
Remarks
If the pType parameter is set to NULL, this method returns the size of the buffer required in the pcbType parameter. The following code shows the sequence of two calls to this method:
// First declare the necessary properties pointer and DWORD variable
IWMMediaProps *pProps;
DWORD cbtype;
// Make the first call to establish the size of buffer needed
pProps -> getMediaType(NULL, &cbtype);
// Now create a buffer of the appropriate size
BYTE *pBuf = new BYTE[cbtype];
// Create an appropriate structure pointer to the buffer
WM_MEDIA_TYPE *pType = (WM_MEDIA_TYPE*) *pBuf;
// Now call the method again to extract the information
pProps -> GetMediaType(pType,cbType);
This procedure is complex mainly because the format structure (pointed to by the pbFormat field in the WM_MEDIA_TYPE structure) is appended to the WM_MEDIA_TYPE structure returned by this call. This means that the size of the structure depends on the properties of the media stream, and a variable-sized buffer must be allocated to hold it.
See Also
Previous | Next |