Reputation: 311
I'm currently writing a custom transform filter like shown in MSDN tutorial : http://msdn.microsoft.com/en-us/library/windows/desktop/dd391015%28v=vs.85%29.aspx .
It's written with my main DirectShow projet (I'm not making a DLL with the filter)
The problem is I dont know how to create/use the filter. I have tried the CoCreateInstance
SmartPtr<IFilterRotation> _pRotation = 0; // My custom filter
if(!SUCCEEDED(_mResult = CoCreateInstance(CLSID_FilterRotation, NULL, CLSCTX_INPROC, IID_IBaseFilter, (void**)&_pRotation)))
{
return _mResult;
}
But It returns the following error : REGDB_E_CLASSNOTREG
Here is all the elements I have override for the moment:
#pragma once
// {4A80F8B5-CFB0-4dc6-96C5-DA427B6DB8BD}
DEFINE_GUID(CLSID_FiltreRotation,
0x4a80f8b5, 0xcfb0, 0x4dc6, 0x96, 0xc5, 0xda, 0x42, 0x7b, 0x6d, 0xb8, 0xbd);
class IFilterRotation: public CTransformFilter
{
public:
IFilterRotation(void);
~IFilterRotation(void);
HRESULT IFilterRotation::CheckInputType(const CMediaType *vpMediaTypeIn);
HRESULT IFilterRotation::CheckTransform(const CMediaType *vpMediaTypeIn,
const CMediaType *vpMediaTypeOut);
HRESULT IFilterRotation::DecideBufferSize(IMemAllocator *vpAllocation,
ALLOCATOR_PROPERTIES *vppRequeteProprieteIn);
HRESULT IFilterRotation::GetMediaType(int vPosition,
CMediaType *vpMediaType);
HRESULT IFilterRotation::Transform(IMediaSample *vpMediaSampleIn,
IMediaSample *vpMediaSampleOut);
};
Am i missing something? Thanks in advance.
Upvotes: 1
Views: 684
Reputation: 69724
The logic chain is here as follows:
CoCreateInstance
takes CLSID_Xxx
CLSID_Xxx
needs to not only be defined, but should be also properly served by your project
CFactoryTemplate
instance mapping CLSID to your classYou can refer to one of the Windows SDK samples for details, I recommend EZRGB24
in particular.
You only show you have CLSID defined within the project. Class IFilterRotation
does not look good to me (you typically don't inherit I-thing from C-thing, but it's a naming matter though). You don't show if you have a CFactoryTemplate
, which I suppose you don't have.
However this all is true when you put your filter into DLL. In your case you don't seem to register COM class at all, so CoCreateInstance
does not work for you. Your options are either put the class into DLL, or CoRegisterClassObject
this class to enable its visibility for CoCreateInstance
, or create a simple C++ instance of the class (operator new or stack/static instance) which you then pass directly to AddFilter
.
Upvotes: 1
Reputation:
IFilterRotation should have private constructor and destructor, because it is a COM object (you want to prevent creating an instance on stack, or by calling new, because of reference counting.. you want to prevent destroying such object by calling delete as well). It will destroy itself once the reference count drops to zero. Add static method for creating an instance of IFilterRotation.
static IFilterRotation * createInstance()
{
IFilterRotation * const pFilterRotation( new (std::nothrow) IFilterRotation() );
if( pFilterRotation )
pFilterRotation->AddRef();
return pFilterRotation;
}
You can use CoCreateInstance()
only if you have your filter as a separate DLL. Of course, you also have to register such DLL before using CoCreateInstance()
.
Upvotes: 1