如何将 Qedit.h 从 DirectShow 包含到项目中?

How to include Qedit.h from DirectShow to project?

我需要实现这个接口ISampleGrabber

https://docs.microsoft.com/en-us/windows/win32/directshow/isamplegrabber

据我了解这个文件应该在Windows SDK中,所以我从Visual Studio安装程序

下载了Windows SDK

但我还是得到 Cannot open source file

我做错了什么?

编辑

通过上面页面给出的 link 我下载了这样的文件 winsdk_web.exe 当我尝试安装它时我得到这样的弹出窗口

根据这个弹出消息,我需要从这个 link

安装 .NET Framework 4.0

http://go.microsoft.com/fwlink/?LinkID=187668

所以,我下载了这个文件并尝试安装它,但收到了另一条消息

这里有什么问题?

编辑

我是 C++ 的新手,但对我来说它看起来很奇怪:) 就像你有一个文档,其中写着为了做某事你需要使用特定的接口,但你几乎找不到这个接口任何地方,但在这里你可以下载 sdk,但最终这一切都无济于事,唯一的解决办法是添加这段代码,很好:)

#pragma once

#include <dshow.h>
#include <dvdmedia.h>
#include <dmodshow.h>

class __declspec(uuid("{C1F400A4-3F08-11D3-9F0B-006008039E37}")) NullRenderer;
class __declspec(uuid("{C1F400A0-3F08-11D3-9F0B-006008039E37}")) SampleGrabber;

#pragma region SampleGrabber

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

class TV_AudioDecoder : public ISampleGrabber
{
public:
    TV_AudioDecoder();
    ~TV_AudioDecoder();

public:
    virtual HRESULT __stdcall SetOneShot(long OneShot) override;
    virtual HRESULT __stdcall SetMediaType(struct _AMMediaType * pType) override;
    virtual HRESULT __stdcall GetConnectedMediaType(struct _AMMediaType * pType) override;
    virtual HRESULT __stdcall SetBufferSamples(long BufferThem) override;
    virtual HRESULT __stdcall GetCurrentBuffer(/*[in,out]*/ long * pBufferSize, /*[out]*/ long * pBuffer) override;
    virtual HRESULT __stdcall GetCurrentSample(/*[out,retval]*/ struct IMediaSample * * ppSample) override;
    virtual HRESULT __stdcall SetCallback(struct ISampleGrabberCB * pCallback, long WhichMethodToCallback) override;
};

假设这是我的代码,使用它是否正确?我没有遗漏什么?

Qedit.h 在过去的某个时候因弃用 DirectShow 编辑服务而被排除在 Windows SDK 之外。从那时起,Windows 的所有版本中仍然存在运行时。

您不需要安装任何东西,反之亦然,安装古老的 SDK 不会让您的生活变得更轻松。

只需 copy/paste 必要 headers 到您的项目中,您就可以开始了。

copy/paste 中提到的内容,例如 this 2009 topic。您可以通过 #import 找到我的答案,它也应该有效。截至 2020 年,我仍然建议 copy/pasting 缺少 headers。

UPD.

// <your regular includes>

#include <dshow.h>
#include <dvdmedia.h>
#include <dmodshow.h>

class __declspec(uuid("{C1F400A4-3F08-11D3-9F0B-006008039E37}")) NullRenderer;
class __declspec(uuid("{C1F400A0-3F08-11D3-9F0B-006008039E37}")) SampleGrabber;

#pragma region SampleGrabber

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

// <your code>

另请参阅:

I am new in C++, but it looks weird for me:) [...]

它不完全是关于 C++ 的。它是关于如何通过重新引入从标准 SDK 中删除的声明来在 C++ 项目中使用废弃的 OS 部分。是的,在 C++ 中我们可以做到,还有其他很酷的技巧。