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 STDMETHODCALLTYPE 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!