shanselman/DirectShowLib-FORK — pull request #2 by OmerMor (2012-08-17 21:41:51+00:00)
Title: Adding CoClassAttribute for easier usage

There's a trick involving the CoClassAttribute that allows instantiating (COM) interfaces in .NET.
You can read about it here:
* http://ayende.com/blog/4121/instantiating-interfaces
* http://marcgravell.blogspot.co.il/2009/08/who-says-you-cant-instantiate-interface.html
* http://blogs.msdn.com/b/kirillosenkov/archive/2009/08/15/calling-new-on-an-interface.aspx

The trick can make the usage of this lib easier: you could instantiate the interface instead of the class, and save the need to cast it before you can call any methods on it.

Here is an example for changing one com class (StreamBufferSource):

```cs
///

/// CLSID_StreamBufferSource
///

[ComImport, Guid("C9F5FE02-F851-4eb5-99EE-AD602AF1E619")]
public class StreamBufferSourceImpl // used to be called StreamBufferSource
{
}

///

/// CLSID_StreamBufferSource
///

[ComImport]
[CoClass(typeof(StreamBufferSourceImpl))]
[Guid("C9F5FE02-F851-4eb5-99EE-AD602AF1E619")]
public interface StreamBufferSource : IAMFilterMiscFlags,
IBaseFilter,
IFileSourceFilter,
ISpecifyPropertyPages,
IStreamBufferMediaSeeking2,
IStreamBufferInitialize,
IStreamBufferSource,
ISBE2GlobalEvent,
ISBE2SpanningEvent,
ISBE2Crossbar
{
}

With this declaration in place, we can use it like this:

var source = new StreamBufferSource();
source.SetStreamSink(sink);

Notice there is no need to cast here. We also enjoy the power of intellisense with our coclass objects.

In this pull request I started adding co-classes (3 so far), hoping it'll drive someone (me?) to continue and adopt this for all the com objects in this library,