]>
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 licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_OLEUTILS_H
13 #define _WX_OLEUTILS_H
16 #pragma interface "oleutils.h"
20 #if wxUSE_NORLANDER_HEADERS
23 // ============================================================================
24 // General purpose functions and macros
25 // ============================================================================
27 // ----------------------------------------------------------------------------
28 // misc helper functions/macros
29 // ----------------------------------------------------------------------------
31 // release the interface pointer (if !NULL)
32 inline void ReleaseInterface(IUnknown
*pIUnk
)
38 // release the interface pointer (if !NULL) and make it NULL
39 #define RELEASE_AND_NULL(p) if ( (p) != NULL ) { p->Release(); p = NULL; };
41 // return TRUE if the iid is in the array
42 bool IsIidFromList(REFIID riid
, const IID
*aIids
[], size_t nCount
);
44 // ============================================================================
45 // IUnknown implementation helpers
46 // ============================================================================
49 The most dumb implementation of IUnknown methods. We don't support
50 aggregation nor containment, but for 99% of cases this simple
51 implementation is quite enough.
53 Usage is trivial: here is all you should have
54 1) DECLARE_IUNKNOWN_METHOS in your (IUnknown derived!) class declaration
55 2) BEGIN/END_IID_TABLE with ADD_IID in between for all interfaces you
56 support (at least all for which you intent to return 'this' from QI,
57 i.e. you should derive from IFoo if you have ADD_IID(Foo)) somewhere else
58 3) IMPLEMENT_IUNKNOWN_METHOS somewhere also
60 These macros are quite simple: AddRef and Release are trivial and QI does
61 lookup in a static member array of IIDs and returns 'this' if it founds
62 the requested interface in it or E_NOINTERFACE if not.
65 // declare the methods and the member variable containing reference count
66 // you must also define the ms_aIids array somewhere with BEGIN_IID_TABLE
67 // and friends (see below)
68 #define DECLARE_IUNKNOWN_METHODS \
70 STDMETHODIMP QueryInterface(REFIID, void **); \
71 STDMETHODIMP_(ULONG) AddRef(); \
72 STDMETHODIMP_(ULONG) Release(); \
74 static const IID *ms_aIids[]; \
77 // macros for declaring supported interfaces
78 // NB: you should write ADD_INTERFACE(Foo) and not ADD_INTERFACE(IID_IFoo)!
79 #define BEGIN_IID_TABLE(cname) const IID *cname::ms_aIids[] = {
80 #define ADD_IID(iid) &IID_I##iid,
81 #define END_IID_TABLE }
83 // implementation is as straightforward as possible
84 // Parameter: classname - the name of the class
85 #define IMPLEMENT_IUNKNOWN_METHODS(classname) \
86 STDMETHODIMP classname::QueryInterface(REFIID riid, void **ppv) \
88 wxLogQueryInterface(_T(#classname), riid); \
90 if ( IsIidFromList(riid, ms_aIids, WXSIZEOF(ms_aIids)) ) { \
99 return (HRESULT) E_NOINTERFACE; \
103 STDMETHODIMP_(ULONG) classname::AddRef() \
105 wxLogAddRef(_T(#classname), m_cRef); \
110 STDMETHODIMP_(ULONG) classname::Release() \
112 wxLogRelease(_T(#classname), m_cRef); \
114 if ( --m_cRef == 0 ) { \
122 // ============================================================================
124 // ============================================================================
126 // VZ: I don't know it's not done for compilers other than VC++ but I leave it
127 // as is. Please note, though, that tracing OLE interface calls may be
128 // incredibly useful when debugging OLE programs.
129 #if defined(__WXDEBUG__) && ( ( defined(__VISUALC__) && (__VISUALC__ >= 1000) ) || defined(__MWERKS__) )
130 // ----------------------------------------------------------------------------
131 // All OLE specific log functions have DebugTrace level (as LogTrace)
132 // ----------------------------------------------------------------------------
134 // tries to translate riid into a symbolic name, if possible
135 void wxLogQueryInterface(const wxChar
*szInterface
, REFIID riid
);
137 // these functions print out the new value of reference counter
138 void wxLogAddRef (const wxChar
*szInterface
, ULONG cRef
);
139 void wxLogRelease(const wxChar
*szInterface
, ULONG cRef
);
142 #define wxLogQueryInterface(szInterface, riid)
143 #define wxLogAddRef(szInterface, cRef)
144 #define wxLogRelease(szInterface, cRef)
147 #endif //_WX_OLEUTILS_H