Thursday, 24 January 2008

Using custom DShow filters without registering DLLs

If you are creating a media application or utility that requires a DMO or DShow filter but instead of having clunky separate dlls that may need code signing and/or registring with DShow, did you know that you can embed the filter within your main application.

For example for a source filter you can specify a new class and base it on the DShow components you require:

class MySourceFilter : public CSourceStream
{
public:
MySourceFilter( HRESULT* phr, LPCWSTR pName);
virtual ~MySourceFilter(void);

..
..
}

When you create your filtergraph you can use AddFilter to add an instance of your class:


// Create and add new source filter
m_source = new MySourceFilter(NULL, &hr);
hr = m_pGraph->AddFilter((IBaseFilter*)m_source, L"Source");


Simple as that!

You don't need to support the registration or have registry files to allow DShow to find your filter as you've explictly added it yourself.

4 comments:

Galen said...

Does any custom filter can be used like this?

GraemeW said...

Any filter can be used like this, the difference is that ones you specify will only be available to your application as they aren't registered in the system.

Anonymous said...

hello,
I am trying to develop a DirectShow application that utilises a custom TransInPlaceFilter. I understand that creating a standalone .dll filter will add to the complexity of the project, so I decided to embed the filter in the application. I am having problems, though, while instantiating the filter. Can you please provide a very simple .prj/.sln that depicts how to connect the filter with the Graph Manager?
Many thanks in advance.

GraemeW said...

To instantiate the filter you just new it and add it to the graph manager pointer, such as:

// Create and add new source filter
m_source = new MySourceFilter(NULL, &hr);
hr = m_pGraph->AddFilter((IBaseFilter*)m_source, L"Source");

What problems are you getting?

Cheers
Graeme