The Artima Developer Community
Sponsored Link

.NET Buzz Forum
What's wrong with this code (COM Interop)?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Eric Gunnerson

Posts: 1006
Nickname: ericgu
Registered: Aug, 2003

Eric Gunnerson is a program manager on the Visual C# team
What's wrong with this code (COM Interop)? Posted: Sep 29, 2004 11:01 PM
Reply to this message Reply

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

Advertisement

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)?

Topic: Great WinForms and GDI+ Tricks for spiffing up your application Previous Topic   Next Topic Topic: Mediterranean Medley

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use