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