gpt4 book ai didi

c++ - 为此 directshow 系统创建一个自定义类,无法弄清楚如何

转载 作者:行者123 更新时间:2023-11-28 03:17:04 29 4
gpt4 key购买 nike

我正在尝试使用 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 文件。

最佳答案

第二个片段 (#pragma region/endregion) 可以包含在项目中的任何 .h 中,对需要它的代码可见。

第一个片段是一个静态函数。您可以将它复制到您的一些类中,或者您可以在第一行的“CComPtr GetPin ...”之前添加“内联”说明符,然后再次将其保留在 .h 文件中。

关于c++ - 为此 directshow 系统创建一个自定义类,无法弄清楚如何,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16540895/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com