diff options
Diffstat (limited to 'src/libs/dutil/WixToolset.DUtil/inc/dutil.h')
-rw-r--r-- | src/libs/dutil/WixToolset.DUtil/inc/dutil.h | 190 |
1 files changed, 190 insertions, 0 deletions
diff --git a/src/libs/dutil/WixToolset.DUtil/inc/dutil.h b/src/libs/dutil/WixToolset.DUtil/inc/dutil.h new file mode 100644 index 00000000..fc9ec0f4 --- /dev/null +++ b/src/libs/dutil/WixToolset.DUtil/inc/dutil.h | |||
@@ -0,0 +1,190 @@ | |||
1 | #pragma once | ||
2 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
3 | |||
4 | #include "dutilsources.h" | ||
5 | |||
6 | #define DAPI __stdcall | ||
7 | #define DAPIV __cdecl // used only for functions taking variable length arguments | ||
8 | |||
9 | #define DAPI_(type) EXTERN_C type DAPI | ||
10 | #define DAPIV_(type) EXTERN_C type DAPIV | ||
11 | |||
12 | |||
13 | // asserts and traces | ||
14 | typedef BOOL (DAPI *DUTIL_ASSERTDISPLAYFUNCTION)(__in_z LPCSTR sz); | ||
15 | |||
16 | typedef void (CALLBACK *DUTIL_CALLBACK_TRACEERROR)( | ||
17 | __in_z LPCSTR szFile, | ||
18 | __in int iLine, | ||
19 | __in REPORT_LEVEL rl, | ||
20 | __in UINT source, | ||
21 | __in HRESULT hrError, | ||
22 | __in_z __format_string LPCSTR szFormat, | ||
23 | __in va_list args | ||
24 | ); | ||
25 | |||
26 | #ifdef __cplusplus | ||
27 | extern "C" { | ||
28 | #endif | ||
29 | |||
30 | /******************************************************************** | ||
31 | DutilInitialize - initialize dutil. | ||
32 | |||
33 | *******************************************************************/ | ||
34 | HRESULT DAPI DutilInitialize( | ||
35 | __in_opt DUTIL_CALLBACK_TRACEERROR pfnTraceErrorCallback | ||
36 | ); | ||
37 | |||
38 | /******************************************************************** | ||
39 | DutilUninitialize - uninitialize dutil. | ||
40 | |||
41 | *******************************************************************/ | ||
42 | void DAPI DutilUninitialize(); | ||
43 | |||
44 | void DAPI Dutil_SetAssertModule(__in HMODULE hAssertModule); | ||
45 | void DAPI Dutil_SetAssertDisplayFunction(__in DUTIL_ASSERTDISPLAYFUNCTION pfn); | ||
46 | void DAPI Dutil_Assert(__in_z LPCSTR szFile, __in int iLine); | ||
47 | void DAPI Dutil_AssertSz(__in_z LPCSTR szFile, __in int iLine, __in_z __format_string LPCSTR szMessage); | ||
48 | |||
49 | void DAPI Dutil_TraceSetLevel(__in REPORT_LEVEL ll, __in BOOL fTraceFilenames); | ||
50 | REPORT_LEVEL DAPI Dutil_TraceGetLevel(); | ||
51 | void DAPIV Dutil_Trace(__in_z LPCSTR szFile, __in int iLine, __in REPORT_LEVEL rl, __in_z __format_string LPCSTR szMessage, ...); | ||
52 | void DAPIV Dutil_TraceError(__in_z LPCSTR szFile, __in int iLine, __in REPORT_LEVEL rl, __in HRESULT hr, __in_z __format_string LPCSTR szMessage, ...); | ||
53 | void DAPIV Dutil_TraceErrorSource(__in_z LPCSTR szFile, __in int iLine, __in REPORT_LEVEL rl, __in UINT source, __in HRESULT hr, __in_z __format_string LPCSTR szMessage, ...); | ||
54 | void DAPI Dutil_RootFailure(__in_z LPCSTR szFile, __in int iLine, __in HRESULT hrError); | ||
55 | |||
56 | #ifdef __cplusplus | ||
57 | } | ||
58 | #endif | ||
59 | |||
60 | |||
61 | #ifdef DEBUG | ||
62 | |||
63 | #define AssertSetModule(m) (void)Dutil_SetAssertModule(m) | ||
64 | #define AssertSetDisplayFunction(pfn) (void)Dutil_SetAssertDisplayFunction(pfn) | ||
65 | #define Assert(f) ((f) ? (void)0 : (void)Dutil_Assert(__FILE__, __LINE__)) | ||
66 | #define AssertSz(f, sz) ((f) ? (void)0 : (void)Dutil_AssertSz(__FILE__, __LINE__, sz)) | ||
67 | |||
68 | #define TraceSetLevel(l, f) (void)Dutil_TraceSetLevel(l, f) | ||
69 | #define TraceGetLevel() (REPORT_LEVEL)Dutil_TraceGetLevel() | ||
70 | #define Trace(l, f, ...) (void)Dutil_Trace(__FILE__, __LINE__, l, f, __VA_ARGS__) | ||
71 | #define TraceError(x, f, ...) (void)Dutil_TraceError(__FILE__, __LINE__, REPORT_ERROR, x, f, __VA_ARGS__) | ||
72 | #define TraceErrorDebug(x, f, ...) (void)Dutil_TraceError(__FILE__, __LINE__, REPORT_DEBUG, x, f, __VA_ARGS__) | ||
73 | |||
74 | #else // !DEBUG | ||
75 | |||
76 | #define AssertSetModule(m) | ||
77 | #define AssertSetDisplayFunction(pfn) | ||
78 | #define Assert(f) | ||
79 | #define AssertSz(f, sz) | ||
80 | |||
81 | #define TraceSetLevel(l, f) | ||
82 | #define Trace(l, f, ...) | ||
83 | #define TraceError(x, f, ...) | ||
84 | #define TraceErrorDebug(x, f, ...) | ||
85 | |||
86 | #endif // DEBUG | ||
87 | |||
88 | // DUTIL_SOURCE_DEFAULT can be overriden | ||
89 | #ifndef DUTIL_SOURCE_DEFAULT | ||
90 | #define DUTIL_SOURCE_DEFAULT DUTIL_SOURCE_UNKNOWN | ||
91 | #endif | ||
92 | |||
93 | // Exit macros | ||
94 | #define ExitFunction() { goto LExit; } | ||
95 | #define ExitFunction1(x) { x; goto LExit; } | ||
96 | |||
97 | #define ExitFunctionWithLastError(x) { x = HRESULT_FROM_WIN32(::GetLastError()); goto LExit; } | ||
98 | |||
99 | #define ExitTraceSource(d, x, s, ...) { TraceError(x, s, __VA_ARGS__); (void)Dutil_TraceErrorSource(__FILE__, __LINE__, REPORT_ERROR, d, x, s, __VA_ARGS__); } | ||
100 | #define ExitTraceDebugSource(d, x, s, ...) { TraceErrorDebug(x, s, __VA_ARGS__); (void)Dutil_TraceErrorSource(__FILE__, __LINE__, REPORT_DEBUG, d, x, s, __VA_ARGS__); } | ||
101 | |||
102 | #define ExitOnLastErrorSource(d, x, s, ...) { DWORD Dutil_er = ::GetLastError(); x = HRESULT_FROM_WIN32(Dutil_er); if (FAILED(x)) { Dutil_RootFailure(__FILE__, __LINE__, x); ExitTraceSource(d, x, s, __VA_ARGS__); goto LExit; } } | ||
103 | #define ExitOnLastErrorDebugTraceSource(d, x, s, ...) { DWORD Dutil_er = ::GetLastError(); x = HRESULT_FROM_WIN32(Dutil_er); if (FAILED(x)) { Dutil_RootFailure(__FILE__, __LINE__, x); ExitTraceDebugSource(d, x, s, __VA_ARGS__); goto LExit; } } | ||
104 | #define ExitWithLastErrorSource(d, x, s, ...) { DWORD Dutil_er = ::GetLastError(); x = HRESULT_FROM_WIN32(Dutil_er); if (!FAILED(x)) { x = E_FAIL; } Dutil_RootFailure(__FILE__, __LINE__, x); ExitTraceSource(d, x, s, __VA_ARGS__); goto LExit; } | ||
105 | #define ExitOnFailureSource(d, x, s, ...) if (FAILED(x)) { ExitTraceSource(d, x, s, __VA_ARGS__); goto LExit; } | ||
106 | #define ExitOnRootFailureSource(d, x, s, ...) if (FAILED(x)) { Dutil_RootFailure(__FILE__, __LINE__, x); ExitTraceSource(d, x, s, __VA_ARGS__); goto LExit; } | ||
107 | #define ExitOnFailureDebugTraceSource(d, x, s, ...) if (FAILED(x)) { ExitTraceDebugSource(d, x, s, __VA_ARGS__); goto LExit; } | ||
108 | #define ExitOnNullSource(d, p, x, e, s, ...) if (NULL == p) { x = e; Dutil_RootFailure(__FILE__, __LINE__, x); ExitTraceSource(d, x, s, __VA_ARGS__); goto LExit; } | ||
109 | #define ExitOnNullWithLastErrorSource(d, p, x, s, ...) if (NULL == p) { DWORD Dutil_er = ::GetLastError(); x = HRESULT_FROM_WIN32(Dutil_er); if (!FAILED(x)) { x = E_FAIL; } Dutil_RootFailure(__FILE__, __LINE__, x); ExitTraceSource(d, x, s, __VA_ARGS__); goto LExit; } | ||
110 | #define ExitOnNullDebugTraceSource(d, p, x, e, s, ...) if (NULL == p) { x = e; Dutil_RootFailure(__FILE__, __LINE__, x); ExitTraceDebugSource(d, x, s, __VA_ARGS__); goto LExit; } | ||
111 | #define ExitOnInvalidHandleWithLastErrorSource(d, p, x, s, ...) if (INVALID_HANDLE_VALUE == p) { DWORD Dutil_er = ::GetLastError(); x = HRESULT_FROM_WIN32(Dutil_er); if (!FAILED(x)) { x = E_FAIL; } Dutil_RootFailure(__FILE__, __LINE__, x); ExitTraceSource(d, x, s, __VA_ARGS__); goto LExit; } | ||
112 | #define ExitOnWin32ErrorSource(d, e, x, s, ...) if (ERROR_SUCCESS != e) { x = HRESULT_FROM_WIN32(e); if (!FAILED(x)) { x = E_FAIL; } Dutil_RootFailure(__FILE__, __LINE__, x); ExitTraceSource(d, x, s, __VA_ARGS__); goto LExit; } | ||
113 | |||
114 | #define ExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_DEFAULT, x, s, __VA_ARGS__) | ||
115 | #define ExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_DEFAULT, x, s, __VA_ARGS__) | ||
116 | #define ExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_DEFAULT, x, s, __VA_ARGS__) | ||
117 | #define ExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_DEFAULT, x, s, __VA_ARGS__) | ||
118 | #define ExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_DEFAULT, x, s, __VA_ARGS__) | ||
119 | #define ExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_DEFAULT, x, s, __VA_ARGS__) | ||
120 | #define ExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_DEFAULT, p, x, e, s, __VA_ARGS__) | ||
121 | #define ExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_DEFAULT, p, x, s, __VA_ARGS__) | ||
122 | #define ExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_DEFAULT, p, x, e, s, __VA_ARGS__) | ||
123 | #define ExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_DEFAULT, p, x, s, __VA_ARGS__) | ||
124 | #define ExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_DEFAULT, e, x, s, __VA_ARGS__) | ||
125 | |||
126 | // release macros | ||
127 | #define ReleaseObject(x) if (x) { x->Release(); } | ||
128 | #define ReleaseObjectArray(prg, cel) if (prg) { for (DWORD Dutil_ReleaseObjectArrayIndex = 0; Dutil_ReleaseObjectArrayIndex < cel; ++Dutil_ReleaseObjectArrayIndex) { ReleaseObject(prg[Dutil_ReleaseObjectArrayIndex]); } ReleaseMem(prg); } | ||
129 | #define ReleaseVariant(x) { ::VariantClear(&x); } | ||
130 | #define ReleaseNullObject(x) if (x) { (x)->Release(); x = NULL; } | ||
131 | #define ReleaseCertificate(x) if (x) { ::CertFreeCertificateContext(x); x=NULL; } | ||
132 | #define ReleaseHandle(x) if (x) { ::CloseHandle(x); x = NULL; } | ||
133 | |||
134 | |||
135 | // useful defines and macros | ||
136 | #define Unused(x) ((void)x) | ||
137 | |||
138 | #ifndef countof | ||
139 | #if 1 | ||
140 | #define countof(ary) (sizeof(ary) / sizeof(ary[0])) | ||
141 | #else | ||
142 | #ifndef __cplusplus | ||
143 | #define countof(ary) (sizeof(ary) / sizeof(ary[0])) | ||
144 | #else | ||
145 | template<typename T> static char countofVerify(void const *, T) throw() { return 0; } | ||
146 | template<typename T> static void countofVerify(T *const, T *const *) throw() {}; | ||
147 | #define countof(arr) (sizeof(countofVerify(arr,&(arr))) * sizeof(arr)/sizeof(*(arr))) | ||
148 | #endif | ||
149 | #endif | ||
150 | #endif | ||
151 | |||
152 | #define roundup(x, n) roundup_typed(x, n, DWORD) | ||
153 | #define roundup_typed(x, n, t) (((t)(x) + ((t)(n) - 1)) & ~((t)(n) - 1)) | ||
154 | |||
155 | #define HRESULT_FROM_RPC(x) ((HRESULT) ((x) | FACILITY_RPC)) | ||
156 | |||
157 | #ifndef MAXSIZE_T | ||
158 | #define MAXSIZE_T ((SIZE_T)~((SIZE_T)0)) | ||
159 | #endif | ||
160 | |||
161 | typedef const BYTE* LPCBYTE; | ||
162 | |||
163 | #define E_FILENOTFOUND HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) | ||
164 | #define E_PATHNOTFOUND HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) | ||
165 | #define E_INVALIDDATA HRESULT_FROM_WIN32(ERROR_INVALID_DATA) | ||
166 | #define E_INVALIDSTATE HRESULT_FROM_WIN32(ERROR_INVALID_STATE) | ||
167 | #define E_INSUFFICIENT_BUFFER HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) | ||
168 | #define E_MOREDATA HRESULT_FROM_WIN32(ERROR_MORE_DATA) | ||
169 | #define E_NOMOREITEMS HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS) | ||
170 | #define E_NOTFOUND HRESULT_FROM_WIN32(ERROR_NOT_FOUND) | ||
171 | #define E_MODNOTFOUND HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND) | ||
172 | #define E_BADCONFIGURATION HRESULT_FROM_WIN32(ERROR_BAD_CONFIGURATION) | ||
173 | |||
174 | #define AddRefAndRelease(x) { x->AddRef(); x->Release(); } | ||
175 | |||
176 | #define MAKEDWORD(lo, hi) ((DWORD)MAKELONG(lo, hi)) | ||
177 | #define MAKEQWORDVERSION(mj, mi, b, r) (((DWORD64)MAKELONG(r, b)) | (((DWORD64)MAKELONG(mi, mj)) << 32)) | ||
178 | |||
179 | |||
180 | #ifdef __cplusplus | ||
181 | extern "C" { | ||
182 | #endif | ||
183 | |||
184 | // other functions | ||
185 | HRESULT DAPI LoadSystemLibrary(__in_z LPCWSTR wzModuleName, __out HMODULE *phModule); | ||
186 | HRESULT DAPI LoadSystemLibraryWithPath(__in_z LPCWSTR wzModuleName, __out HMODULE *phModule, __deref_out_z_opt LPWSTR* psczPath); | ||
187 | |||
188 | #ifdef __cplusplus | ||
189 | } | ||
190 | #endif | ||