Remove ATL dependency from MSMF capture code

Use _com_ptr_t instead of CComPtr in ComPtr wrapper to avoid ATL dependency.
This commit is contained in:
Artur Wieczorek 2014-09-23 19:31:55 +02:00
parent a160158cb3
commit e3f1d722e7
2 changed files with 83 additions and 34 deletions

View File

@ -72,6 +72,7 @@
#include <stdarg.h>
#include <string.h>
#ifdef _MSC_VER
#pragma warning(disable:4503)
#pragma comment(lib, "mfplat")
#pragma comment(lib, "mf")
@ -81,6 +82,7 @@
#if (WINVER >= 0x0602) // Available since Win 8
#pragma comment(lib, "MinCore_Downlevel")
#endif
#endif
#include <mferror.h>
@ -260,7 +262,7 @@ public:
#include "ppltasks_winrt.h"
#endif
#else
#include <atlbase.h>
#include <comdef.h>
#endif
struct IMFMediaType;

View File

@ -600,27 +600,65 @@ hr = orig.As(&obj);
#define _ComPtr Microsoft::WRL::ComPtr
#else
#define _COM_SMARTPTR_DECLARE(T,var) T ## Ptr var
template <class T>
class ComPtr : public ATL::CComPtr<T>
class ComPtr
{
public:
ComPtr() throw()
{
}
ComPtr(int nNull) throw() :
CComPtr<T>((T*)nNull)
ComPtr(int nNull) throw()
{
assert(nNull == 0);
p = NULL;
}
ComPtr(T* lp) throw()
{
p = lp;
}
ComPtr(_In_ const ComPtr<T>& lp) throw()
{
p = lp.p;
}
virtual ~ComPtr()
{
}
ComPtr(T* lp) throw() :
CComPtr<T>(lp)
T** operator&() throw()
{
assert(p == NULL);
return p.operator&();
}
ComPtr(_In_ const CComPtr<T>& lp) throw() :
CComPtr<T>(lp.p)
T* operator->() const throw()
{
assert(p != NULL);
return p.operator->();
}
bool operator!() const throw()
{
return p.operator==(NULL);
}
bool operator==(_In_opt_ T* pT) const throw()
{
return p.operator==(pT);
}
// For comparison to NULL
bool operator==(int nNull) const
{
assert(nNull == 0);
return p.operator==(NULL);
}
bool operator!=(_In_opt_ T* pT) const throw()
{
return p.operator!=(pT);
}
operator bool()
{
return p.operator!=(NULL);
}
virtual ~ComPtr() {}
T* const* GetAddressOf() const throw()
{
@ -634,7 +672,7 @@ public:
T** ReleaseAndGetAddressOf() throw()
{
InternalRelease();
p.Release();
return &p;
}
@ -642,27 +680,38 @@ public:
{
return p;
}
ComPtr& operator=(decltype(__nullptr)) throw()
// Attach to an existing interface (does not AddRef)
void Attach(_In_opt_ T* p2) throw()
{
InternalRelease();
return *this;
p.Attach(p2);
}
ComPtr& operator=(_In_ const int nNull) throw()
// Detach the interface (does not Release)
T* Detach() throw()
{
ASSERT(nNull == 0);
(void)nNull;
InternalRelease();
return *this;
return p.Detach();
}
unsigned long Reset()
_Check_return_ HRESULT CopyTo(_Deref_out_opt_ T** ppT) throw()
{
return InternalRelease();
assert(ppT != NULL);
if (ppT == NULL)
return E_POINTER;
*ppT = p;
if (p != NULL)
p->AddRef();
return S_OK;
}
void Reset()
{
p.Release();
}
// query for U interface
template<typename U>
HRESULT As(_Inout_ U** lp) const throw()
{
return p->QueryInterface(__uuidof(U), (void**)lp);
return p->QueryInterface(__uuidof(U), reinterpret_cast<void**>(lp));
}
// query for U interface
template<typename U>
@ -671,19 +720,8 @@ public:
return p->QueryInterface(__uuidof(U), reinterpret_cast<void**>(lp->ReleaseAndGetAddressOf()));
}
private:
unsigned long InternalRelease() throw()
{
unsigned long ref = 0;
T* temp = p;
if (temp != nullptr)
{
p = nullptr;
ref = temp->Release();
}
return ref;
}
_COM_SMARTPTR_TYPEDEF(T, __uuidof(T));
_COM_SMARTPTR_DECLARE(T, p);
};
#define _ComPtr ComPtr
@ -2262,6 +2300,11 @@ public:
// succeed but return a nullptr pointer. By default, the list does not allow nullptr
// pointers.
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4127) // constant expression
#endif
template <class T, bool NULLABLE = FALSE>
class ComPtrList : public List<T*>
{
@ -2352,6 +2395,10 @@ protected:
}
};
#ifdef _MSC_VER
#pragma warning(pop)
#endif
/* Be sure to declare webcam device capability in manifest
For better media capture support, add the following snippet with correct module name to the project manifest
(highgui needs DLL activation class factoryentry points):