CreateAudioMediaType 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 CreateAudioMediaType function initializes a media type from a WAVEFORMATEX structure.


HRESULT STDAPI CreateAudioMediaType(
   const WAVEFORMATEX  *pwfx,
         AM_MEDIA_TYPE *pmt,
         BOOL          bSetFormat



Pointer to the supplied WAVEFORMATEX structure.


Pointer to the AM_MEDIA_TYPE structure to initialize.


Flag indicating whether to initialize the format block. Specify TRUE to initialize it, or FALSE otherwise.

Return value

Returns E_OUTOFMEMORY if memory could not be allocated for the format data; S_OK otherwise.


If the bSetFormat parameter is TRUE, the method allocates the memory for the format block. If the pmt parameter already contains an allocated format block, a memory leak will occur. To avoid a memory leak, call FreeMediaType before calling this function. After the method returns, call FreeMediaType again to free the format block.


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

See also

Media Type Functions