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 ()
 
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= (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  }
HRESULT _QueryInterface(_InterfacePtr p)
Definition: comip.h:800
void __stdcall _com_issue_error(HRESULT)
#define NULL
Definition: crtdbg.h:30
#define FAILED(hr)
Definition: comutil.h:71
Interface * m_pInterface
Definition: comip.h:774
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  }
HRESULT _QueryInterface(_InterfacePtr p)
Definition: comip.h:800
void __stdcall _com_issue_error(HRESULT)
#define NULL
Definition: crtdbg.h:30
#define FAILED(hr)
Definition: comutil.h:71
Interface * m_pInterface
Definition: comip.h:774
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  }
_com_ptr_t()
Definition: comip.h:133
#define NULL
Definition: crtdbg.h:30
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  }
_com_ptr_t()
Definition: comip.h:133
#define NULL
Definition: crtdbg.h:30
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  }
void __stdcall _com_issue_error(HRESULT)
#define NULL
Definition: crtdbg.h:30
Interface * m_pInterface
Definition: comip.h:774
void AddRef()
Definition: comip.h:551
template<typename _IIID>
_com_ptr_t< _IIID >::_com_ptr_t ( )
throw (
)
inline
134  : m_pInterface(NULL)
135  {
136  }
#define NULL
Definition: crtdbg.h:30
Interface * m_pInterface
Definition: comip.h:774
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  }
void __stdcall _com_issue_error(HRESULT)
#define NULL
Definition: crtdbg.h:30
Interface * m_pInterface
Definition: comip.h:774
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:788
Interface * m_pInterface
Definition: comip.h:774
template<typename _IIID>
template<>
_com_ptr_t< _IIID >::_com_ptr_t ( Interface pInterface)
throw (
)
inline
167  : m_pInterface(pInterface)
168  {
169  _AddRef();
170  }
void _AddRef()
Definition: comip.h:788
Interface * m_pInterface
Definition: comip.h:774
template<typename _IIID>
_com_ptr_t< _IIID >::_com_ptr_t ( Interface pInterface,
bool  fAddRef 
)
throw (
)
inline
176  : m_pInterface(pInterface)
177  {
178  if (fAddRef) {
179  _AddRef();
180  }
181  }
void _AddRef()
Definition: comip.h:788
Interface * m_pInterface
Definition: comip.h:774
template<typename _IIID>
_com_ptr_t< _IIID >::_com_ptr_t ( const _variant_t varSrc)
inline
186  : m_pInterface(NULL)
187  {
188  HRESULT hr = QueryStdInterfaces(varSrc);
189 
190  if (FAILED(hr) && (hr != E_NOINTERFACE)) {
191  _com_issue_error(hr);
192  }
193  }
void __stdcall _com_issue_error(HRESULT)
HRESULT QueryStdInterfaces(const _variant_t &varSrc)
Definition: comip.h:867
#define NULL
Definition: crtdbg.h:30
#define FAILED(hr)
Definition: comutil.h:71
Interface * m_pInterface
Definition: comip.h:774
template<typename _IIID>
_com_ptr_t< _IIID >::_com_ptr_t ( const CLSID &  clsid,
IUnknown *  pOuter = NULL,
DWORD  dwClsContext = CLSCTX_ALL 
)
inlineexplicit
198  : m_pInterface(NULL)
199  {
200  HRESULT hr = CreateInstance(clsid, pOuter, dwClsContext);
201 
202  if (FAILED(hr) && (hr != E_NOINTERFACE)) {
203  _com_issue_error(hr);
204  }
205  }
void __stdcall _com_issue_error(HRESULT)
#define NULL
Definition: crtdbg.h:30
HRESULT CreateInstance(const CLSID &rclsid, IUnknown *pOuter=NULL, DWORD dwClsContext=CLSCTX_ALL)
Definition: comip.h:578
#define FAILED(hr)
Definition: comutil.h:71
Interface * m_pInterface
Definition: comip.h:774
template<typename _IIID>
_com_ptr_t< _IIID >::_com_ptr_t ( LPCWSTR  str,
IUnknown *  pOuter = NULL,
DWORD  dwClsContext = CLSCTX_ALL 
)
inlineexplicit
211  : m_pInterface(NULL)
212  {
213  HRESULT hr = CreateInstance(str, pOuter, dwClsContext);
214 
215  if (FAILED(hr) && (hr != E_NOINTERFACE)) {
216  _com_issue_error(hr);
217  }
218  }
void __stdcall _com_issue_error(HRESULT)
#define NULL
Definition: crtdbg.h:30
HRESULT CreateInstance(const CLSID &rclsid, IUnknown *pOuter=NULL, DWORD dwClsContext=CLSCTX_ALL)
Definition: comip.h:578
#define FAILED(hr)
Definition: comutil.h:71
Interface * m_pInterface
Definition: comip.h:774
template<typename _IIID>
_com_ptr_t< _IIID >::_com_ptr_t ( LPCSTR  str,
IUnknown *  pOuter = NULL,
DWORD  dwClsContext = CLSCTX_ALL 
)
inlineexplicit
224  : m_pInterface(NULL)
225  {
226  HRESULT hr = CreateInstance(str, pOuter, dwClsContext);
227 
228  if (FAILED(hr) && (hr != E_NOINTERFACE)) {
229  _com_issue_error(hr);
230  }
231  }
void __stdcall _com_issue_error(HRESULT)
#define NULL
Definition: crtdbg.h:30
HRESULT CreateInstance(const CLSID &rclsid, IUnknown *pOuter=NULL, DWORD dwClsContext=CLSCTX_ALL)
Definition: comip.h:578
#define FAILED(hr)
Definition: comutil.h:71
Interface * m_pInterface
Definition: comip.h:774
template<typename _IIID>
_com_ptr_t< _IIID >::~_com_ptr_t ( )
throw (
)
inline
315  {
316  _Release();
317  }
void _Release()
Definition: comip.h:779

Member Function Documentation

template<typename _IIID>
void _com_ptr_t< _IIID >::_AddRef ( )
throw (
)
inlineprivate
789  {
790  if (m_pInterface != NULL) {
791  m_pInterface->AddRef();
792  }
793  }
#define NULL
Definition: crtdbg.h:30
Interface * m_pInterface
Definition: comip.h:774
template<typename _IIID>
template<typename _InterfacePtr >
int _com_ptr_t< _IIID >::_CompareUnknown ( _InterfacePtr  p) const
inlineprivate
828  {
829  IUnknown* pu1 = NULL;
830  IUnknown* pu2 = NULL;
831 
832  if (m_pInterface != NULL) {
833  HRESULT hr = m_pInterface->QueryInterface(__uuidof(IUnknown), reinterpret_cast<void**>(&pu1));
834 
835  if (FAILED(hr)) {
836  pu1 = NULL;
837  _com_issue_error(hr);
838  }
839  else {
840  pu1->Release();
841  }
842  }
843 
844  if (p != NULL) {
845  HRESULT hr = p->QueryInterface(__uuidof(IUnknown), reinterpret_cast<void**>(&pu2));
846 
847  if (FAILED(hr)) {
848  pu2 = NULL;
849  _com_issue_error(hr);
850  }
851  else {
852  pu2->Release();
853  }
854  }
855 
856  if (pu1 == pu2)
857  {
858  return 0;
859  }
860 
861  return (pu1 > pu2) ? 1 : -1;
862  }
void __stdcall _com_issue_error(HRESULT)
#define NULL
Definition: crtdbg.h:30
#define FAILED(hr)
Definition: comutil.h:71
Interface * m_pInterface
Definition: comip.h:774
template<typename _IIID>
template<typename _InterfacePtr >
HRESULT _com_ptr_t< _IIID >::_QueryInterface ( _InterfacePtr  p)
throw (
)
inlineprivate
801  {
802  HRESULT hr;
803 
804  // Can't QI NULL
805  //
806  if (p != NULL) {
807  // Query for this interface
808  //
809  Interface* pInterface;
810  hr = p->QueryInterface(GetIID(), reinterpret_cast<void**>(&pInterface));
811 
812  // Save the interface without AddRef()ing.
813  //
814  Attach(SUCCEEDED(hr)? pInterface: NULL);
815  }
816  else {
817  operator=(static_cast<Interface*>(NULL));
818  hr = E_NOINTERFACE;
819  }
820 
821  return hr;
822  }
#define NULL
Definition: crtdbg.h:30
void Attach(Interface *pInterface)
Definition: comip.h:322
_com_ptr_t & operator=(const _com_ptr_t< _OtherIID > &p)
Definition: comip.h:235
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
780  {
781  if (m_pInterface != NULL) {
782  m_pInterface->Release();
783  }
784  }
#define NULL
Definition: crtdbg.h:30
Interface * m_pInterface
Definition: comip.h:774
template<typename _IIID>
void _com_ptr_t< _IIID >::AddRef ( )
inline
552  {
553  if (m_pInterface == NULL) {
554  _com_issue_error(E_POINTER);
555  }
556  else {
557  m_pInterface->AddRef();
558  }
559  }
void __stdcall _com_issue_error(HRESULT)
#define NULL
Definition: crtdbg.h:30
Interface * m_pInterface
Definition: comip.h:774
template<typename _IIID>
void _com_ptr_t< _IIID >::Attach ( Interface pInterface)
throw (
)
inline
323  {
324  _Release();
325  m_pInterface = pInterface;
326  }
void _Release()
Definition: comip.h:779
Interface * m_pInterface
Definition: comip.h:774
template<typename _IIID>
void _com_ptr_t< _IIID >::Attach ( Interface pInterface,
bool  fAddRef 
)
throw (
)
inline
332  {
333  _Release();
334  m_pInterface = pInterface;
335 
336  if (fAddRef) {
337  if (pInterface == NULL) {
338  _com_issue_error(E_POINTER);
339  }
340  else {
341  pInterface->AddRef();
342  }
343  }
344  }
void _Release()
Definition: comip.h:779
void __stdcall _com_issue_error(HRESULT)
#define NULL
Definition: crtdbg.h:30
Interface * m_pInterface
Definition: comip.h:774
template<typename _IIID>
HRESULT _com_ptr_t< _IIID >::CreateInstance ( const CLSID &  rclsid,
IUnknown *  pOuter = NULL,
DWORD  dwClsContext = CLSCTX_ALL 
)
throw (
)
inline
579  {
580  HRESULT hr;
581 
582  _Release();
583 
584  if (dwClsContext & (CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER)) {
585  IUnknown* pIUnknown;
586  hr = CoCreateInstance(rclsid, pOuter, dwClsContext, __uuidof(IUnknown), reinterpret_cast<void**>(&pIUnknown));
587 
588  if (SUCCEEDED(hr)) {
589  hr = OleRun(pIUnknown);
590 
591  if (SUCCEEDED(hr)) {
592  hr = pIUnknown->QueryInterface(GetIID(), reinterpret_cast<void**>(&m_pInterface));
593  }
594 
595  pIUnknown->Release();
596  }
597  }
598  else {
599  hr = CoCreateInstance(rclsid, pOuter, dwClsContext, GetIID(), reinterpret_cast<void**>(&m_pInterface));
600  }
601 
602  if (FAILED(hr)) {
603  // just in case refcount = 0 and dtor gets called
604  m_pInterface = NULL;
605  }
606 
607  return hr;
608  }
void _Release()
Definition: comip.h:779
#define NULL
Definition: crtdbg.h:30
#define FAILED(hr)
Definition: comutil.h:71
Interface * m_pInterface
Definition: comip.h:774
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
614  {
615  if (clsidString == NULL) {
616  return E_INVALIDARG;
617  }
618 
619  CLSID clsid;
620  HRESULT hr;
621 
622  if (clsidString[0] == L'{') {
623  hr = CLSIDFromString(const_cast<LPWSTR> (clsidString), &clsid);
624  }
625  else {
626  hr = CLSIDFromProgID(const_cast<LPWSTR> (clsidString), &clsid);
627  }
628 
629  if (FAILED(hr)) {
630  return hr;
631  }
632 
633  return CreateInstance(clsid, pOuter, dwClsContext);
634  }
#define NULL
Definition: crtdbg.h:30
HRESULT CreateInstance(const CLSID &rclsid, IUnknown *pOuter=NULL, DWORD dwClsContext=CLSCTX_ALL)
Definition: comip.h:578
#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
640  {
641  if (clsidStringA == NULL) {
642  return E_INVALIDARG;
643  }
644 
645  int size = lstrlenA(clsidStringA) + 1;
646  int destSize = MultiByteToWideChar(CP_ACP, 0, clsidStringA, size, NULL, 0);
647 
648  if (destSize == 0) {
649  return HRESULT_FROM_WIN32(GetLastError());
650  }
651 
652  LPWSTR clsidStringW;
653  clsidStringW = static_cast<LPWSTR>(_malloca(destSize * sizeof(WCHAR)));
654 
655  if (clsidStringW == NULL) {
656  return E_OUTOFMEMORY;
657  }
658 
659  if (MultiByteToWideChar(CP_ACP, 0, clsidStringA, size, clsidStringW, destSize) == 0) {
660  _freea(clsidStringW);
661  return HRESULT_FROM_WIN32(GetLastError());
662  }
663 
664  HRESULT hr=CreateInstance(clsidStringW, pOuter, dwClsContext);
665  _freea(clsidStringW);
666  return hr;
667  }
#define NULL
Definition: crtdbg.h:30
HRESULT CreateInstance(const CLSID &rclsid, IUnknown *pOuter=NULL, DWORD dwClsContext=CLSCTX_ALL)
Definition: comip.h:578
#define _malloca(size)
Definition: malloc.h:228
template<typename _IIID>
Interface* _com_ptr_t< _IIID >::Detach ( )
throw (
)
inline
349  {
350  Interface* const old = m_pInterface;
351  m_pInterface = NULL;
352  return old;
353  }
#define NULL
Definition: crtdbg.h:30
Interface * m_pInterface
Definition: comip.h:774
_IIID::Interface Interface
Definition: comip.h:66
template<typename _IIID>
HRESULT _com_ptr_t< _IIID >::GetActiveObject ( const CLSID &  rclsid)
throw (
)
inline
673  {
674  _Release();
675 
676  IUnknown* pIUnknown;
677 
678  HRESULT hr = ::GetActiveObject(rclsid, NULL, &pIUnknown);
679 
680  if (SUCCEEDED(hr)) {
681  hr = pIUnknown->QueryInterface(GetIID(), reinterpret_cast<void**>(&m_pInterface));
682 
683  pIUnknown->Release();
684  }
685 
686  if (FAILED(hr)) {
687  // just in case refcount = 0 and dtor gets called
688  m_pInterface = NULL;
689  }
690 
691  return hr;
692  }
void _Release()
Definition: comip.h:779
#define NULL
Definition: crtdbg.h:30
#define FAILED(hr)
Definition: comutil.h:71
HRESULT GetActiveObject(const CLSID &rclsid)
Definition: comip.h:672
Interface * m_pInterface
Definition: comip.h:774
static const IID & GetIID()
Definition: comip.h:73
template<typename _IIID>
HRESULT _com_ptr_t< _IIID >::GetActiveObject ( LPCWSTR  clsidString)
throw (
)
inline
698  {
699  if (clsidString == NULL) {
700  return E_INVALIDARG;
701  }
702 
703  CLSID clsid;
704  HRESULT hr;
705 
706  if (clsidString[0] == '{') {
707  hr = CLSIDFromString(const_cast<LPWSTR> (clsidString), &clsid);
708  }
709  else {
710  hr = CLSIDFromProgID(const_cast<LPWSTR> (clsidString), &clsid);
711  }
712 
713  if (FAILED(hr)) {
714  return hr;
715  }
716 
717  return GetActiveObject(clsid);
718  }
#define NULL
Definition: crtdbg.h:30
#define FAILED(hr)
Definition: comutil.h:71
HRESULT GetActiveObject(const CLSID &rclsid)
Definition: comip.h:672
template<typename _IIID>
HRESULT _com_ptr_t< _IIID >::GetActiveObject ( LPCSTR  clsidStringA)
throw (
)
inline
724  {
725  if (clsidStringA == NULL) {
726  return E_INVALIDARG;
727  }
728 
729  int size = lstrlenA(clsidStringA) + 1;
730  int destSize = MultiByteToWideChar(CP_ACP, 0, clsidStringA, size, NULL, 0);
731 
732  LPWSTR clsidStringW;
733  __try {
734  clsidStringW = static_cast<LPWSTR>(_alloca(destSize * sizeof(WCHAR)));
735  }
736  __except (GetExceptionCode() == STATUS_STACK_OVERFLOW) {
737  clsidStringW = NULL;
738  }
739 
740  if (clsidStringW == NULL) {
741  return E_OUTOFMEMORY;
742  }
743 
744  if (MultiByteToWideChar(CP_ACP, 0, clsidStringA, size, clsidStringW, destSize) == 0) {
745  return HRESULT_FROM_WIN32(GetLastError());
746  }
747 
748  return GetActiveObject(clsidStringW);
749  }
#define NULL
Definition: crtdbg.h:30
#define GetExceptionCode
Definition: excpt.h:89
HRESULT GetActiveObject(const CLSID &rclsid)
Definition: comip.h:672
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
564  {
565  return m_pInterface;
566  }
Interface * m_pInterface
Definition: comip.h:774
template<typename _IIID>
Interface*& _com_ptr_t< _IIID >::GetInterfacePtr ( )
throw (
)
inline
571  {
572  return m_pInterface;
573  }
Interface * m_pInterface
Definition: comip.h:774
template<typename _IIID>
_com_ptr_t< _IIID >::operator bool ( ) const
throw (
)
inline
414  {
415  return m_pInterface != NULL;
416  }
#define NULL
Definition: crtdbg.h:30
Interface * m_pInterface
Definition: comip.h:774
template<typename _IIID>
_com_ptr_t< _IIID >::operator Interface & ( ) const
inline
366  {
367  if (m_pInterface == NULL) {
368  _com_issue_error(E_POINTER);
369  }
370 
371  return *m_pInterface;
372  }
void __stdcall _com_issue_error(HRESULT)
#define NULL
Definition: crtdbg.h:30
Interface * m_pInterface
Definition: comip.h:774
template<typename _IIID>
_com_ptr_t< _IIID >::operator Interface * ( ) const
throw (
)
inline
358  {
359  return m_pInterface;
360  }
Interface * m_pInterface
Definition: comip.h:774
template<typename _IIID>
template<typename _OtherIID >
bool _com_ptr_t< _IIID >::operator!= ( const _com_ptr_t< _OtherIID > &  p) const
inline
462  {
463  return !(operator==(p));
464  }
bool operator==(const _com_ptr_t< _OtherIID > &p) const
Definition: comip.h:420
template<typename _IIID>
template<typename _InterfaceType >
bool _com_ptr_t< _IIID >::operator!= ( _InterfaceType *  p) const
inline
469  {
470  return !(operator==(p));
471  }
bool operator==(const _com_ptr_t< _OtherIID > &p) const
Definition: comip.h:420
template<typename _IIID>
bool _com_ptr_t< _IIID >::operator!= ( int  null) const
inline
476  {
477  return !(operator==(null));
478  }
bool operator==(const _com_ptr_t< _OtherIID > &p) const
Definition: comip.h:420
template<typename _IIID>
Interface** _com_ptr_t< _IIID >::operator& ( )
throw (
)
inline
391  {
392  _Release();
393  m_pInterface = NULL;
394  return &m_pInterface;
395  }
void _Release()
Definition: comip.h:779
#define NULL
Definition: crtdbg.h:30
Interface * m_pInterface
Definition: comip.h:774
template<typename _IIID>
Interface& _com_ptr_t< _IIID >::operator* ( ) const
inline
378  {
379  if (m_pInterface == NULL) {
380  _com_issue_error(E_POINTER);
381  }
382 
383  return *m_pInterface;
384  }
void __stdcall _com_issue_error(HRESULT)
#define NULL
Definition: crtdbg.h:30
Interface * m_pInterface
Definition: comip.h:774
template<typename _IIID>
Interface* _com_ptr_t< _IIID >::operator-> ( ) const
inline
401  {
402  if (m_pInterface == NULL) {
403  _com_issue_error(E_POINTER);
404  }
405 
406  return m_pInterface;
407  }
void __stdcall _com_issue_error(HRESULT)
#define NULL
Definition: crtdbg.h:30
Interface * m_pInterface
Definition: comip.h:774
template<typename _IIID>
template<typename _OtherIID >
bool _com_ptr_t< _IIID >::operator< ( const _com_ptr_t< _OtherIID > &  p) const
inline
483  {
484  return _CompareUnknown(p) < 0;
485  }
int _CompareUnknown(_InterfacePtr p) const
Definition: comip.h:827
template<typename _IIID>
template<typename _InterfaceType >
bool _com_ptr_t< _IIID >::operator< ( _InterfaceType *  p) const
inline
490  {
491  return _CompareUnknown(p) < 0;
492  }
int _CompareUnknown(_InterfacePtr p) const
Definition: comip.h:827
template<typename _IIID>
template<typename _OtherIID >
bool _com_ptr_t< _IIID >::operator<= ( const _com_ptr_t< _OtherIID > &  p) const
inline
511  {
512  return _CompareUnknown(p) <= 0;
513  }
int _CompareUnknown(_InterfacePtr p) const
Definition: comip.h:827
template<typename _IIID>
template<typename _InterfaceType >
bool _com_ptr_t< _IIID >::operator<= ( _InterfaceType *  p) const
inline
518  {
519  return _CompareUnknown(p) <= 0;
520  }
int _CompareUnknown(_InterfacePtr p) const
Definition: comip.h:827
template<typename _IIID>
template<typename _OtherIID >
_com_ptr_t& _com_ptr_t< _IIID >::operator= ( const _com_ptr_t< _OtherIID > &  p)
inline
236  {
237  HRESULT hr = _QueryInterface(p);
238 
239  if (FAILED(hr) && (hr != E_NOINTERFACE)) {
240  _com_issue_error(hr);
241  }
242 
243  return *this;
244  }
HRESULT _QueryInterface(_InterfacePtr p)
Definition: comip.h:800
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
249  {
250  HRESULT hr = _QueryInterface(p);
251 
252  if (FAILED(hr) && (hr != E_NOINTERFACE)) {
253  _com_issue_error(hr);
254  }
255 
256  return *this;
257  }
HRESULT _QueryInterface(_InterfacePtr p)
Definition: comip.h:800
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
262  {
263  if (m_pInterface != pInterface) {
264  Interface* pOldInterface = m_pInterface;
265 
266  m_pInterface = pInterface;
267 
268  _AddRef();
269 
270  if (pOldInterface != NULL) {
271  pOldInterface->Release();
272  }
273  }
274 
275  return *this;
276  }
void _AddRef()
Definition: comip.h:788
#define NULL
Definition: crtdbg.h:30
Interface * m_pInterface
Definition: comip.h:774
_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
281  {
282  return operator=(cp.m_pInterface);
283  }
_com_ptr_t & operator=(const _com_ptr_t< _OtherIID > &p)
Definition: comip.h:235
Interface * m_pInterface
Definition: comip.h:774
template<typename _IIID>
_com_ptr_t& _com_ptr_t< _IIID >::operator= ( int  null)
inline
289  {
290  if (null != 0) {
291  _com_issue_error(E_POINTER);
292  }
293 
294  return operator=(reinterpret_cast<Interface*>(NULL));
295  }
void __stdcall _com_issue_error(HRESULT)
#define NULL
Definition: crtdbg.h:30
_com_ptr_t & operator=(const _com_ptr_t< _OtherIID > &p)
Definition: comip.h:235
template<typename _IIID>
_com_ptr_t& _com_ptr_t< _IIID >::operator= ( const _variant_t varSrc)
inline
300  {
301  HRESULT hr = QueryStdInterfaces(varSrc);
302 
303  if (FAILED(hr) && (hr != E_NOINTERFACE)) {
304  _com_issue_error(hr);
305  }
306 
307  return *this;
308  }
void __stdcall _com_issue_error(HRESULT)
HRESULT QueryStdInterfaces(const _variant_t &varSrc)
Definition: comip.h:867
#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
421  {
422  return _CompareUnknown(p) == 0;
423  }
int _CompareUnknown(_InterfacePtr p) const
Definition: comip.h:827
template<typename _IIID>
template<typename _InterfaceType >
bool _com_ptr_t< _IIID >::operator== ( _InterfaceType *  p) const
inline
428  {
429  return _CompareUnknown(p) == 0;
430  }
int _CompareUnknown(_InterfacePtr p) const
Definition: comip.h:827
template<typename _IIID>
template<>
bool _com_ptr_t< _IIID >::operator== ( Interface p) const
inline
435  {
436  return (m_pInterface == p)
437  ? true
438  : _CompareUnknown(p) == 0;
439  }
int _CompareUnknown(_InterfacePtr p) const
Definition: comip.h:827
Interface * m_pInterface
Definition: comip.h:774
template<typename _IIID>
template<>
bool _com_ptr_t< _IIID >::operator== ( const _com_ptr_t< _IIID > &  p) const
throw (
)
inline
444  {
445  return operator==(p.m_pInterface);
446  }
bool operator==(const _com_ptr_t< _OtherIID > &p) const
Definition: comip.h:420
Interface * m_pInterface
Definition: comip.h:774
template<typename _IIID>
bool _com_ptr_t< _IIID >::operator== ( int  null) const
inline
451  {
452  if (null != 0) {
453  _com_issue_error(E_POINTER);
454  }
455 
456  return m_pInterface == NULL;
457  }
void __stdcall _com_issue_error(HRESULT)
#define NULL
Definition: crtdbg.h:30
Interface * m_pInterface
Definition: comip.h:774
template<typename _IIID>
template<typename _OtherIID >
bool _com_ptr_t< _IIID >::operator> ( const _com_ptr_t< _OtherIID > &  p) const
inline
497  {
498  return _CompareUnknown(p) > 0;
499  }
int _CompareUnknown(_InterfacePtr p) const
Definition: comip.h:827
template<typename _IIID>
template<typename _InterfaceType >
bool _com_ptr_t< _IIID >::operator> ( _InterfaceType *  p) const
inline
504  {
505  return _CompareUnknown(p) > 0;
506  }
int _CompareUnknown(_InterfacePtr p) const
Definition: comip.h:827
template<typename _IIID>
template<typename _OtherIID >
bool _com_ptr_t< _IIID >::operator>= ( const _com_ptr_t< _OtherIID > &  p) const
inline
525  {
526  return _CompareUnknown(p) >= 0;
527  }
int _CompareUnknown(_InterfacePtr p) const
Definition: comip.h:827
template<typename _IIID>
template<typename _InterfaceType >
bool _com_ptr_t< _IIID >::operator>= ( _InterfaceType *  p) const
inline
532  {
533  return _CompareUnknown(p) >= 0;
534  }
int _CompareUnknown(_InterfacePtr p) const
Definition: comip.h:827
template<typename _IIID>
template<typename _InterfaceType >
HRESULT _com_ptr_t< _IIID >::QueryInterface ( const IID &  iid,
_InterfaceType *&  p 
)
throw (
)
inline
755  {
756  if (m_pInterface != NULL) {
757  return m_pInterface->QueryInterface(iid, reinterpret_cast<void**>(&p));
758  }
759 
760  return E_POINTER;
761  }
#define NULL
Definition: crtdbg.h:30
Interface * m_pInterface
Definition: comip.h:774
template<typename _IIID>
template<typename _InterfaceType >
HRESULT _com_ptr_t< _IIID >::QueryInterface ( const IID &  iid,
_InterfaceType **  p 
)
throw (
)
inline
767  {
768  return QueryInterface(iid, *p);
769  }
HRESULT QueryInterface(const IID &iid, _InterfaceType *&p)
Definition: comip.h:754
template<typename _IIID>
HRESULT _com_ptr_t< _IIID >::QueryStdInterfaces ( const _variant_t varSrc)
throw (
)
inlineprivate
868  {
869  if (V_VT(&varSrc) == VT_DISPATCH) {
870  return _QueryInterface(V_DISPATCH(&varSrc));
871  }
872 
873  if (V_VT(&varSrc) == VT_UNKNOWN) {
874  return _QueryInterface(V_UNKNOWN(&varSrc));
875  }
876 
877  // We have something other than an IUnknown or an IDispatch.
878  // Can we convert it to either one of these?
879  // Try IDispatch first
880  //
881  VARIANT varDest;
882  VariantInit(&varDest);
883 
884  HRESULT hr = VariantChangeType(&varDest, const_cast<VARIANT*>(static_cast<const VARIANT*>(&varSrc)), 0, VT_DISPATCH);
885  if (SUCCEEDED(hr)) {
886  hr = _QueryInterface(V_DISPATCH(&varDest));
887  }
888 
889  if (hr == E_NOINTERFACE) {
890  // That failed ... so try IUnknown
891  //
892  VariantInit(&varDest);
893  hr = VariantChangeType(&varDest, const_cast<VARIANT*>(static_cast<const VARIANT*>(&varSrc)), 0, VT_UNKNOWN);
894  if (SUCCEEDED(hr)) {
895  hr = _QueryInterface(V_UNKNOWN(&varDest));
896  }
897  }
898 
899  VariantClear(&varDest);
900  return hr;
901  }
HRESULT _QueryInterface(_InterfacePtr p)
Definition: comip.h:800
template<typename _IIID>
void _com_ptr_t< _IIID >::Release ( )
inline
539  {
540  if (m_pInterface == NULL) {
541  _com_issue_error(E_POINTER);
542  }
543  else {
544  m_pInterface->Release();
545  m_pInterface = NULL;
546  }
547  }
void __stdcall _com_issue_error(HRESULT)
#define NULL
Definition: crtdbg.h:30
Interface * m_pInterface
Definition: comip.h:774

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: