February 23, 2008

Sample code for IWMMediaProps::GetMediaType()

// Get the required buffer size
DWORD cbType = 0;
pWMMediaProps->GetMediaType(NULL, &cbType);

// Get media type
WM_MEDIA_TYPE* pType = (WM_MEDIA_TYPE*)new BYTE[cbType];
if(SUCCEEDED(pWMMediaProps->GetMediaType(pType, &cbType)))
{
  // Use media type here
  // ...
}

// Free buffer
// Should not use "delete [] pType", we have to cast it to (BYTE*) before delete it.
delete [] (BYTE*)pType;