]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/ole/oleutils.h
compilation problem fixed
[wxWidgets.git] / include / wx / msw / ole / oleutils.h
CommitLineData
bbf1f0e5
KB
1///////////////////////////////////////////////////////////////////////////////
2// Name: oleutils.h
3// Purpose: OLE helper routines, OLE debugging support &c
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 19.02.1998
7// RCS-ID: $Id$
8// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
bbcdf8bc 9// Licence: wxWindows licence
bbf1f0e5
KB
10///////////////////////////////////////////////////////////////////////////////
11
bbcdf8bc
JS
12#ifndef _WX_OLEUTILS_H
13#define _WX_OLEUTILS_H
bbf1f0e5
KB
14
15#ifdef __GNUG__
16#pragma interface "oleutils.h"
17#endif
18
e5ad6961
JS
19#include "wx/defs.h"
20
bbf1f0e5
KB
21// ============================================================================
22// General purpose functions and macros
23// ============================================================================
24
25// ----------------------------------------------------------------------------
26// misc helper functions/macros
27// ----------------------------------------------------------------------------
28
29// release the interface pointer (if !NULL)
30inline void ReleaseInterface(IUnknown *pIUnk)
31{
32 if ( pIUnk != NULL )
33 pIUnk->Release();
34}
35
36// release the interface pointer (if !NULL) and make it NULL
37#define RELEASE_AND_NULL(p) if ( (p) != NULL ) { p->Release(); p = NULL; };
38
39// return TRUE if the iid is in the array
40bool IsIidFromList(REFIID riid, const IID *aIids[], size_t nCount);
41
42// ============================================================================
43// IUnknown implementation helpers
44// ============================================================================
45
46/*
47 The most dumb implementation of IUnknown methods. We don't support
48 aggregation nor containment, but for 99% of cases this simple
49 implementation is quite enough.
50
51 Usage is trivial: here is all you should have
52 1) DECLARE_IUNKNOWN_METHOS in your (IUnknown derived!) class declaration
53 2) BEGIN/END_IID_TABLE with ADD_IID in between for all interfaces you
54 support (at least all for which you intent to return 'this' from QI,
55 i.e. you should derive from IFoo if you have ADD_IID(Foo)) somewhere else
56 3) IMPLEMENT_IUNKNOWN_METHOS somewhere also
57
58 These macros are quite simple: AddRef and Release are trivial and QI does
59 lookup in a static member array of IIDs and returns 'this' if it founds
60 the requested interface in it or E_NOINTERFACE if not.
61 */
62
63// declare the methods and the member variable containing reference count
64// you must also define the ms_aIids array somewhere with BEGIN_IID_TABLE
65// and friends (see below)
66#define DECLARE_IUNKNOWN_METHODS \
67 public: \
68 STDMETHODIMP QueryInterface(REFIID, void **); \
69 STDMETHODIMP_(ULONG) AddRef(); \
70 STDMETHODIMP_(ULONG) Release(); \
71 private: \
72 static const IID *ms_aIids[]; \
73 ULONG m_cRef
74
75// macros for declaring supported interfaces
76// NB: you should write ADD_INTERFACE(Foo) and not ADD_INTERFACE(IID_IFoo)!
77#define BEGIN_IID_TABLE(cname) const IID *cname::ms_aIids[] = {
78#define ADD_IID(iid) &IID_I##iid,
79#define END_IID_TABLE }
80
81// implementation is as straightforward as possible
82// Parameter: classname - the name of the class
83#define IMPLEMENT_IUNKNOWN_METHODS(classname) \
84 STDMETHODIMP classname::QueryInterface(REFIID riid, void **ppv) \
85 { \
86 wxLogQueryInterface(#classname, riid); \
87 \
88 if ( IsIidFromList(riid, ms_aIids, WXSIZEOF(ms_aIids)) ) { \
89 *ppv = this; \
90 AddRef(); \
91 \
92 return S_OK; \
93 } \
94 else { \
95 *ppv = NULL; \
96 \
97 return (HRESULT) E_NOINTERFACE; \
98 } \
99 } \
100 \
101 STDMETHODIMP_(ULONG) classname::AddRef() \
102 { \
103 wxLogAddRef(#classname, m_cRef); \
104 \
105 return ++m_cRef; \
106 } \
107 \
108 STDMETHODIMP_(ULONG) classname::Release() \
109 { \
110 wxLogRelease(#classname, m_cRef); \
111 \
112 if ( --m_cRef == 0 ) { \
113 delete this; \
114 return 0; \
115 } \
116 else \
117 return m_cRef; \
118 }
119
120// ============================================================================
121// Debugging support
122// ============================================================================
123
b2aef89b 124#if defined(__WXDEBUG__) && defined(_MSC_VER) && (_MSC_VER > 1000)
bbf1f0e5
KB
125// ----------------------------------------------------------------------------
126//
127// ----------------------------------------------------------------------------
128
129// ----------------------------------------------------------------------------
130// All OLE specific log functions have DebugTrace level (as LogTrace)
131// ----------------------------------------------------------------------------
132
133// tries to translate riid into a symbolic name, if possible
134void wxLogQueryInterface(const char *szInterface, REFIID riid);
135
136// these functions print out the new value of reference counter
137void wxLogAddRef (const char *szInterface, ULONG cRef);
138void wxLogRelease(const char *szInterface, ULONG cRef);
139
b2aef89b 140#else //!WXDEBUG
bbf1f0e5
KB
141 #define wxLogQueryInterface(szInterface, riid)
142 #define wxLogAddRef(szInterface, cRef)
143 #define wxLogRelease(szInterface, cRef)
b2aef89b 144#endif //WXDEBUG
bbf1f0e5 145
bbcdf8bc 146#endif //_WX_OLEUTILS_H