Reputation: 1563
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.
Upvotes: 1
Views: 715
Reputation: 1563
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.
Upvotes: 1