]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/ole/oleutils.h
1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: OLE helper routines, OLE debugging support &c
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
16 #pragma interface "oleutils.h"
19 // ============================================================================
20 // General purpose functions and macros
21 // ============================================================================
23 // ----------------------------------------------------------------------------
24 // misc helper functions/macros
25 // ----------------------------------------------------------------------------
27 // release the interface pointer (if !NULL)
28 inline void ReleaseInterface(IUnknown
*pIUnk
)
34 // release the interface pointer (if !NULL) and make it NULL
35 #define RELEASE_AND_NULL(p) if ( (p) != NULL ) { p->Release(); p = NULL; };
37 // return TRUE if the iid is in the array
38 bool IsIidFromList(REFIID riid
, const IID
*aIids
[], size_t nCount
);
40 // ============================================================================
41 // IUnknown implementation helpers
42 // ============================================================================
45 The most dumb implementation of IUnknown methods. We don't support
46 aggregation nor containment, but for 99% of cases this simple
47 implementation is quite enough.
49 Usage is trivial: here is all you should have
50 1) DECLARE_IUNKNOWN_METHOS in your (IUnknown derived!) class declaration
51 2) BEGIN/END_IID_TABLE with ADD_IID in between for all interfaces you
52 support (at least all for which you intent to return 'this' from QI,
53 i.e. you should derive from IFoo if you have ADD_IID(Foo)) somewhere else
54 3) IMPLEMENT_IUNKNOWN_METHOS somewhere also
56 These macros are quite simple: AddRef and Release are trivial and QI does
57 lookup in a static member array of IIDs and returns 'this' if it founds
58 the requested interface in it or E_NOINTERFACE if not.
61 // declare the methods and the member variable containing reference count
62 // you must also define the ms_aIids array somewhere with BEGIN_IID_TABLE
63 // and friends (see below)
64 #define DECLARE_IUNKNOWN_METHODS \
66 STDMETHODIMP QueryInterface(REFIID, void **); \
67 STDMETHODIMP_(ULONG) AddRef(); \
68 STDMETHODIMP_(ULONG) Release(); \
70 static const IID *ms_aIids[]; \
73 // macros for declaring supported interfaces
74 // NB: you should write ADD_INTERFACE(Foo) and not ADD_INTERFACE(IID_IFoo)!
75 #define BEGIN_IID_TABLE(cname) const IID *cname::ms_aIids[] = {
76 #define ADD_IID(iid) &IID_I##iid,
77 #define END_IID_TABLE }
79 // implementation is as straightforward as possible
80 // Parameter: classname - the name of the class
81 #define IMPLEMENT_IUNKNOWN_METHODS(classname) \
82 STDMETHODIMP classname::QueryInterface(REFIID riid, void **ppv) \
84 wxLogQueryInterface(#classname, riid); \
86 if ( IsIidFromList(riid, ms_aIids, WXSIZEOF(ms_aIids)) ) { \
95 return (HRESULT) E_NOINTERFACE; \
99 STDMETHODIMP_(ULONG) classname::AddRef() \
101 wxLogAddRef(#classname, m_cRef); \
106 STDMETHODIMP_(ULONG) classname::Release() \
108 wxLogRelease(#classname, m_cRef); \
110 if ( --m_cRef == 0 ) { \
118 // ============================================================================
120 // ============================================================================
124 // ----------------------------------------------------------------------------
126 // ----------------------------------------------------------------------------
128 // ----------------------------------------------------------------------------
129 // All OLE specific log functions have DebugTrace level (as LogTrace)
130 // ----------------------------------------------------------------------------
132 // tries to translate riid into a symbolic name, if possible
133 void wxLogQueryInterface(const char *szInterface
, REFIID riid
);
135 // these functions print out the new value of reference counter
136 void wxLogAddRef (const char *szInterface
, ULONG cRef
);
137 void wxLogRelease(const char *szInterface
, ULONG cRef
);
140 #define wxLogQueryInterface(szInterface, riid)
141 #define wxLogAddRef(szInterface, cRef)
142 #define wxLogRelease(szInterface, cRef)