14 #if !defined (_INC_MSCLR_COM_PTR)
16 #ifndef __cplusplus_cli
17 #error ERROR: msclr libraries are not compatible with /clr:oldSyntax
33 template<
class _
interface_type>
59 _interface_type *
ptr;
66 template<
class _
interface_type>
76 ptr(_interface_type * p)
83 void Attach(_interface_type * _right)
87 throw gcnew System::InvalidOperationException(
"COM::ptr.Attach");
104 wchar_t * pwszprog_id =
NULL;
106 if(prog_id !=
nullptr)
109 pwszprog_id =
_wcsdup(_pinned_ptr);
135 System::Runtime::InteropServices::Marshal::ThrowExceptionForHR(
136 CLSIDFromProgID(progid, &clsid));
154 throw gcnew System::InvalidOperationException(
"COM::ptr.CreateInstance");
157 _interface_type * interface_ptr =
NULL;
159 System::Runtime::InteropServices::Marshal::ThrowExceptionForHR(CoCreateInstance(
160 rclsid, pouter, cls_context, __uuidof(_interface_type),
161 (
void**)&interface_ptr));
166 interface_ptr->Release();
188 return interface_ptr;
209 return interface_ptr;
220 System::IntPtr iface_intptr = System::Runtime::InteropServices::Marshal::GetIUnknownForObject(
obj_rcw);
222 IUnknown * iunk =
static_cast<IUnknown *
>(
static_cast<void*
>(iface_intptr));
224 _interface_type * interface_ptr;
225 System::Runtime::InteropServices::Marshal::ThrowExceptionForHR(iunk->QueryInterface(__uuidof(_interface_type), (
void **)&interface_ptr));
229 interface_ptr->AddRef();
230 System::Runtime::InteropServices::Marshal::Release(iface_intptr);
232 return interface_ptr;
236 template<
class _other_type>
239 QueryInterface<_other_type>(__uuidof(_other_type), other);
266 System::Runtime::InteropServices::Marshal::ReleaseComObject(
obj_rcw);
280 obj_rcw = System::Runtime::InteropServices::Marshal::GetUniqueObjectForIUnknown(System::IntPtr(p));
284 template<
class _other_type>
288 _other_type * other_ptr;
290 System::Runtime::InteropServices::Marshal::ThrowExceptionForHR(interface_ptr->QueryInterface(riid,(
void **)&other_ptr));
293 other_ptr->Release();
302 #define _INC_MSCLR_COM_PTR
smart_com_ptr(_interface_type *p)
Definition: ptr.h:37
_interface_type * operator->()
Definition: ptr.h:48
System::String _safe_bool
Definition: safebool.h:37
void CreateInstance(System::String^prog_id, LPUNKNOWN pouter)
Definition: ptr.h:122
void CreateInstance(const wchar_t *progid, LPUNKNOWN pouter, DWORD cls_context)
Definition: ptr.h:132
ptr()
Definition: ptr.h:71
Definition: appdomain.h:36
void assign(_interface_type *p)
Definition: ptr.h:276
static _safe_bool const _safe_false
Definition: safebool.h:39
_CRTIMP _CRTNOALIAS void __cdecl free(_Pre_maybenull_ _Post_invalid_ void *_Memory)
#define NULL
Definition: crtdbg.h:30
__const_Char_ptr PtrToStringChars(__const_String_handle s)
Definition: vcclr.h:40
void CreateInstance(REFCLSID rclsid)
Definition: ptr.h:175
static _safe_bool const _safe_true
Definition: safebool.h:38
~smart_com_ptr()
Definition: ptr.h:53
Object obj_rcw
Definition: ptr.h:296
void Release()
Definition: ptr.h:195
void Attach(_interface_type *_right)
Definition: ptr.h:83
_interface_type * ptr
Definition: ptr.h:59
void CreateInstance(REFCLSID rclsid, LPUNKNOWN pouter, DWORD cls_context)
Definition: ptr.h:150
void destroy()
Definition: ptr.h:264
_interface_type * GetInterface()
Definition: ptr.h:213
ptr< _interface_type > operator=(_interface_type *_right)
Definition: ptr.h:94
unsigned long DWORD
Definition: concrt.h:57
~ptr()
Definition: ptr.h:254
void CreateInstance(REFCLSID rclsid, LPUNKNOWN pouter)
Definition: ptr.h:170
void CreateInstance(System::String^prog_id, LPUNKNOWN pouter, DWORD cls_context)
Definition: ptr.h:102
bool operator!()
Definition: ptr.h:249
bool valid()
Definition: ptr.h:270
void CreateInstance(const wchar_t *progid, LPUNKNOWN pouter)
Definition: ptr.h:140
_Check_return_ _CRTIMP wchar_t *__cdecl _wcsdup(_In_z_ const wchar_t *_Str)
smart_com_ptr(smart_com_ptr%ip)
Definition: ptr.h:42
_interface_type * Detach()
Definition: ptr.h:182
void QueryInterface(ptr< _other_type >%other)
Definition: ptr.h:237
_detail::smart_com_ptr< _interface_type > operator->()
Definition: ptr.h:206
void CreateInstance(System::String^prog_id)
Definition: ptr.h:127
ptr(_interface_type *p)
Definition: ptr.h:76
void QueryInterface(REFIID riid, ptr< _other_type >%other)
Definition: ptr.h:285
void CreateInstance(const wchar_t *progid)
Definition: ptr.h:145