|
//
// COMAutoPtrWrapper module
// ------------------------
//
// Provides a simple wrapper around various/known COM smart pointers and raw
// interface pointers to provide a single interface.
// (currently provides only the minimum required for the Wasiona project)
//
////////////////////////////////////////////////////////////////////////////////
#pragma once
#ifdef TINY_ATL
// (todo) this is duplicated from WTL.h (remove the duplication).
#define ATLENSURE ATLVERIFY
#define AtlThrow exit
#endif
#define _WIN32_DCOM // Required to be able to use COM.
// "Native" _com_ptr_t<>.
#include "comip.h"
#include "comdef.h"
// ATL::CComPtr<>.
#include "atlcomcli.h"
#include <type_traits>
////////////////////////////////////////////////////////////////////////////////
//
// COMAutoPtrWrapper
// -----------------
//
// (todo) add a "direct" getter for the BaseCOMInterface (which bypasses any
// BaseCOMPtr checks).
//
////////////////////////////////////////////////////////////////////////////////
template <class BaseCOMPtr, class BaseCOMInterface>
class COMAutoPtrWrapper
{
public:
COMAutoPtrWrapper() : baseCOMPtr_() {}
COMAutoPtrWrapper( BaseCOMPtr const * const baseCOMPtr ) : baseCOMPtr_( baseCOMPtr ) { addRefIfNecessary(); }
COMAutoPtrWrapper( COMAutoPtrWrapper const & source ) : baseCOMPtr_( source.baseCOMPtr_ ) { addRefIfNecessary(); }
~COMAutoPtrWrapper() { releaseIfNecessary(); }
BaseCOMInterface & operator *() const;
BaseCOMInterface * operator->() const { return &operator*(); }
COMAutoPtrWrapper & operator=( COMAutoPtrWrapper const & other );
unsigned long release();
static COMAutoPtrWrapper createInstance( REFCLSID rclsid, REFIID riid, DWORD dwClsContext = CLSCTX_INPROC_SERVER );
BaseCOMPtr & base() { return baseCOMPtr_; }
typedef BaseCOMInterface * (COMAutoPtrWrapper::*unspecified_bool_type)() const;
operator unspecified_bool_type() const { return baseCOMPtr_ ? &COMAutoPtrWrapper::operator-> : 0; }
private:
void addRefIfNecessary();
void releaseIfNecessary();
private:
BaseCOMPtr baseCOMPtr_;
};
#include "COMSmartPTrWrapper.inl"
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.