DeleteMediaType function

[The feature associated with this page, DirectShow, is a legacy feature. It has been superseded by MediaPlayer, IMFMediaEngine, and Audio/Video Capture in Media Foundation. Those features have been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use MediaPlayer, IMFMediaEngine and Audio/Video Capture in Media Foundation instead of DirectShow, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

The DeleteMediaType function deletes an allocated AM_MEDIA_TYPE structure, including the format block.

Syntax

void WINAPI DeleteMediaType(
   AM_MEDIA_TYPE *pmt
);

Parameters

pmt

A pointer to an AM_MEDIA_TYPE structure.

Return value

This function does not return a value.

Remarks

Use this function to release any media type structure that was allocated using either CoTaskMemAlloc or CreateMediaType.

This function is defined in the DirectShow Base Classes library. If you prefer not to link to the base class library, you can use the following code:

// Release the format block for a media type.

void _FreeMediaType(AM_MEDIA_TYPE& mt)
{
    if (mt.cbFormat != 0)
    {
        CoTaskMemFree((PVOID)mt.pbFormat);
        mt.cbFormat = 0;
        mt.pbFormat = NULL;
    }
    if (mt.pUnk != NULL)
    {
        // pUnk should not be used.
        mt.pUnk->Release();
        mt.pUnk = NULL;
    }
}


// Delete a media type structure that was allocated on the heap.
void _DeleteMediaType(AM_MEDIA_TYPE *pmt)
{
    if (pmt != NULL)
    {
        _FreeMediaType(*pmt); 
        CoTaskMemFree(pmt);
    }
}

Requirements

Requirement Value
Header
Mtype.h (include Streams.h)
Library
Strmbase.lib (retail builds);
Strmbasd.lib (debug builds)

See also

FreeMediaType

Media Type Functions