]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/private/comptr.h
286fcdefc0dc54dd24f75f9fef4f1606f59cb208
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/private/comptr.h
3 // Purpose: Smart pointer for COM interfaces.
7 // Copyright: (c) 2012 wxWidgets team
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_MSW_PRIVATE_COMPTR_H_
12 #define _WX_MSW_PRIVATE_COMPTR_H_
14 // ----------------------------------------------------------------------------
15 // wxCOMPtr: A minimalistic smart pointer for use with COM interfaces.
16 // ----------------------------------------------------------------------------
22 typedef T element_type
;
29 wxEXPLICIT
wxCOMPtr(T
* ptr
)
36 wxCOMPtr(const wxCOMPtr
& ptr
)
49 void reset(T
* ptr
= NULL
)
61 wxCOMPtr
& operator=(const wxCOMPtr
& ptr
)
67 wxCOMPtr
& operator=(T
* ptr
)
88 // It would be better to forbid direct access completely but we do need
89 // for QueryInterface() and similar functions, so provide it but it can
90 // only be used to initialize the pointer, not to modify an existing one.
94 wxS("Can't get direct access to initialized pointer"));
104 bool operator<(T
* ptr
) const
113 // Define a helper for the macro below: we just need a function taking a
114 // pointer and not returning anything to avoid warnings about unused return
115 // value of the cast in the macro itself.
116 namespace wxPrivate
{ void PPV_ARGS_CHECK(void*) { } }
118 // Takes the interface name and a pointer to a pointer of the interface type
119 // and expands into the IID of this interface and the same pointer but after a
120 // type-safety check.
122 // This is similar to the standard IID_PPV_ARGS macro but takes the pointer
123 // type instead of relying on the non-standard Microsoft __uuidof().
124 #define wxIID_PPV_ARGS(IType, pType) \
126 (wxPrivate::PPV_ARGS_CHECK(static_cast<IType*>(*pType)), \
127 reinterpret_cast<void**>(pType))
129 #endif // _WX_MSW_PRIVATE_COMPTR_H_