Using DirectShow C ++ API with C # (COM component)

I am developing a Windwos form application using Directshow. In the beginning, I used Quarts.dll located in windows / system32 to get the basic Directshow API. After a while, I realized that I needed the entire Directshow API because I needed to create a new video ad filter (VM7). To do this, I need to have access to some of the interfaces provided in the DirectShow C ++ API. I found that Directshow is a COM component, and I can access its API in C # if I find the right way to link it.

Now this is what I did to access the API:

I found out that the C ++ API is provided in the Windows SDK. I need an API located in devenum.idl, axcore.idl and axextend.idl.

These are language interface description files, and I found out that I can use midl.exe via cmd to create a .tlb file (typelib), now I can use the file to access the interfaces I need, But to use the midl compiler I needed to create a new .idl file containing the interfaces I need, it looks like this:

import "devenum.idl"; import "axcore.idl"; import "axextend.idl"; [ uuid(A68F9934-FDB9-4AAE-A631-F9307171B2FA), helpstring("DirectShow interfaces") ] library DirectShow { interface IFilterGraph; interface ICreateDevEnum; interface IGraphBuilder; interface ICaptureGraphBuilder2; interface IFileSinkFilter; interface IFileSinkFilter2; interface IAMAudioInputMixer; }; 

This is necessary to create a new guid.

After that, I was able to run midl and create a .tlb file. But when I tried to add a link to the .tlb file, it gave an error.

I found a way to create a DLL file from this .tlb file by running tlbimp.exe via cmd in the .tlb file. He created a .dll that I managed to add to my project. Visual Studio now knows how to interact with all the interfaces I tried to get.

But for the problem I'm facing right now:

At runtime, I get this error:

Fetching the factory COM class for a component with CLSID {56A868A9-0AD4-11CE-B03A-0020AF0BA770} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

I see that the clsid component of the problem is not the clsid library in the .idl file that I created, this may indicate that the problem is with the imported files that I use, maybe a bad guide in these files

I also think that the problem may be that the .dll is not registered on my system. I tried using regsvr32, but it gave me an error:

The module "directshow.dll" was loaded, but the entry point DLLRegisterServer was not found ...

Now, please save me and tell me how to fix the problem or offer me another solution for using the C ++ API Directshow through C #.

+4
source share
1 answer

It will be difficult for you to associate the DirectShow API directly with C # code. Fortunately, this work has already been completed and is available as the DirectShow.NET Library . It comes with all the necessary links and sample projects.

In particular, this error

Getting the factory COM class for a component with CLSID {56A868A9-0AD4-11CE-B03A-0020AF0BA770} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

reports that you are trying to use the IGraphBuilder IID as the CLSID class identifier. This is not expected to work.

+3
source

Source: https://habr.com/ru/post/1436573/


All Articles