IMFSourceReaderCallback: base class undefined

倾然丶 夕夏残阳落幕 提交于 2019-12-24 17:02:06

问题


I am having some trouble reading samples from a video camera via Media Foundation. I am following the example in the windows SDK samples folder MFCaptureToFile.

My class is set up correctly to inherit from the abstract IMFSourceReaderCallback class, as far as I can tell:

#include <windows.h>
#include <mfapi.h>
#include <mfidl.h>
#include <mfreadwrite.h>

class WinCapture : public IMFSourceReaderCallback{

public:

    static HRESULT CreateInstance(
        std::string deviceName,
        WinCapture **winCapture 
        );

    // IUnknown methods
    STDMETHODIMP QueryInterface(REFIID iid, void** ppv);
    STDMETHODIMP_(ULONG) AddRef();
    STDMETHODIMP_(ULONG) Release();

    // IMFSourceReaderCallback methods
    STDMETHODIMP OnReadSample(
        HRESULT hrStatus,
        DWORD dwStreamIndex,
        DWORD dwStreamFlags,
        LONGLONG llTimestamp,
        IMFSample *pSample
        );

    STDMETHODIMP OnEvent(DWORD, IMFMediaEvent *)
    {
        return S_OK;
    }

    STDMETHODIMP OnFlush(DWORD)
    {
        return S_OK;
    }

}

If I compile this code on its own, it compiles fine. However, if I wish to use this class in a larger project it gives me the error. Is there something about how I am including winCapture.h in the other files that is tossing this error? Why will it compile on its own but not in the context of a larger project?

I guess there is a circular dependency going on, but I'm not sure how to track this down. It certainly doesn't appear to be of my own making, it's more likely hidden withing included headers somewhere.


回答1:


The solution seems to be to use

#define WIN32_LEAN_AND_MEAN

in the header file and to move all includes of this header to the top of any #include directives in any other files that include it. This code now compiles both stand alone, and in the context of a larger project.



来源:https://stackoverflow.com/questions/37998380/imfsourcereadercallback-base-class-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!