|
This post originated from an RSS feed registered with .NET Buzz
by Eric Gunnerson.
|
Original Post: What's wrong with this code (COM Interop)?
Feed Title: Eric Gunnerson's C# Compendium
Feed URL: /msdnerror.htm?aspxerrorpath=/ericgu/Rss.aspx
Feed Description: Eric comments on C#, programming and dotnet in general, and the aerodynamic characteristics of the red-nosed flying squirrel of the Lesser Antilles
|
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Eric Gunnerson
Latest Posts From Eric Gunnerson's C# Compendium
|
|
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())); }
Read: What's wrong with this code (COM Interop)?
|