STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | Private Member Functions | Private Attributes | List of all members
msclr::com::ptr< _interface_type > Class Template Reference

#include <msclr/com/ptr.h>

Public Member Functions

 ptr ()
 
 ptr (_interface_type *p)
 
void Attach (_interface_type *_right)
 
ptr< _interface_type > operator= (_interface_type *_right)
 
void CreateInstance (System::String^prog_id, LPUNKNOWN pouter, DWORD cls_context)
 
void CreateInstance (System::String^prog_id, LPUNKNOWN pouter)
 
void CreateInstance (System::String^prog_id)
 
void CreateInstance (const wchar_t *progid, LPUNKNOWN pouter, DWORD cls_context)
 
void CreateInstance (const wchar_t *progid, LPUNKNOWN pouter)
 
void CreateInstance (const wchar_t *progid)
 
void CreateInstance (REFCLSID rclsid, LPUNKNOWN pouter, DWORD cls_context)
 
void CreateInstance (REFCLSID rclsid, LPUNKNOWN pouter)
 
void CreateInstance (REFCLSID rclsid)
 
_interface_type * Detach ()
 
void Release ()
 
_detail::smart_com_ptr< _interface_type > operator-> ()
 
_interface_type * GetInterface ()
 
template<class _other_type >
void QueryInterface (ptr< _other_type >%other)
 
 operator _detail_class::_safe_bool ()
 
bool operator! ()
 
 ~ptr ()
 

Private Member Functions

void destroy ()
 
bool valid ()
 
void assign (_interface_type *p)
 
template<class _other_type >
void QueryInterface (REFIID riid, ptr< _other_type >%other)
 

Private Attributes

Object obj_rcw
 

Constructor & Destructor Documentation

template<class _interface_type>
msclr::com::ptr< _interface_type >::ptr ( )
inline
71  :obj_rcw(nullptr)
72  {
73  }
Object obj_rcw
Definition: ptr.h:296
template<class _interface_type>
msclr::com::ptr< _interface_type >::ptr ( _interface_type *  p)
inline
77  {
78  obj_rcw = nullptr;
79  assign(p);
80  }
void assign(_interface_type *p)
Definition: ptr.h:276
Object obj_rcw
Definition: ptr.h:296
template<class _interface_type>
msclr::com::ptr< _interface_type >::~ptr ( )
inline
255  {
256  if(valid())
257  {
258  destroy();
259  }
260  }
void destroy()
Definition: ptr.h:264
bool valid()
Definition: ptr.h:270

Member Function Documentation

template<class _interface_type>
void msclr::com::ptr< _interface_type >::assign ( _interface_type *  p)
inlineprivate
277  {
278  if(p)
279  {
280  obj_rcw = System::Runtime::InteropServices::Marshal::GetUniqueObjectForIUnknown(System::IntPtr(p));
281  }
282  }
Object obj_rcw
Definition: ptr.h:296
template<class _interface_type>
void msclr::com::ptr< _interface_type >::Attach ( _interface_type *  _right)
inline
84  {
85  if (valid())
86  {
87  throw gcnew System::InvalidOperationException("COM::ptr.Attach");
88  }
89 
90  assign(_right);
91  }
void assign(_interface_type *p)
Definition: ptr.h:276
bool valid()
Definition: ptr.h:270
template<class _interface_type>
void msclr::com::ptr< _interface_type >::CreateInstance ( System::String^  prog_id,
LPUNKNOWN  pouter,
DWORD  cls_context 
)
inline
103  {
104  wchar_t * pwszprog_id = NULL;
105 
106  if(prog_id != nullptr)
107  {
108  pin_ptr<const __wchar_t> _pinned_ptr = PtrToStringChars( prog_id );
109  pwszprog_id = _wcsdup(_pinned_ptr);
110  }
111 
112  try
113  {
114  CreateInstance(pwszprog_id, pouter, cls_context);
115  }
116  finally
117  {
118  free(pwszprog_id);
119  }
120  }
#define NULL
Definition: vcruntime.h:236
__const_Char_ptr PtrToStringChars(__const_String_handle s)
Definition: vcclr.h:40
void CreateInstance(System::String^prog_id, LPUNKNOWN pouter, DWORD cls_context)
Definition: ptr.h:102
template<class _interface_type>
void msclr::com::ptr< _interface_type >::CreateInstance ( System::String^  prog_id,
LPUNKNOWN  pouter 
)
inline
123  {
124  CreateInstance(prog_id, pouter, CLSCTX_ALL);
125  }
void CreateInstance(System::String^prog_id, LPUNKNOWN pouter, DWORD cls_context)
Definition: ptr.h:102
template<class _interface_type>
void msclr::com::ptr< _interface_type >::CreateInstance ( System::String^  prog_id)
inline
128  {
129  CreateInstance(prog_id, NULL, CLSCTX_ALL);
130  }
#define NULL
Definition: vcruntime.h:236
void CreateInstance(System::String^prog_id, LPUNKNOWN pouter, DWORD cls_context)
Definition: ptr.h:102
template<class _interface_type>
void msclr::com::ptr< _interface_type >::CreateInstance ( const wchar_t progid,
LPUNKNOWN  pouter,
DWORD  cls_context 
)
inline
133  {
134  CLSID clsid;
135  System::Runtime::InteropServices::Marshal::ThrowExceptionForHR(
136  CLSIDFromProgID(progid, &clsid));
137  CreateInstance(clsid, pouter, cls_context);
138  }
void CreateInstance(System::String^prog_id, LPUNKNOWN pouter, DWORD cls_context)
Definition: ptr.h:102
template<class _interface_type>
void msclr::com::ptr< _interface_type >::CreateInstance ( const wchar_t progid,
LPUNKNOWN  pouter 
)
inline
141  {
142  CreateInstance(progid, pouter, CLSCTX_ALL);
143  }
void CreateInstance(System::String^prog_id, LPUNKNOWN pouter, DWORD cls_context)
Definition: ptr.h:102
template<class _interface_type>
void msclr::com::ptr< _interface_type >::CreateInstance ( const wchar_t progid)
inline
146  {
147  CreateInstance(progid, NULL, CLSCTX_ALL);
148  }
#define NULL
Definition: vcruntime.h:236
void CreateInstance(System::String^prog_id, LPUNKNOWN pouter, DWORD cls_context)
Definition: ptr.h:102
template<class _interface_type>
void msclr::com::ptr< _interface_type >::CreateInstance ( REFCLSID  rclsid,
LPUNKNOWN  pouter,
DWORD  cls_context 
)
inline
151  {
152  if (valid())
153  {
154  throw gcnew System::InvalidOperationException("COM::ptr.CreateInstance");
155  }
156 
157  _interface_type * interface_ptr = NULL;
158 
159  System::Runtime::InteropServices::Marshal::ThrowExceptionForHR(CoCreateInstance(
160  rclsid, pouter, cls_context, __uuidof(_interface_type),
161  (void**)&interface_ptr));
162 
163  if (interface_ptr)
164  {
165  assign(interface_ptr);
166  interface_ptr->Release();
167  }
168  }
#define NULL
Definition: vcruntime.h:236
void assign(_interface_type *p)
Definition: ptr.h:276
bool valid()
Definition: ptr.h:270
template<class _interface_type>
void msclr::com::ptr< _interface_type >::CreateInstance ( REFCLSID  rclsid,
LPUNKNOWN  pouter 
)
inline
171  {
172  CreateInstance(rclsid, pouter, CLSCTX_ALL);
173  }
void CreateInstance(System::String^prog_id, LPUNKNOWN pouter, DWORD cls_context)
Definition: ptr.h:102
template<class _interface_type>
void msclr::com::ptr< _interface_type >::CreateInstance ( REFCLSID  rclsid)
inline
176  {
177  CreateInstance(rclsid, NULL, CLSCTX_ALL);
178  }
#define NULL
Definition: vcruntime.h:236
void CreateInstance(System::String^prog_id, LPUNKNOWN pouter, DWORD cls_context)
Definition: ptr.h:102
template<class _interface_type>
void msclr::com::ptr< _interface_type >::destroy ( )
inlineprivate
265  {
266  System::Runtime::InteropServices::Marshal::ReleaseComObject(obj_rcw);
267  obj_rcw = nullptr;
268  }
Object obj_rcw
Definition: ptr.h:296
template<class _interface_type>
_interface_type* msclr::com::ptr< _interface_type >::Detach ( )
inline
183  {
184  if(valid())
185  {
186  _interface_type * interface_ptr = GetInterface();
187  destroy();
188  return interface_ptr;
189  }
190 
191  return NULL;
192  }
#define NULL
Definition: vcruntime.h:236
void destroy()
Definition: ptr.h:264
_interface_type * GetInterface()
Definition: ptr.h:213
bool valid()
Definition: ptr.h:270
template<class _interface_type>
_interface_type* msclr::com::ptr< _interface_type >::GetInterface ( )
inline
214  {
215  if(!valid())
216  {
217  return NULL;
218  }
219 
220  System::IntPtr iface_intptr = System::Runtime::InteropServices::Marshal::GetIUnknownForObject(obj_rcw);
221 
222  IUnknown * iunk = static_cast<IUnknown *>(static_cast<void*>(iface_intptr));
223 
224  _interface_type * interface_ptr = NULL;
225  System::Runtime::InteropServices::Marshal::ThrowExceptionForHR(iunk->QueryInterface(__uuidof(_interface_type), (void **)&interface_ptr));
226 
227  iunk->Release();
228 
229  interface_ptr->AddRef();
230  System::Runtime::InteropServices::Marshal::Release(iface_intptr);
231 
232  return interface_ptr;
233  }
#define NULL
Definition: vcruntime.h:236
Object obj_rcw
Definition: ptr.h:296
bool valid()
Definition: ptr.h:270
template<class _interface_type>
msclr::com::ptr< _interface_type >::operator _detail_class::_safe_bool ( )
inline
244  {
246  }
static _safe_bool const _safe_false
Definition: safebool.h:39
static _safe_bool const _safe_true
Definition: safebool.h:38
bool valid()
Definition: ptr.h:270
template<class _interface_type>
bool msclr::com::ptr< _interface_type >::operator! ( )
inline
250  {
251  return ! valid();
252  }
bool valid()
Definition: ptr.h:270
template<class _interface_type>
_detail::smart_com_ptr<_interface_type> msclr::com::ptr< _interface_type >::operator-> ( )
inline
207  {
208  _detail::smart_com_ptr<_interface_type> interface_ptr(GetInterface());
209  return interface_ptr;
210  }
_interface_type * GetInterface()
Definition: ptr.h:213
template<class _interface_type>
ptr<_interface_type> msclr::com::ptr< _interface_type >::operator= ( _interface_type *  _right)
inline
95  {
96  Attach(_right);
97  return *this;
98  }
void Attach(_interface_type *_right)
Definition: ptr.h:83
template<class _interface_type>
template<class _other_type >
void msclr::com::ptr< _interface_type >::QueryInterface ( ptr< _other_type >%  other)
inline
238  {
239  QueryInterface<_other_type>(__uuidof(_other_type), other);
240  }
template<class _interface_type>
template<class _other_type >
void msclr::com::ptr< _interface_type >::QueryInterface ( REFIID  riid,
ptr< _other_type >%  other 
)
inlineprivate
286  {
287  _detail::smart_com_ptr<_interface_type> interface_ptr(GetInterface());
288  _other_type * other_ptr = NULL;
289 
290  System::Runtime::InteropServices::Marshal::ThrowExceptionForHR(interface_ptr->QueryInterface(riid,(void **)&other_ptr));
291  other.Attach(other_ptr);
292 
293  other_ptr->Release();
294  }
#define NULL
Definition: vcruntime.h:236
_interface_type * GetInterface()
Definition: ptr.h:213
template<class _interface_type>
void msclr::com::ptr< _interface_type >::Release ( )
inline
196  {
197  if(valid())
198  {
199  destroy();
200  }
201  }
void destroy()
Definition: ptr.h:264
bool valid()
Definition: ptr.h:270
template<class _interface_type>
bool msclr::com::ptr< _interface_type >::valid ( )
inlineprivate
271  {
272  return (obj_rcw != nullptr);
273  }
Object obj_rcw
Definition: ptr.h:296

Member Data Documentation

template<class _interface_type>
Object msclr::com::ptr< _interface_type >::obj_rcw
private

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