views:

217

answers:

2

Hi,

I have a custom DirectShow filter created by extending the ezrgb24 filter from the DirectShow sample documentation.

I am using this filter (indirectly) in C# through a 3rd party multimedia SDK (LeadTools). Now I need to add a reference to the filter's DLL to the project so that I can cast an IUnknown interface retrieved by the SDK to the filter's own custom interface.

I have tried adding the DLL reference through add reference -> browse, and by using tlbimp directly at the commandline. Both approaches result in the error 'C:\windows\system32\ezrgb24.dll' is not a valid type library.

Am I missing something? The extensions I have made to the ezrgb24 example are pretty trivial structurally, essentially if anyone has the DirectShow examples they know exactly the code I am working with.

Any and all help is greatly appreciated.

Tony.

A: 

The standard DirectShow filter samples do not implement IDispatch compatible interfaces. Furthermore, there are no type libraries in these dlls. You have to implement your own type library interface.

You can use ATL to do this.

Christopher
A: 

You need to write interface in C# and use ComImport attribute. For example sample filter from SDK will look

[ComImport,
InterfaceType(ComInterfaceType.InterfaceIsIUnknown), 
Guid("fd5010a3-8ebe-11ce-8183-00aa00577da1")] //guid defined for interface in example code
public interface IIPEffect
{
  [PreserveSig]
  int get_IPEffect(out int effectTime, out double startTime, out double length);

  [PreserveSig]
  int set_IPEffect(int effectNum, double startTime, double length);
}

Now you can use interface definition is such way

//find IBaseFilter somehow
var effectFilter = FindFilter() as IIPEffect;
effectFilter.set_IPEffect(0, 0, 20);

NOTE: in interface definition there is REFTIME type as parameter for length and startTime, but it is simple typedef and that's why in our code it is double. For more information on converting interface definition to C# you can read marshaling article on msdn

Yurec
thank you, this method has worked brilliantly for my purposes.
Tony Oldfield