]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/ole/oleutils.h
don't process VK_OEM_XXX key presses
[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
3f4a0c5b 5// Modified by:
bbf1f0e5
KB
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 19#include "wx/defs.h"
b64f0a5f 20#if wxUSE_NORLANDER_HEADERS
7dee726c
RS
21#include <ole2.h>
22#endif
bbf1f0e5
KB
23// ============================================================================
24// General purpose functions and macros
25// ============================================================================
26
27// ----------------------------------------------------------------------------
28// misc helper functions/macros
29// ----------------------------------------------------------------------------
30
31// release the interface pointer (if !NULL)
32inline void ReleaseInterface(IUnknown *pIUnk)
33{
34 if ( pIUnk != NULL )
35 pIUnk->Release();
36}
37
38// release the interface pointer (if !NULL) and make it NULL
39#define RELEASE_AND_NULL(p) if ( (p) != NULL ) { p->Release(); p = NULL; };
40
41// return TRUE if the iid is in the array
42bool IsIidFromList(REFIID riid, const IID *aIids[], size_t nCount);
43
44// ============================================================================
45// IUnknown implementation helpers
46// ============================================================================
47
48/*
3f4a0c5b 49 The most dumb implementation of IUnknown methods. We don't support
bbf1f0e5
KB
50 aggregation nor containment, but for 99% of cases this simple
51 implementation is quite enough.
52
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
59
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.
63 */
64
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 \
69 public: \
70 STDMETHODIMP QueryInterface(REFIID, void **); \
71 STDMETHODIMP_(ULONG) AddRef(); \
72 STDMETHODIMP_(ULONG) Release(); \
73 private: \
74 static const IID *ms_aIids[]; \
75 ULONG m_cRef
76
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 }
82
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) \
87 { \
f6bcfd97 88 wxLogQueryInterface(_T(#classname), riid); \
bbf1f0e5 89 \
f6bcfd97 90 if ( IsIidFromList(riid, ms_aIids, WXSIZEOF(ms_aIids)) ) { \
bbf1f0e5
KB
91 *ppv = this; \
92 AddRef(); \
93 \
94 return S_OK; \
95 } \
96 else { \
97 *ppv = NULL; \
98 \
f6bcfd97 99 return (HRESULT) E_NOINTERFACE; \
bbf1f0e5
KB
100 } \
101 } \
102 \
103 STDMETHODIMP_(ULONG) classname::AddRef() \
104 { \
f6bcfd97 105 wxLogAddRef(_T(#classname), m_cRef); \
bbf1f0e5
KB
106 \
107 return ++m_cRef; \
108 } \
109 \
110 STDMETHODIMP_(ULONG) classname::Release() \
111 { \
f6bcfd97 112 wxLogRelease(_T(#classname), m_cRef); \
bbf1f0e5
KB
113 \
114 if ( --m_cRef == 0 ) { \
115 delete this; \
116 return 0; \
117 } \
118 else \
119 return m_cRef; \
120 }
121
122// ============================================================================
123// Debugging support
124// ============================================================================
125
3f4a0c5b
VZ
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)
bbf1f0e5
KB
130// ----------------------------------------------------------------------------
131// All OLE specific log functions have DebugTrace level (as LogTrace)
132// ----------------------------------------------------------------------------
133
134// tries to translate riid into a symbolic name, if possible
f6bcfd97 135void wxLogQueryInterface(const wxChar *szInterface, REFIID riid);
bbf1f0e5
KB
136
137// these functions print out the new value of reference counter
f6bcfd97
BP
138void wxLogAddRef (const wxChar *szInterface, ULONG cRef);
139void wxLogRelease(const wxChar *szInterface, ULONG cRef);
bbf1f0e5 140
b2aef89b 141#else //!WXDEBUG
bbf1f0e5
KB
142 #define wxLogQueryInterface(szInterface, riid)
143 #define wxLogAddRef(szInterface, cRef)
144 #define wxLogRelease(szInterface, cRef)
b2aef89b 145#endif //WXDEBUG
bbf1f0e5 146
3f4a0c5b
VZ
147#endif //_WX_OLEUTILS_H
148