KeePass Help Center KeePass Home | Downloads | Translations | Plugins | Donate 
Help Center Home | Forums | Awards | Links 







SysDefEx.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008-2024 Dominik Reichl
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions
7  are met:
8 
9  * Redistributions of source code must retain the above copyright
10  notice, this list of conditions and the following disclaimer.
11  * Redistributions in binary form must reproduce the above copyright
12  notice, this list of conditions and the following disclaimer in
13  the documentation and/or other materials provided with the
14  distribution.
15 
16  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  POSSIBILITY OF SUCH DAMAGE.
28 */
29 
30 #ifndef ___SYS_DEF_EX_H___
31 #define ___SYS_DEF_EX_H___
32 
33 #pragma once
34 
35 // The following types and functions must be implemented for each
36 // supported platform:
37 
38 // Types:
39 // UINT8 -- 8-bit unsigned integer.
40 // UINT16 -- 16-bit unsigned integer.
41 // UINT32 -- 32-bit unsigned integer.
42 // UINT64 -- 64-bit unsigned integer.
43 // INT8 -- 8-bit unsigned integer.
44 // INT16 -- 16-bit unsigned integer.
45 // INT32 -- 32-bit unsigned integer.
46 // INT64 -- 64-bit unsigned integer.
47 
48 // Defines:
49 // CPP_CLASS_SHARE -- Define to a keyword that imports or exports a C++ class.
50 // CPP_FN_SHARE -- Define to a keyword that imports or exports a function
51 // that uses C++ types (class in parameters, STL type).
52 // C_FN_SHARE -- Define to a keyword that imports or exports a function.
53 // KP_EXP -- Define to the opposite of C_FN_SHARE.
54 // KP_API -- Define to a function call type (STDCALL / CDECL).
55 
56 // Include all system-specific definitions
57 #include "SysSpec_Windows/SysSpecWin.h"
58 // #include "SysSpec/SysSpecLinux.h"
59 #if defined _WIN32_WCE
60 #include "wce_wrap.h"
61 #endif
62 
63 // Implications, standard macros and other definitions follow.
64 
65 #ifndef UNREFERENCED_PARAMETER
66 #define UNREFERENCED_PARAMETER(p) (void)0
67 #endif
68 
69 #if (_MSC_VER >= 1600)
70 #include <stdint.h>
71 #else
72 #ifndef INT32_MAX
73 #define INT32_MAX 0x7FFFFFFF
74 #endif
75 #ifndef UINT32_MAX
76 #define UINT32_MAX 0xFFFFFFFF
77 #endif
78 #ifndef UINT64_MAX
79 #define UINT64_MAX 0xFFFFFFFFFFFFFFFFui64
80 #endif
81 #endif
82 
83 #ifndef DWORD_MAX
84 #define DWORD_MAX 0xFFFFFFFF
85 #endif
86 
87 #ifndef UTF8_BYTE
88 #define UTF8_BYTE BYTE
89 #endif
90 
91 #ifndef ROTL32UE
92 #define ROTL32UE(__uv,__nv) ((((__uv) << (__nv)) | ((__uv) >> (32 - (__nv)))) & 0xFFFFFFFF)
93 #endif
94 
95 // Safely delete pointers
96 #ifndef SAFE_DELETE
97 #define SAFE_DELETE(__kp_p) { if((__kp_p) != NULL) { delete (__kp_p); (__kp_p) = NULL; } }
102 
107 #define SAFE_DELETE_ARRAY(__kp_p) { if((__kp_p) != NULL) { delete [](__kp_p); (__kp_p) = NULL; } }
108 
112 #define SAFE_RELEASE(__kp_p) { if((__kp_p) != NULL) { (__kp_p)->Release(); (__kp_p) = NULL; } }
113 #endif
114 
115 #ifndef KP_DEFINE_GUID
116 #define KP_DEFINE_GUID(__kp_name,__kp_l,__kp_w1,__kp_w2,__kp_b1,__kp_b2,__kp_b3,__kp_b4,__kp_b5,__kp_b6,__kp_b7,__kp_b8) \
117  EXTERN_C const GUID DECLSPEC_SELECTANY __kp_name \
118  = { __kp_l, __kp_w1, __kp_w2, { __kp_b1, __kp_b2, __kp_b3, __kp_b4, \
119  __kp_b5, __kp_b6, __kp_b7, __kp_b8 } }
120 #endif
121 
122 #ifndef KP_DECLSPEC_UUID
123 #if ((_MSC_VER >= 1100) && defined(__cplusplus))
124 #define KP_DECLSPEC_UUID(__kp_uuid) __declspec(uuid(__kp_uuid))
125 #else
126 #define KP_DECLSPEC_UUID(__kp_uuid)
127 #endif
128 #endif
129 
130 #ifndef KP_DECLSPEC_NOVTABLE
131 #if ((_MSC_VER >= 1100) && defined(__cplusplus))
132 #define KP_DECLSPEC_NOVTABLE __declspec(novtable)
133 #else
134 #define KP_DECLSPEC_NOVTABLE
135 #endif
136 #endif
137 
138 #ifndef KP_DECL_INTERFACE
139 #define KP_DECL_INTERFACE(__kp_if_uuid) KP_DECLSPEC_UUID(__kp_if_uuid) KP_DECLSPEC_NOVTABLE
140 #endif
141 
142 #ifndef KP_DECL_IUNKNOWN
143 #define KP_DECL_IUNKNOWN STDMETHODIMP QueryInterface(REFIID riid, void** ppvObject); \
144  STDMETHODIMP_(ULONG) AddRef(); STDMETHODIMP_(ULONG) Release()
145 #endif
146 
147 #ifndef KP_DECL_STDREFIMPL
148 #define KP_DECL_STDREFIMPL ULONG __m_uInterfaceRefCount
149 #endif
150 
151 #ifndef KP_IMPL_STDREFIMPL
152 #define KP_IMPL_STDREFIMPL(__kp_class_name) STDMETHODIMP_(ULONG) \
153  __kp_class_name##::AddRef() { return ++__m_uInterfaceRefCount; } \
154  STDMETHODIMP_(ULONG) __kp_class_name##::Release() { \
155  ULONG __kp_ref = __m_uInterfaceRefCount; \
156  if(__m_uInterfaceRefCount != 0) { __kp_ref = --__m_uInterfaceRefCount; \
157  if(__m_uInterfaceRefCount == 0) delete this; } \
158  else { assert(false); } return __kp_ref; }
159 #endif
160 
161 #ifndef KP_IMPL_STDREFIMPL_SUB
162 #define KP_IMPL_STDREFIMPL_SUB(__kp_class_name,__kp_sub_name) STDMETHODIMP_(ULONG) \
163  __kp_class_name##::AddRef() { return ++__m_uInterfaceRefCount; } \
164  STDMETHODIMP_(ULONG) __kp_class_name##::Release() { \
165  ULONG __kp_ref = __m_uInterfaceRefCount; \
166  if(__m_uInterfaceRefCount != 0) { __kp_ref = --__m_uInterfaceRefCount; \
167  if(__m_uInterfaceRefCount == 0) { SAFE_DELETE(__kp_sub_name); delete this; } } \
168  else { assert(false); } return __kp_ref; }
169 #endif
170 
171 #ifndef KP_IMPL_STDREFIMPL_NODELETE
172 #define KP_IMPL_STDREFIMPL_NODELETE(__kp_class_name) STDMETHODIMP_(ULONG) \
173  __kp_class_name##::AddRef() { return ++__m_uInterfaceRefCount; } \
174  STDMETHODIMP_(ULONG) __kp_class_name##::Release() { \
175  if(__m_uInterfaceRefCount != 0) --__m_uInterfaceRefCount; \
176  else { assert(false); } return __m_uInterfaceRefCount; }
177 #endif
178 
179 #ifndef KP_IMPL_CONSTRUCT
180 #define KP_IMPL_CONSTRUCT { __m_uInterfaceRefCount = 1; }
181 #endif
182 
183 #ifndef KP_SUPPORT_INTERFACE
184 #define KP_SUPPORT_INTERFACE(__kp_iid,__kp_int) { assert(__m_uInterfaceRefCount > 0); \
185  if(riid == __kp_iid) { __kp_int##* __kp_p = this; *ppvObject = __kp_p; \
186  this->AddRef(); return S_OK; } }
187 #endif
188 
189 /* #ifndef KP_IMPL_SUPPORT_INTERFACES2
190 #define KP_IMPL_SUPPORT_INTERFACES2(__kp_class,__kp_iid1,__kp_int1,__kp_iid2,__kp_int2) \
191  STDMETHODIMP __kp_class##::QueryInterface(REFIID riid, void** ppvObject) { \
192  KP_SUPPORT_INTERFACE(__kp_iid1, __kp_int1); \
193  KP_SUPPORT_INTERFACE(__kp_iid2, __kp_int2); \
194  *ppvObject = NULL; return E_NOINTERFACE; }
195 #endif */
196 
197 #ifndef KP_ASSERT_REFS
198 #define KP_ASSERT_REFS(__kp_comobj,__kp_refcnt) ASSERT((__kp_comobj).AddRef() \
199  > 0); ASSERT((__kp_comobj).Release() == (__kp_refcnt));
200 #endif
201 
202 #ifndef KP_REQ_OUT_PTR
203 #define KP_REQ_OUT_PTR(__kp_ppv) { if((__kp_ppv) == NULL) { assert(false); \
204  return E_POINTER; } }
205 #endif
206 
207 #ifndef KP_REQ_OUT_PTR_INIT
208 #define KP_REQ_OUT_PTR_INIT(__kp_ppvx) { KP_REQ_OUT_PTR(__kp_ppvx); \
209  *(__kp_ppvx) = NULL; }
210 #endif
211 
212 // For use in CreateInstanceEx:
213 #ifndef KP_QUERY_INTERFACE_RELEASE_LOCAL_RET
214 #define KP_QUERY_INTERFACE_RELEASE_LOCAL_RET(__kp_comobj,__kp_riid,__kp_ppvout) { \
215  void* __kp_ip = NULL; if((__kp_comobj)->QueryInterface((__kp_riid), &__kp_ip) == \
216  S_OK) { *(__kp_ppvout) = __kp_ip; VERIFY((__kp_comobj)->Release() == 1); \
217  return S_OK; } else { VERIFY((__kp_comobj)->Release() == 0); return E_NOINTERFACE; } }
218 #endif
219 
220 #endif // ___SYS_DEF_EX_H___

Documentation generated with Doxygen.





Get KeePass