Why does VC2008 think this class is abstract?
I'm writing some code to handle video input from some cameras using DirectShow, so I have to implement ISampleGrabberCB.
My class that implements the interface compiles okay, but when I try to instantiate it the compiler raises "error C2259: 'SampleGrabberCB' : cannot instantiate abstract class".
Here is the interface I'm implementing:
interface ISampleGrabberCB : public IUnknown {
virtual STDMETHODIMP SampleCB( double SampleTime, IMediaSample *pSample ) = 0;
virtual STDMETHODIMP BufferCB( double SampleTime, BYTE *pBuffer, long BufferLen ) = 0;
};
Here is my SampleGrabberCB header:
#pragma once
#include "stdafx.h"
class SampleGrabberCB : public ISampleGrabberCB {
private:
int _refCount;
DShowCaptureDevice* _parent;
public:
// SampleGrabberCB();
SampleGrabberCB(DShowCaptureDevice* parent);
~SampleGrabberCB();
virtual STDMETHODIMP BufferCB(double sampleTime, BYTE* pBuffer, long bufferLen);
virtual STDMETHODIMP SampleCB(double sampleTime, IMediaSample * pSample, long bufferLen);
#pragma region IUnknown
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppv) {
if( riid == IID_ISampleGrabberCB || riid == IID_IUnknown ) {
*ppv = (void *) static_cast<ISampleGrabberCB*> ( this );
return NOERROR;
}
return E_NOINTERFACE;
}
virtual ULONG STDMETHODCALLTYPE AddRef() {
return ++_refCount;
}
virtual ULONG STDME开发者_高级运维THODCALLTYPE Release() {
int n = --_refCount;
if (n <= 0) {
delete this;
}
return n;
}
#pragma endregion
};
and this is the implementation SampleGrabberCB.cpp:
#include "StdAfx.h"
#include "SampleGrabberCB.h"
//SampleGrabberCB::SampleGrabberCB() {
// _parent = NULL;
//}
SampleGrabberCB::SampleGrabberCB(DShowCaptureDevice* parent) {
_parent = parent;
}
SampleGrabberCB::~SampleGrabberCB() {
}
STDMETHODIMP SampleGrabberCB::BufferCB(double sampleTime, BYTE *pBuffer, long bufferLen) {
// dummy value for now
return -50;
}
STDMETHODIMP SampleGrabberCB::SampleCB(double sampleTime, IMediaSample *pSample, long bufferLen) {
// dummy value for now
return 100;
}
Here is how I'm using it:
SampleGrabberCB* callback = new SampleGrabberCB(device);
Any ideas? Thanks!
SampleCB as declared in the interface doesn't have the third parameter (bufferLen) that is present in the SampleGrabberCB class.
Your SampleCB method doesn't match the method in the base (abstract) class.
STDMETHODIMP SampleGrabberCB::SampleCB(double sampleTime, IMediaSample *pSample, long bufferLen)
versus
virtual STDMETHODIMP SampleCB( double SampleTime, IMediaSample *pSample ) = 0;
The signature of your virtual STDMETHODIMP SampleCB(double sampleTime, IMediaSample * pSample, long bufferLen) method doesn't matcht that of the pure virtual mether in the Interface - you need to drop the bufferlen argument.
It looks like the method signature is different in SampleCB method. On case has 2 parameters and the other 3 parameters.
加载中,请稍侯......
精彩评论