Discussion:
Creating internal filter
(too old to reply)
Cheyne
2006-02-01 22:25:21 UTC
Permalink
I have an embedded filter that I can access directly.
Is it possible to create an instance of it without having to use the registry?
Currently I register it and create it using CoCreateInstance.

How can I create it internally?
What steps do I need to take to create it and assign it an interface to
access it by?

I have tried the following but it quits during the QueryInterface call

IBaseFilter *pSourceBase;
IUnknown *pSourceUnknown;
HRESULT hr = E_ABORT;

CUnknown *foo = CAsyncFilter::CreateInstance(pSourceUnknown, &hr);
if (hr != S_OK){
fprintf(log,"CreateInstance failed: HRESULT is %ld\n", hr);
fflush(log);
return hr;
}

//Query additional intefaces
// this does not work - it did work when I used CoCreateInstance
// the program exits here during the QueryInterface call
hr = pSourceUnknown->QueryInterface(IID_IBaseFilter, (void **)&pSourceBase);
if (hr != S_OK){
fprintf(log,"IID_IBaseFilter HRESULTS is %ld\n", hr);
fflush(log);
return hr;
}


// filter code snippit
CUnknown* CAsyncFilter::CreateInstance(LPUNKNOWN pUnk, HRESULT *phr)
{
return new CAsyncFilter(pUnk, phr);
}

//constructor
CAsyncFilter::CAsyncFilter(LPUNKNOWN pUnk, HRESULT *phr) :
CAsyncReader(NAME("Mem Reader"), pUnk, &m_Stream, phr)
{
}
Cheyne
2006-02-01 22:44:07 UTC
Permalink
I just found the value of pSourceUnknown is 0 after CreteInstance is call.
Obviously that this my problem, but how do I fix it?
Chris P. [MVP]
2006-02-01 23:12:53 UTC
Permalink
Post by Cheyne
I just found the value of pSourceUnknown is 0 after CreteInstance is call.
Obviously that this my problem, but how do I fix it?
Instead of using CreateInstance, do a new.

CMyFilter *pMyFilter = new CMyFilter;
Cheyne
2006-02-01 23:47:30 UTC
Permalink
I tried that but I still have the same problem.
Is the cause my contructor? I assume that is is meant to initialize the
interface, but it doesn't appear to do it.
Post by Chris P. [MVP]
Post by Cheyne
I just found the value of pSourceUnknown is 0 after CreteInstance is call.
Obviously that this my problem, but how do I fix it?
Instead of using CreateInstance, do a new.
CMyFilter *pMyFilter = new CMyFilter;
Cheyne
2006-02-02 01:06:27 UTC
Permalink
I used the code:
// ICustomSourceFilter is a custom interface that
// I wrote for CAsyncFilter (from the Directshow samples)

ICustomSourceFilter *pSourceFilter
pSourceFilter = new CAsyncFilter(0, &hr);

This works fine now
Thanx for your help Chris
Post by Chris P. [MVP]
Post by Cheyne
I just found the value of pSourceUnknown is 0 after CreteInstance is call.
Obviously that this my problem, but how do I fix it?
Instead of using CreateInstance, do a new.
CMyFilter *pMyFilter = new CMyFilter;
Geraint Davies
2006-02-02 10:05:43 UTC
Permalink
Post by Cheyne
// ICustomSourceFilter is a custom interface that
// I wrote for CAsyncFilter (from the Directshow samples)
ICustomSourceFilter *pSourceFilter
pSourceFilter = new CAsyncFilter(0, &hr);
This works fine now
Thanx for your help Chris
remember to addref it immediately, and to destroy it with ->Release, not
delete. The easiest way to do this would be a smart pointe
ICustomSourceFilterPtr pSourceFilter = new CAsyncFilter(0, &hr);

G
Cheyne
2006-02-02 19:59:03 UTC
Permalink
I woke up this morning and remembered that I hadn't called Addref.
Cheers for the reminder.
Post by Geraint Davies
remember to addref it immediately, and to destroy it with ->Release, not
delete. The easiest way to do this would be a smart pointe
ICustomSourceFilterPtr pSourceFilter = new CAsyncFilter(0, &hr);
G
vanselm
2012-01-09 13:43:39 UTC
Permalink
Hello,

I was looking for some example, where a filter can be used, without to register it to the system. Finally, I have found this article: (http://msdn.microsoft.com/en-us/library/ms787698.aspx)

"Also, filters do not have to be packaged inside DLLs. In some cases, you might write a specialized filter that is designed only for a specific application. In that case, you can compile the filter class directly in your application, and create it with the new operator, as shown in the following example:"

#include "MyFilter.h" // Header file that declares the filter class.
// Compile and link MyFilter.cpp.
int main()
{
IBaseFilter *pFilter = 0;
{
// Scope to hide pF.
CMyFilter* pF = new MyFilter();
if (!pF)
{
printf("Could not create MyFilter.\n");
return 1;
}
pF->QueryInterface(IID_IBaseFilter,
reinterpret_cast<void**>(&pFilter));
}

/* Now use pFilter as normal. */

pFilter->Release(); // Deletes the filter.
return 0;
}

So I have found an example for a transform filter and modified it, removing the COM registration stuff and applied the code above. It works!

best regards,

Vitali

Loading...