我正在尝试使用opencv学习directshow和计算机视觉。但是为了保持代码更简洁,我想“收起”(创建一个类)我从互联网上借来的 directshow 代码。代码是: http ://alax.info/trac/public/browser/trunk/Utilities/SetLifeCamStudioResolutionSample/SetLifeCamStudioResolutionSample.cpp
好的。所以在我的 vc++ 项目中,我创建了一个新类。我称之为“directshowclass”,我有directshowclass.h & .cpp。
我遇到的问题是我无法弄清楚如何处理代码中的所有部分。
_tmain() 中的所有内容我都放在一个函数中。那个没问题。
但我该怎么办:
CComPtr<IPin> GetPin(IBaseFilter* pBaseFilter, SIZE_T nIndex = 0)
{
....
}
和:
#pragma region Formerly located in qedit.h in Windows SDK, now obsoleted and defined within project
struct __declspec(uuid("0579154a-2b53-4994-b0d0-e773148eff85"))
ISampleGrabberCB : IUnknown
{
//
// Raw methods provided by interface
//
virtual HRESULT __stdcall SampleCB (double SampleTime,struct IMediaSample * pSample ) = 0;
virtual HRESULT __stdcall BufferCB double SampleTime,unsigned char * pBuffer, long BufferLen ) = 0;
};
struct __declspec(uuid("6b652fff-11fe-4fce-92ad-0266b5d7c78f"))
ISampleGrabber : IUnknown
{
//
// Raw methods provided by interface
//
virtual HRESULT __stdcall SetOneShot (
long OneShot ) = 0;
virtual HRESULT __stdcall SetMediaType (
struct _AMMediaType * pType ) = 0;
virtual HRESULT __stdcall GetConnectedMediaType (
struct _AMMediaType * pType ) = 0;
virtual HRESULT __stdcall SetBufferSamples (
long BufferThem ) = 0;
virtual HRESULT __stdcall GetCurrentBuffer (
/*[in,out]*/ long * pBufferSize,
/*[out]*/ long * pBuffer ) = 0;
virtual HRESULT __stdcall GetCurrentSample (
/*[out,retval]*/ struct IMediaSample * * ppSample ) = 0;
virtual HRESULT __stdcall SetCallback (
struct ISampleGrabberCB * pCallback,
long WhichMethodToCallback ) = 0;
};
struct __declspec(uuid("c1f400a0-3f08-11d3-9f0b-006008039e37"))
SampleGrabber;
// [ default ] interface ISampleGrabber
#pragma endregion
#undef ATLENSURE_SUCCEEDED
#define ATLENSURE_SUCCEEDED(x) { HRESULT __a = (x); if(FAILED(__a)) { _tprintf(_T("Error 0x%08x in line %d\n"), __a, __LINE__); AtlThrow(__a); } }
如何在 .h 文件中声明它们?还有 .cpp 文件。