A special "COM Interop" edition of "What's Wrong with this code?"

This code is using some Windows Media interfaces to get the properties from a profile.

IWMMediaProps::GetMediaType() gets a _WMMediaType structure. Because there is optional format data that comes back, you have to call the method once to get the size, then again to get the actual data. You can assume that that extra data is a WAVEFORMATEX structure. In the C# world, the pbFormat field in _WMMediaType is an IntPtr.

Here's the code. There's something bad lurking there. I think I've given you enough information to figure it out.

IWMStreamConfig iStreamConfig = ...;   // set somewhere else...
DirectShow.IWMMediaProps mediaProperties = (DirectShow.IWMMediaProps) iStreamConfig;

uint typeSize = 0;
mediaProperties.GetMediaType(null, ref typeSize);  // call to get size

byte[] buffer = new byte[typeSize];
mediaProperties.GetMediaType(buffer, ref typeSize); // call to fetch values

fixed (byte* pBuffer = buffer)
    mediaType = *((DirectShow._WMMediaType*) pBuffer);
    waveFormatEx = *((DirectShow.WAVEFORMATEX*) (mediaType.pbFormat.ToPointer()));