STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
_com_ptr_t< _IIID > Class Template Reference

#include <comip.h>

Public Types

typedef _IIID ThisIIID
 
typedef _IIID::Interface Interface
 

Public Member Functions

template<typename _OtherIID >
 _com_ptr_t (const _com_ptr_t< _OtherIID > &p)
 
template<typename _InterfaceType >
 _com_ptr_t (_InterfaceType *p)
 
template<>
 _com_ptr_t (_In_ LPSTR str)
 
template<>
 _com_ptr_t (_In_ LPWSTR str)
 
template<>
 _com_ptr_t (_com_ptr_t *p)
 
 _com_ptr_t () throw ()
 
 _com_ptr_t (int null)
 
 _com_ptr_t (const _com_ptr_t &cp) throw ()
 
 _com_ptr_t (_com_ptr_t &&cp) throw ()
 
template<>
 _com_ptr_t (Interface *pInterface) throw ()
 
 _com_ptr_t (Interface *pInterface, bool fAddRef) throw ()
 
 _com_ptr_t (const _variant_t &varSrc)
 
 _com_ptr_t (const CLSID &clsid, IUnknown *pOuter=NULL, DWORD dwClsContext=CLSCTX_ALL)
 
 _com_ptr_t (LPCWSTR str, IUnknown *pOuter=NULL, DWORD dwClsContext=CLSCTX_ALL)
 
 _com_ptr_t (LPCSTR str, IUnknown *pOuter=NULL, DWORD dwClsContext=CLSCTX_ALL)
 
template<typename _OtherIID >
_com_ptr_toperator= (const _com_ptr_t< _OtherIID > &p)
 
template<typename _InterfaceType >
_com_ptr_toperator= (_InterfaceType *p)
 
template<>
_com_ptr_toperator= (Interface *pInterface) throw ()
 
_com_ptr_toperator= (const _com_ptr_t &cp) throw ()
 
_com_ptr_toperator= (_com_ptr_t &&cp) throw ()
 
_com_ptr_toperator= (int null)
 
_com_ptr_toperator= (const _variant_t &varSrc)
 
 ~_com_ptr_t () throw ()
 
void Attach (Interface *pInterface) throw ()
 
void Attach (Interface *pInterface, bool fAddRef) throw ()
 
InterfaceDetach () throw ()
 
 operator Interface * () const throw ()
 
 operator Interface & () const
 
Interfaceoperator* () const
 
Interface ** operator& () throw ()
 
Interfaceoperator-> () const
 
 operator bool () const throw ()
 
template<typename _OtherIID >
bool operator== (const _com_ptr_t< _OtherIID > &p) const
 
template<typename _InterfaceType >
bool operator== (_InterfaceType *p) const
 
template<>
bool operator== (Interface *p) const
 
template<>
bool operator== (const _com_ptr_t &p) const throw ()
 
bool operator== (int null) const
 
template<typename _OtherIID >
bool operator!= (const _com_ptr_t< _OtherIID > &p) const
 
template<typename _InterfaceType >
bool operator!= (_InterfaceType *p) const
 
bool operator!= (int null) const
 
template<typename _OtherIID >
bool operator< (const _com_ptr_t< _OtherIID > &p) const
 
template<typename _InterfaceType >
bool operator< (_InterfaceType *p) const
 
template<typename _OtherIID >
bool operator> (const _com_ptr_t< _OtherIID > &p) const
 
template<typename _InterfaceType >
bool operator> (_InterfaceType *p) const
 
template<typename _OtherIID >
bool operator<= (const _com_ptr_t< _OtherIID > &p) const
 
template<typename _InterfaceType >
bool operator<= (_InterfaceType *p) const
 
template<typename _OtherIID >
bool operator>= (const _com_ptr_t< _OtherIID > &p) const
 
template<typename _InterfaceType >
bool operator>= (_InterfaceType *p) const
 
void Release ()
 
void AddRef ()
 
InterfaceGetInterfacePtr () const throw ()
 
Interface *& GetInterfacePtr () throw ()
 
HRESULT CreateInstance (const CLSID &rclsid, IUnknown *pOuter=NULL, DWORD dwClsContext=CLSCTX_ALL) throw ()
 
HRESULT CreateInstance (LPCWSTR clsidString, IUnknown *pOuter=NULL, DWORD dwClsContext=CLSCTX_ALL) throw ()
 
HRESULT CreateInstance (LPCSTR clsidStringA, IUnknown *pOuter=NULL, DWORD dwClsContext=CLSCTX_ALL) throw ()
 
HRESULT GetActiveObject (const CLSID &rclsid) throw ()
 
HRESULT GetActiveObject (LPCWSTR clsidString) throw ()
 
HRESULT GetActiveObject (LPCSTR clsidStringA) throw ()
 
template<typename _InterfaceType >
HRESULT QueryInterface (const IID &iid, _InterfaceType *&p) throw ()
 
template<typename _InterfaceType >
HRESULT QueryInterface (const IID &iid, _InterfaceType **p) throw ()
 

Static Public Member Functions

static const IID & GetIID () throw ()
 

Private Member Functions

void _Release () throw ()
 
void _AddRef () throw ()
 
template<typename _InterfacePtr >
HRESULT _QueryInterface (_InterfacePtr p) throw ()
 
template<typename _InterfacePtr >
int _CompareUnknown (_InterfacePtr p) const
 
HRESULT QueryStdInterfaces (const _variant_t &varSrc) throw ()
 

Private Attributes

Interfacem_pInterface
 

Member Typedef Documentation

template<typename _IIID>
typedef _IIID::Interface _com_ptr_t< _IIID >::Interface
template<typename _IIID>
typedef _IIID _com_ptr_t< _IIID >::ThisIIID

Constructor & Destructor Documentation

template<typename _IIID>
template<typename _OtherIID >
_com_ptr_t< _IIID >::_com_ptr_t ( const _com_ptr_t< _OtherIID > &  p)
inline
82  {
83  HRESULT hr = _QueryInterface(p);
84 
85  if (FAILED(hr) && (hr != E_NOINTERFACE)) {
86  _com_issue_error(hr);
87  }
88  }
#define NULL
Definition: vcruntime.h:236
HRESULT _QueryInterface(_InterfacePtr p)
Definition: comip.h:836
void __stdcall _com_issue_error(HRESULT)
#define FAILED(hr)
Definition: comutil.h:71
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
template<typename _InterfaceType >
_com_ptr_t< _IIID >::_com_ptr_t ( _InterfaceType *  p)
inline
94  {
95  HRESULT hr = _QueryInterface(p);
96 
97  if (FAILED(hr) && (hr != E_NOINTERFACE)) {
98  _com_issue_error(hr);
99  }
100  }
#define NULL
Definition: vcruntime.h:236
HRESULT _QueryInterface(_InterfacePtr p)
Definition: comip.h:836
void __stdcall _com_issue_error(HRESULT)
#define FAILED(hr)
Definition: comutil.h:71
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
template<>
_com_ptr_t< _IIID >::_com_ptr_t ( _In_ LPSTR  str)
inline
105  {
106  new(this) _com_ptr_t(static_cast<LPCSTR> (str), NULL);
107  }
#define NULL
Definition: vcruntime.h:236
_com_ptr_t()
Definition: comip.h:133
template<typename _IIID>
template<>
_com_ptr_t< _IIID >::_com_ptr_t ( _In_ LPWSTR  str)
inline
112  {
113  new(this) _com_ptr_t(static_cast<LPCWSTR> (str), NULL);
114  }
#define NULL
Definition: vcruntime.h:236
_com_ptr_t()
Definition: comip.h:133
template<typename _IIID>
template<>
_com_ptr_t< _IIID >::_com_ptr_t ( _com_ptr_t< _IIID > *  p)
inlineexplicit
120  : m_pInterface(NULL)
121  {
122  if (p == NULL) {
123  _com_issue_error(E_POINTER);
124  }
125  else {
127  AddRef();
128  }
129  }
#define NULL
Definition: vcruntime.h:236
void __stdcall _com_issue_error(HRESULT)
Interface * m_pInterface
Definition: comip.h:810
void AddRef()
Definition: comip.h:577
template<typename _IIID>
_com_ptr_t< _IIID >::_com_ptr_t ( )
throw (
)
inline
134  : m_pInterface(NULL)
135  {
136  }
#define NULL
Definition: vcruntime.h:236
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
_com_ptr_t< _IIID >::_com_ptr_t ( int  null)
inline
142  : m_pInterface(NULL)
143  {
144  if (null != 0) {
145  _com_issue_error(E_POINTER);
146  }
147  }
#define NULL
Definition: vcruntime.h:236
void __stdcall _com_issue_error(HRESULT)
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
_com_ptr_t< _IIID >::_com_ptr_t ( const _com_ptr_t< _IIID > &  cp)
throw (
)
inline
160  {
161  _AddRef();
162  }
void _AddRef()
Definition: comip.h:824
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
_com_ptr_t< _IIID >::_com_ptr_t ( _com_ptr_t< _IIID > &&  cp)
throw (
)
inline
168  {
169  cp.m_pInterface = nullptr;
170  }
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
template<>
_com_ptr_t< _IIID >::_com_ptr_t ( Interface pInterface)
throw (
)
inline
175  : m_pInterface(pInterface)
176  {
177  _AddRef();
178  }
void _AddRef()
Definition: comip.h:824
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
_com_ptr_t< _IIID >::_com_ptr_t ( Interface pInterface,
bool  fAddRef 
)
throw (
)
inline
184  : m_pInterface(pInterface)
185  {
186  if (fAddRef) {
187  _AddRef();
188  }
189  }
void _AddRef()
Definition: comip.h:824
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
_com_ptr_t< _IIID >::_com_ptr_t ( const _variant_t varSrc)
inline
194  : m_pInterface(NULL)
195  {
196  HRESULT hr = QueryStdInterfaces(varSrc);
197 
198  if (FAILED(hr) && (hr != E_NOINTERFACE)) {
199  _com_issue_error(hr);
200  }
201  }
#define NULL
Definition: vcruntime.h:236
void __stdcall _com_issue_error(HRESULT)
HRESULT QueryStdInterfaces(const _variant_t &varSrc)
Definition: comip.h:903
#define FAILED(hr)
Definition: comutil.h:71
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
_com_ptr_t< _IIID >::_com_ptr_t ( const CLSID &  clsid,
IUnknown *  pOuter = NULL,
DWORD  dwClsContext = CLSCTX_ALL 
)
inlineexplicit
206  : m_pInterface(NULL)
207  {
208  HRESULT hr = CreateInstance(clsid, pOuter, dwClsContext);
209 
210  if (FAILED(hr) && (hr != E_NOINTERFACE)) {
211  _com_issue_error(hr);
212  }
213  }
#define NULL
Definition: vcruntime.h:236
void __stdcall _com_issue_error(HRESULT)
HRESULT CreateInstance(const CLSID &rclsid, IUnknown *pOuter=NULL, DWORD dwClsContext=CLSCTX_ALL)
Definition: comip.h:604
#define FAILED(hr)
Definition: comutil.h:71
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
_com_ptr_t< _IIID >::_com_ptr_t ( LPCWSTR  str,
IUnknown *  pOuter = NULL,
DWORD  dwClsContext = CLSCTX_ALL 
)
inlineexplicit
219  : m_pInterface(NULL)
220  {
221  HRESULT hr = CreateInstance(str, pOuter, dwClsContext);
222 
223  if (FAILED(hr) && (hr != E_NOINTERFACE)) {
224  _com_issue_error(hr);
225  }
226  }
#define NULL
Definition: vcruntime.h:236
void __stdcall _com_issue_error(HRESULT)
HRESULT CreateInstance(const CLSID &rclsid, IUnknown *pOuter=NULL, DWORD dwClsContext=CLSCTX_ALL)
Definition: comip.h:604
#define FAILED(hr)
Definition: comutil.h:71
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
_com_ptr_t< _IIID >::_com_ptr_t ( LPCSTR  str,
IUnknown *  pOuter = NULL,
DWORD  dwClsContext = CLSCTX_ALL 
)
inlineexplicit
232  : m_pInterface(NULL)
233  {
234  HRESULT hr = CreateInstance(str, pOuter, dwClsContext);
235 
236  if (FAILED(hr) && (hr != E_NOINTERFACE)) {
237  _com_issue_error(hr);
238  }
239  }
#define NULL
Definition: vcruntime.h:236
void __stdcall _com_issue_error(HRESULT)
HRESULT CreateInstance(const CLSID &rclsid, IUnknown *pOuter=NULL, DWORD dwClsContext=CLSCTX_ALL)
Definition: comip.h:604
#define FAILED(hr)
Definition: comutil.h:71
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
_com_ptr_t< _IIID >::~_com_ptr_t ( )
throw (
)
inline
341  {
342  _Release();
343  }
void _Release()
Definition: comip.h:815

Member Function Documentation

template<typename _IIID>
void _com_ptr_t< _IIID >::_AddRef ( )
throw (
)
inlineprivate
825  {
826  if (m_pInterface != NULL) {
827  m_pInterface->AddRef();
828  }
829  }
#define NULL
Definition: vcruntime.h:236
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
template<typename _InterfacePtr >
int _com_ptr_t< _IIID >::_CompareUnknown ( _InterfacePtr  p) const
inlineprivate
864  {
865  IUnknown* pu1 = NULL;
866  IUnknown* pu2 = NULL;
867 
868  if (m_pInterface != NULL) {
869  HRESULT hr = m_pInterface->QueryInterface(__uuidof(IUnknown), reinterpret_cast<void**>(&pu1));
870 
871  if (FAILED(hr)) {
872  pu1 = NULL;
873  _com_issue_error(hr);
874  }
875  else {
876  pu1->Release();
877  }
878  }
879 
880  if (p != NULL) {
881  HRESULT hr = p->QueryInterface(__uuidof(IUnknown), reinterpret_cast<void**>(&pu2));
882 
883  if (FAILED(hr)) {
884  pu2 = NULL;
885  _com_issue_error(hr);
886  }
887  else {
888  pu2->Release();
889  }
890  }
891 
892  if (pu1 == pu2)
893  {
894  return 0;
895  }
896 
897  return (pu1 > pu2) ? 1 : -1;
898  }
#define NULL
Definition: vcruntime.h:236
void __stdcall _com_issue_error(HRESULT)
#define FAILED(hr)
Definition: comutil.h:71
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
template<typename _InterfacePtr >
HRESULT _com_ptr_t< _IIID >::_QueryInterface ( _InterfacePtr  p)
throw (
)
inlineprivate
837  {
838  HRESULT hr;
839 
840  // Can't QI NULL
841  //
842  if (p != NULL) {
843  // Query for this interface
844  //
845  Interface* pInterface = NULL;
846  hr = p->QueryInterface(GetIID(), reinterpret_cast<void**>(&pInterface));
847 
848  // Save the interface without AddRef()ing.
849  //
850  Attach(SUCCEEDED(hr)? pInterface: NULL);
851  }
852  else {
853  operator=(static_cast<Interface*>(NULL));
854  hr = E_NOINTERFACE;
855  }
856 
857  return hr;
858  }
#define NULL
Definition: vcruntime.h:236
void Attach(Interface *pInterface)
Definition: comip.h:348
_com_ptr_t & operator=(const _com_ptr_t< _OtherIID > &p)
Definition: comip.h:243
static const IID & GetIID()
Definition: comip.h:73
_IIID::Interface Interface
Definition: comip.h:66
template<typename _IIID>
void _com_ptr_t< _IIID >::_Release ( )
throw (
)
inlineprivate
816  {
817  if (m_pInterface != NULL) {
818  m_pInterface->Release();
819  }
820  }
#define NULL
Definition: vcruntime.h:236
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
void _com_ptr_t< _IIID >::AddRef ( )
inline
578  {
579  if (m_pInterface == NULL) {
580  _com_issue_error(E_POINTER);
581  }
582  else {
583  m_pInterface->AddRef();
584  }
585  }
#define NULL
Definition: vcruntime.h:236
void __stdcall _com_issue_error(HRESULT)
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
void _com_ptr_t< _IIID >::Attach ( Interface pInterface)
throw (
)
inline
349  {
350  _Release();
351  m_pInterface = pInterface;
352  }
void _Release()
Definition: comip.h:815
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
void _com_ptr_t< _IIID >::Attach ( Interface pInterface,
bool  fAddRef 
)
throw (
)
inline
358  {
359  _Release();
360  m_pInterface = pInterface;
361 
362  if (fAddRef) {
363  if (pInterface == NULL) {
364  _com_issue_error(E_POINTER);
365  }
366  else {
367  pInterface->AddRef();
368  }
369  }
370  }
#define NULL
Definition: vcruntime.h:236
void _Release()
Definition: comip.h:815
void __stdcall _com_issue_error(HRESULT)
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
HRESULT _com_ptr_t< _IIID >::CreateInstance ( const CLSID &  rclsid,
IUnknown *  pOuter = NULL,
DWORD  dwClsContext = CLSCTX_ALL 
)
throw (
)
inline
605  {
606  HRESULT hr;
607 
608  _Release();
609 
610  if (dwClsContext & (CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER)) {
611  IUnknown* pIUnknown;
612  hr = CoCreateInstance(rclsid, pOuter, dwClsContext, __uuidof(IUnknown), reinterpret_cast<void**>(&pIUnknown));
613 
614  if (SUCCEEDED(hr)) {
615  hr = OleRun(pIUnknown);
616 
617  if (SUCCEEDED(hr)) {
618  hr = pIUnknown->QueryInterface(GetIID(), reinterpret_cast<void**>(&m_pInterface));
619  }
620 
621  pIUnknown->Release();
622  }
623  }
624  else {
625  hr = CoCreateInstance(rclsid, pOuter, dwClsContext, GetIID(), reinterpret_cast<void**>(&m_pInterface));
626  }
627 
628  if (FAILED(hr)) {
629  // just in case refcount = 0 and dtor gets called
630  m_pInterface = NULL;
631  }
632 
633  return hr;
634  }
#define NULL
Definition: vcruntime.h:236
void _Release()
Definition: comip.h:815
#define FAILED(hr)
Definition: comutil.h:71
Interface * m_pInterface
Definition: comip.h:810
static const IID & GetIID()
Definition: comip.h:73
template<typename _IIID>
HRESULT _com_ptr_t< _IIID >::CreateInstance ( LPCWSTR  clsidString,
IUnknown *  pOuter = NULL,
DWORD  dwClsContext = CLSCTX_ALL 
)
throw (
)
inline
640  {
641  if (clsidString == NULL) {
642  return E_INVALIDARG;
643  }
644 
645  CLSID clsid;
646  HRESULT hr;
647 
648  if (clsidString[0] == L'{') {
649  hr = CLSIDFromString(const_cast<LPWSTR> (clsidString), &clsid);
650  }
651  else {
652  hr = CLSIDFromProgID(const_cast<LPWSTR> (clsidString), &clsid);
653  }
654 
655  if (FAILED(hr)) {
656  return hr;
657  }
658 
659  return CreateInstance(clsid, pOuter, dwClsContext);
660  }
#define NULL
Definition: vcruntime.h:236
HRESULT CreateInstance(const CLSID &rclsid, IUnknown *pOuter=NULL, DWORD dwClsContext=CLSCTX_ALL)
Definition: comip.h:604
#define FAILED(hr)
Definition: comutil.h:71
template<typename _IIID>
HRESULT _com_ptr_t< _IIID >::CreateInstance ( LPCSTR  clsidStringA,
IUnknown *  pOuter = NULL,
DWORD  dwClsContext = CLSCTX_ALL 
)
throw (
)
inline
666  {
667  if (clsidStringA == NULL) {
668  return E_INVALIDARG;
669  }
670 
671  size_t const size = strlen(clsidStringA) + 1;
672 
673  if (size > INT_MAX) {
674  return E_INVALIDARG;
675  }
676 
677  int const destSize = MultiByteToWideChar(CP_ACP, 0, clsidStringA, static_cast<int>(size), NULL, 0);
678 
679  if (destSize == 0) {
680  return HRESULT_FROM_WIN32(GetLastError());
681  }
682 
683  LPWSTR clsidStringW;
684  clsidStringW = static_cast<LPWSTR>(_malloca(destSize * sizeof(WCHAR)));
685 
686  if (clsidStringW == NULL) {
687  return E_OUTOFMEMORY;
688  }
689 
690  if (MultiByteToWideChar(CP_ACP, 0, clsidStringA, static_cast<int>(size), clsidStringW, destSize) == 0) {
691  _freea(clsidStringW);
692  return HRESULT_FROM_WIN32(GetLastError());
693  }
694 
695  HRESULT hr=CreateInstance(clsidStringW, pOuter, dwClsContext);
696  _freea(clsidStringW);
697  return hr;
698  }
#define NULL
Definition: vcruntime.h:236
constexpr auto size(const _Container &_Cont) -> decltype(_Cont.size())
Definition: xutility:1478
HRESULT CreateInstance(const CLSID &rclsid, IUnknown *pOuter=NULL, DWORD dwClsContext=CLSCTX_ALL)
Definition: comip.h:604
#define INT_MAX
Definition: limits.h:35
template<typename _IIID>
Interface* _com_ptr_t< _IIID >::Detach ( )
throw (
)
inline
375  {
376  Interface* const old = m_pInterface;
377  m_pInterface = NULL;
378  return old;
379  }
#define NULL
Definition: vcruntime.h:236
Interface * m_pInterface
Definition: comip.h:810
_IIID::Interface Interface
Definition: comip.h:66
template<typename _IIID>
HRESULT _com_ptr_t< _IIID >::GetActiveObject ( const CLSID &  rclsid)
throw (
)
inline
704  {
705  _Release();
706 
707  IUnknown* pIUnknown;
708 
709  HRESULT hr = ::GetActiveObject(rclsid, NULL, &pIUnknown);
710 
711  if (SUCCEEDED(hr)) {
712  hr = pIUnknown->QueryInterface(GetIID(), reinterpret_cast<void**>(&m_pInterface));
713 
714  pIUnknown->Release();
715  }
716 
717  if (FAILED(hr)) {
718  // just in case refcount = 0 and dtor gets called
719  m_pInterface = NULL;
720  }
721 
722  return hr;
723  }
#define NULL
Definition: vcruntime.h:236
void _Release()
Definition: comip.h:815
#define FAILED(hr)
Definition: comutil.h:71
HRESULT GetActiveObject(const CLSID &rclsid)
Definition: comip.h:703
Interface * m_pInterface
Definition: comip.h:810
static const IID & GetIID()
Definition: comip.h:73
template<typename _IIID>
HRESULT _com_ptr_t< _IIID >::GetActiveObject ( LPCWSTR  clsidString)
throw (
)
inline
729  {
730  if (clsidString == NULL) {
731  return E_INVALIDARG;
732  }
733 
734  CLSID clsid;
735  HRESULT hr;
736 
737  if (clsidString[0] == '{') {
738  hr = CLSIDFromString(const_cast<LPWSTR> (clsidString), &clsid);
739  }
740  else {
741  hr = CLSIDFromProgID(const_cast<LPWSTR> (clsidString), &clsid);
742  }
743 
744  if (FAILED(hr)) {
745  return hr;
746  }
747 
748  return GetActiveObject(clsid);
749  }
#define NULL
Definition: vcruntime.h:236
#define FAILED(hr)
Definition: comutil.h:71
HRESULT GetActiveObject(const CLSID &rclsid)
Definition: comip.h:703
template<typename _IIID>
HRESULT _com_ptr_t< _IIID >::GetActiveObject ( LPCSTR  clsidStringA)
throw (
)
inline
755  {
756  if (clsidStringA == NULL) {
757  return E_INVALIDARG;
758  }
759 
760  size_t const size = strlen(clsidStringA) + 1;
761 
762  if (size > INT_MAX) {
763  return E_INVALIDARG;
764  }
765 
766  int const destSize = MultiByteToWideChar(CP_ACP, 0, clsidStringA, static_cast<int>(size), NULL, 0);
767 
768  LPWSTR clsidStringW;
769  __try {
770  clsidStringW = static_cast<LPWSTR>(_alloca(destSize * sizeof(WCHAR)));
771  }
772  __except (GetExceptionCode() == STATUS_STACK_OVERFLOW) {
773  clsidStringW = NULL;
774  }
775 
776  if (clsidStringW == NULL) {
777  return E_OUTOFMEMORY;
778  }
779 
780  if (MultiByteToWideChar(CP_ACP, 0, clsidStringA, static_cast<int>(size), clsidStringW, destSize) == 0) {
781  return HRESULT_FROM_WIN32(GetLastError());
782  }
783 
784  return GetActiveObject(clsidStringW);
785  }
#define NULL
Definition: vcruntime.h:236
constexpr auto size(const _Container &_Cont) -> decltype(_Cont.size())
Definition: xutility:1478
#define GetExceptionCode
Definition: excpt.h:62
HRESULT GetActiveObject(const CLSID &rclsid)
Definition: comip.h:703
#define INT_MAX
Definition: limits.h:35
template<typename _IIID>
static const IID& _com_ptr_t< _IIID >::GetIID ( )
throw (
)
inlinestatic
74  {
75  return ThisIIID::GetIID();
76  }
template<typename _IIID>
Interface* _com_ptr_t< _IIID >::GetInterfacePtr ( ) const
throw (
)
inline
590  {
591  return m_pInterface;
592  }
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
Interface*& _com_ptr_t< _IIID >::GetInterfacePtr ( )
throw (
)
inline
597  {
598  return m_pInterface;
599  }
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
_com_ptr_t< _IIID >::operator bool ( ) const
throw (
)
inline
440  {
441  return m_pInterface != NULL;
442  }
#define NULL
Definition: vcruntime.h:236
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
_com_ptr_t< _IIID >::operator Interface & ( ) const
inline
392  {
393  if (m_pInterface == NULL) {
394  _com_issue_error(E_POINTER);
395  }
396 
397  return *m_pInterface;
398  }
#define NULL
Definition: vcruntime.h:236
void __stdcall _com_issue_error(HRESULT)
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
_com_ptr_t< _IIID >::operator Interface * ( ) const
throw (
)
inline
384  {
385  return m_pInterface;
386  }
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
template<typename _OtherIID >
bool _com_ptr_t< _IIID >::operator!= ( const _com_ptr_t< _OtherIID > &  p) const
inline
488  {
489  return !(operator==(p));
490  }
bool operator==(const _com_ptr_t< _OtherIID > &p) const
Definition: comip.h:446
template<typename _IIID>
template<typename _InterfaceType >
bool _com_ptr_t< _IIID >::operator!= ( _InterfaceType *  p) const
inline
495  {
496  return !(operator==(p));
497  }
bool operator==(const _com_ptr_t< _OtherIID > &p) const
Definition: comip.h:446
template<typename _IIID>
bool _com_ptr_t< _IIID >::operator!= ( int  null) const
inline
502  {
503  return !(operator==(null));
504  }
bool operator==(const _com_ptr_t< _OtherIID > &p) const
Definition: comip.h:446
template<typename _IIID>
Interface** _com_ptr_t< _IIID >::operator& ( )
throw (
)
inline
417  {
418  _Release();
419  m_pInterface = NULL;
420  return &m_pInterface;
421  }
#define NULL
Definition: vcruntime.h:236
void _Release()
Definition: comip.h:815
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
Interface& _com_ptr_t< _IIID >::operator* ( ) const
inline
404  {
405  if (m_pInterface == NULL) {
406  _com_issue_error(E_POINTER);
407  }
408 
409  return *m_pInterface;
410  }
#define NULL
Definition: vcruntime.h:236
void __stdcall _com_issue_error(HRESULT)
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
Interface* _com_ptr_t< _IIID >::operator-> ( ) const
inline
427  {
428  if (m_pInterface == NULL) {
429  _com_issue_error(E_POINTER);
430  }
431 
432  return m_pInterface;
433  }
#define NULL
Definition: vcruntime.h:236
void __stdcall _com_issue_error(HRESULT)
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
template<typename _OtherIID >
bool _com_ptr_t< _IIID >::operator< ( const _com_ptr_t< _OtherIID > &  p) const
inline
509  {
510  return _CompareUnknown(p) < 0;
511  }
int _CompareUnknown(_InterfacePtr p) const
Definition: comip.h:863
template<typename _IIID>
template<typename _InterfaceType >
bool _com_ptr_t< _IIID >::operator< ( _InterfaceType *  p) const
inline
516  {
517  return _CompareUnknown(p) < 0;
518  }
int _CompareUnknown(_InterfacePtr p) const
Definition: comip.h:863
template<typename _IIID>
template<typename _OtherIID >
bool _com_ptr_t< _IIID >::operator<= ( const _com_ptr_t< _OtherIID > &  p) const
inline
537  {
538  return _CompareUnknown(p) <= 0;
539  }
int _CompareUnknown(_InterfacePtr p) const
Definition: comip.h:863
template<typename _IIID>
template<typename _InterfaceType >
bool _com_ptr_t< _IIID >::operator<= ( _InterfaceType *  p) const
inline
544  {
545  return _CompareUnknown(p) <= 0;
546  }
int _CompareUnknown(_InterfacePtr p) const
Definition: comip.h:863
template<typename _IIID>
template<typename _OtherIID >
_com_ptr_t& _com_ptr_t< _IIID >::operator= ( const _com_ptr_t< _OtherIID > &  p)
inline
244  {
245  HRESULT hr = _QueryInterface(p);
246 
247  if (FAILED(hr) && (hr != E_NOINTERFACE)) {
248  _com_issue_error(hr);
249  }
250 
251  return *this;
252  }
HRESULT _QueryInterface(_InterfacePtr p)
Definition: comip.h:836
void __stdcall _com_issue_error(HRESULT)
#define FAILED(hr)
Definition: comutil.h:71
template<typename _IIID>
template<typename _InterfaceType >
_com_ptr_t& _com_ptr_t< _IIID >::operator= ( _InterfaceType *  p)
inline
257  {
258  HRESULT hr = _QueryInterface(p);
259 
260  if (FAILED(hr) && (hr != E_NOINTERFACE)) {
261  _com_issue_error(hr);
262  }
263 
264  return *this;
265  }
HRESULT _QueryInterface(_InterfacePtr p)
Definition: comip.h:836
void __stdcall _com_issue_error(HRESULT)
#define FAILED(hr)
Definition: comutil.h:71
template<typename _IIID>
template<>
_com_ptr_t& _com_ptr_t< _IIID >::operator= ( Interface pInterface)
throw (
)
inline
270  {
271  if (m_pInterface != pInterface) {
272  Interface* pOldInterface = m_pInterface;
273 
274  m_pInterface = pInterface;
275 
276  _AddRef();
277 
278  if (pOldInterface != nullptr) {
279  pOldInterface->Release();
280  }
281  }
282 
283  return *this;
284  }
void _AddRef()
Definition: comip.h:824
Interface * m_pInterface
Definition: comip.h:810
_IIID::Interface Interface
Definition: comip.h:66
template<typename _IIID>
_com_ptr_t& _com_ptr_t< _IIID >::operator= ( const _com_ptr_t< _IIID > &  cp)
throw (
)
inline
289  {
290  return operator=(cp.m_pInterface);
291  }
_com_ptr_t & operator=(const _com_ptr_t< _OtherIID > &p)
Definition: comip.h:243
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
_com_ptr_t& _com_ptr_t< _IIID >::operator= ( _com_ptr_t< _IIID > &&  cp)
throw (
)
inline
296  {
297  if (m_pInterface != cp.m_pInterface) {
298  Interface* pOldInterface = m_pInterface;
299 
301  cp.m_pInterface = nullptr;
302 
303  if (pOldInterface != nullptr) {
304  pOldInterface->Release();
305  }
306  }
307 
308  return *this;
309  }
Interface * m_pInterface
Definition: comip.h:810
_IIID::Interface Interface
Definition: comip.h:66
template<typename _IIID>
_com_ptr_t& _com_ptr_t< _IIID >::operator= ( int  null)
inline
315  {
316  if (null != 0) {
317  _com_issue_error(E_POINTER);
318  }
319 
320  return operator=(reinterpret_cast<Interface*>(NULL));
321  }
#define NULL
Definition: vcruntime.h:236
void __stdcall _com_issue_error(HRESULT)
_com_ptr_t & operator=(const _com_ptr_t< _OtherIID > &p)
Definition: comip.h:243
template<typename _IIID>
_com_ptr_t& _com_ptr_t< _IIID >::operator= ( const _variant_t varSrc)
inline
326  {
327  HRESULT hr = QueryStdInterfaces(varSrc);
328 
329  if (FAILED(hr) && (hr != E_NOINTERFACE)) {
330  _com_issue_error(hr);
331  }
332 
333  return *this;
334  }
void __stdcall _com_issue_error(HRESULT)
HRESULT QueryStdInterfaces(const _variant_t &varSrc)
Definition: comip.h:903
#define FAILED(hr)
Definition: comutil.h:71
template<typename _IIID>
template<typename _OtherIID >
bool _com_ptr_t< _IIID >::operator== ( const _com_ptr_t< _OtherIID > &  p) const
inline
447  {
448  return _CompareUnknown(p) == 0;
449  }
int _CompareUnknown(_InterfacePtr p) const
Definition: comip.h:863
template<typename _IIID>
template<typename _InterfaceType >
bool _com_ptr_t< _IIID >::operator== ( _InterfaceType *  p) const
inline
454  {
455  return _CompareUnknown(p) == 0;
456  }
int _CompareUnknown(_InterfacePtr p) const
Definition: comip.h:863
template<typename _IIID>
template<>
bool _com_ptr_t< _IIID >::operator== ( Interface p) const
inline
461  {
462  return (m_pInterface == p)
463  ? true
464  : _CompareUnknown(p) == 0;
465  }
int _CompareUnknown(_InterfacePtr p) const
Definition: comip.h:863
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
template<>
bool _com_ptr_t< _IIID >::operator== ( const _com_ptr_t< _IIID > &  p) const
throw (
)
inline
470  {
471  return operator==(p.m_pInterface);
472  }
bool operator==(const _com_ptr_t< _OtherIID > &p) const
Definition: comip.h:446
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
bool _com_ptr_t< _IIID >::operator== ( int  null) const
inline
477  {
478  if (null != 0) {
479  _com_issue_error(E_POINTER);
480  }
481 
482  return m_pInterface == NULL;
483  }
#define NULL
Definition: vcruntime.h:236
void __stdcall _com_issue_error(HRESULT)
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
template<typename _OtherIID >
bool _com_ptr_t< _IIID >::operator> ( const _com_ptr_t< _OtherIID > &  p) const
inline
523  {
524  return _CompareUnknown(p) > 0;
525  }
int _CompareUnknown(_InterfacePtr p) const
Definition: comip.h:863
template<typename _IIID>
template<typename _InterfaceType >
bool _com_ptr_t< _IIID >::operator> ( _InterfaceType *  p) const
inline
530  {
531  return _CompareUnknown(p) > 0;
532  }
int _CompareUnknown(_InterfacePtr p) const
Definition: comip.h:863
template<typename _IIID>
template<typename _OtherIID >
bool _com_ptr_t< _IIID >::operator>= ( const _com_ptr_t< _OtherIID > &  p) const
inline
551  {
552  return _CompareUnknown(p) >= 0;
553  }
int _CompareUnknown(_InterfacePtr p) const
Definition: comip.h:863
template<typename _IIID>
template<typename _InterfaceType >
bool _com_ptr_t< _IIID >::operator>= ( _InterfaceType *  p) const
inline
558  {
559  return _CompareUnknown(p) >= 0;
560  }
int _CompareUnknown(_InterfacePtr p) const
Definition: comip.h:863
template<typename _IIID>
template<typename _InterfaceType >
HRESULT _com_ptr_t< _IIID >::QueryInterface ( const IID &  iid,
_InterfaceType *&  p 
)
throw (
)
inline
791  {
792  if (m_pInterface != NULL) {
793  return m_pInterface->QueryInterface(iid, reinterpret_cast<void**>(&p));
794  }
795 
796  return E_POINTER;
797  }
#define NULL
Definition: vcruntime.h:236
Interface * m_pInterface
Definition: comip.h:810
template<typename _IIID>
template<typename _InterfaceType >
HRESULT _com_ptr_t< _IIID >::QueryInterface ( const IID &  iid,
_InterfaceType **  p 
)
throw (
)
inline
803  {
804  return QueryInterface(iid, *p);
805  }
HRESULT QueryInterface(const IID &iid, _InterfaceType *&p)
Definition: comip.h:790
template<typename _IIID>
HRESULT _com_ptr_t< _IIID >::QueryStdInterfaces ( const _variant_t varSrc)
throw (
)
inlineprivate
904  {
905  if (V_VT(&varSrc) == VT_DISPATCH) {
906  return _QueryInterface(V_DISPATCH(&varSrc));
907  }
908 
909  if (V_VT(&varSrc) == VT_UNKNOWN) {
910  return _QueryInterface(V_UNKNOWN(&varSrc));
911  }
912 
913  // We have something other than an IUnknown or an IDispatch.
914  // Can we convert it to either one of these?
915  // Try IDispatch first
916  //
917  VARIANT varDest;
918  VariantInit(&varDest);
919 
920  HRESULT hr = VariantChangeType(&varDest, const_cast<VARIANT*>(static_cast<const VARIANT*>(&varSrc)), 0, VT_DISPATCH);
921  if (SUCCEEDED(hr)) {
922  hr = _QueryInterface(V_DISPATCH(&varDest));
923  }
924 
925  if (hr == E_NOINTERFACE) {
926  // That failed ... so try IUnknown
927  //
928  VariantInit(&varDest);
929  hr = VariantChangeType(&varDest, const_cast<VARIANT*>(static_cast<const VARIANT*>(&varSrc)), 0, VT_UNKNOWN);
930  if (SUCCEEDED(hr)) {
931  hr = _QueryInterface(V_UNKNOWN(&varDest));
932  }
933  }
934 
935  VariantClear(&varDest);
936  return hr;
937  }
HRESULT _QueryInterface(_InterfacePtr p)
Definition: comip.h:836
template<typename _IIID>
void _com_ptr_t< _IIID >::Release ( )
inline
565  {
566  if (m_pInterface == NULL) {
567  _com_issue_error(E_POINTER);
568  }
569  else {
570  m_pInterface->Release();
571  m_pInterface = NULL;
572  }
573  }
#define NULL
Definition: vcruntime.h:236
void __stdcall _com_issue_error(HRESULT)
Interface * m_pInterface
Definition: comip.h:810

Member Data Documentation

template<typename _IIID>
Interface* _com_ptr_t< _IIID >::m_pInterface
private

The documentation for this class was generated from the following file: