aboutsummaryrefslogtreecommitdiff
path: root/src/dutil/resrutil.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/dutil/resrutil.cpp45
1 files changed, 30 insertions, 15 deletions
diff --git a/src/dutil/resrutil.cpp b/src/dutil/resrutil.cpp
index 1da03ed9..a6a7ee23 100644
--- a/src/dutil/resrutil.cpp
+++ b/src/dutil/resrutil.cpp
@@ -2,6 +2,21 @@
2 2
3#include "precomp.h" 3#include "precomp.h"
4 4
5
6// Exit macros
7#define ResrExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_RESRUTIL, x, s, __VA_ARGS__)
8#define ResrExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_RESRUTIL, x, s, __VA_ARGS__)
9#define ResrExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_RESRUTIL, x, s, __VA_ARGS__)
10#define ResrExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_RESRUTIL, x, s, __VA_ARGS__)
11#define ResrExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_RESRUTIL, x, s, __VA_ARGS__)
12#define ResrExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_RESRUTIL, x, s, __VA_ARGS__)
13#define ResrExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_RESRUTIL, p, x, e, s, __VA_ARGS__)
14#define ResrExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_RESRUTIL, p, x, s, __VA_ARGS__)
15#define ResrExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_RESRUTIL, p, x, e, s, __VA_ARGS__)
16#define ResrExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_RESRUTIL, p, x, s, __VA_ARGS__)
17#define ResrExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_RESRUTIL, e, x, s, __VA_ARGS__)
18#define ResrExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_RESRUTIL, g, x, s, __VA_ARGS__)
19
5#define RES_STRINGS_PER_BLOCK 16 20#define RES_STRINGS_PER_BLOCK 16
6 21
7 22
@@ -33,7 +48,7 @@ extern "C" HRESULT DAPI ResGetStringLangId(
33 if (wzPath && *wzPath) 48 if (wzPath && *wzPath)
34 { 49 {
35 hModule = LoadLibraryExW(wzPath, NULL, DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE); 50 hModule = LoadLibraryExW(wzPath, NULL, DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE);
36 ExitOnNullWithLastError(hModule, hr, "Failed to open resource file: %ls", wzPath); 51 ResrExitOnNullWithLastError(hModule, hr, "Failed to open resource file: %ls", wzPath);
37 } 52 }
38 53
39#pragma prefast(push) 54#pragma prefast(push)
@@ -41,7 +56,7 @@ extern "C" HRESULT DAPI ResGetStringLangId(
41 if (!::EnumResourceLanguagesA(hModule, RT_STRING, MAKEINTRESOURCE(dwBlockId), static_cast<ENUMRESLANGPROC>(EnumLangIdProc), reinterpret_cast<LONG_PTR>(&wFoundLangId))) 56 if (!::EnumResourceLanguagesA(hModule, RT_STRING, MAKEINTRESOURCE(dwBlockId), static_cast<ENUMRESLANGPROC>(EnumLangIdProc), reinterpret_cast<LONG_PTR>(&wFoundLangId)))
42#pragma prefast(pop) 57#pragma prefast(pop)
43 { 58 {
44 ExitWithLastError(hr, "Failed to find string language identifier."); 59 ResrExitWithLastError(hr, "Failed to find string language identifier.");
45 } 60 }
46 61
47 *pwLangId = wFoundLangId; 62 *pwLangId = wFoundLangId;
@@ -76,12 +91,12 @@ extern "C" HRESULT DAPI ResReadString(
76 do 91 do
77 { 92 {
78 hr = StrAlloc(ppwzString, cch); 93 hr = StrAlloc(ppwzString, cch);
79 ExitOnFailureDebugTrace(hr, "Failed to allocate string for resource id: %d", uID); 94 ResrExitOnFailureDebugTrace(hr, "Failed to allocate string for resource id: %d", uID);
80 95
81 cchReturned = ::LoadStringW(hinst, uID, *ppwzString, cch); 96 cchReturned = ::LoadStringW(hinst, uID, *ppwzString, cch);
82 if (0 == cchReturned) 97 if (0 == cchReturned)
83 { 98 {
84 ExitWithLastError(hr, "Failed to load string resource id: %d", uID); 99 ResrExitWithLastError(hr, "Failed to load string resource id: %d", uID);
85 } 100 }
86 101
87 // if the returned string count is one character too small, it's likely we have 102 // if the returned string count is one character too small, it's likely we have
@@ -92,7 +107,7 @@ extern "C" HRESULT DAPI ResReadString(
92 hr = S_FALSE; 107 hr = S_FALSE;
93 } 108 }
94 } while (S_FALSE == hr); 109 } while (S_FALSE == hr);
95 ExitOnFailure(hr, "Failed to load string resource id: %d", uID); 110 ResrExitOnFailure(hr, "Failed to load string resource id: %d", uID);
96 111
97LExit: 112LExit:
98 return hr; 113 return hr;
@@ -119,7 +134,7 @@ extern "C" HRESULT DAPI ResReadStringAnsi(
119 do 134 do
120 { 135 {
121 hr = StrAnsiAlloc(ppszString, cch); 136 hr = StrAnsiAlloc(ppszString, cch);
122 ExitOnFailureDebugTrace(hr, "Failed to allocate string for resource id: %d", uID); 137 ResrExitOnFailureDebugTrace(hr, "Failed to allocate string for resource id: %d", uID);
123 138
124#pragma prefast(push) 139#pragma prefast(push)
125#pragma prefast(disable:25068) 140#pragma prefast(disable:25068)
@@ -127,7 +142,7 @@ extern "C" HRESULT DAPI ResReadStringAnsi(
127#pragma prefast(pop) 142#pragma prefast(pop)
128 if (0 == cchReturned) 143 if (0 == cchReturned)
129 { 144 {
130 ExitWithLastError(hr, "Failed to load string resource id: %d", uID); 145 ResrExitWithLastError(hr, "Failed to load string resource id: %d", uID);
131 } 146 }
132 147
133 // if the returned string count is one character too small, it's likely we have 148 // if the returned string count is one character too small, it's likely we have
@@ -138,7 +153,7 @@ extern "C" HRESULT DAPI ResReadStringAnsi(
138 hr = S_FALSE; 153 hr = S_FALSE;
139 } 154 }
140 } while (S_FALSE == hr); 155 } while (S_FALSE == hr);
141 ExitOnFailure(hr, "failed to load string resource id: %d", uID); 156 ResrExitOnFailure(hr, "failed to load string resource id: %d", uID);
142 157
143LExit: 158LExit:
144 return hr; 159 return hr;
@@ -169,19 +184,19 @@ extern "C" HRESULT DAPI ResReadData(
169#pragma prefast(disable:25068) 184#pragma prefast(disable:25068)
170 hRsrc = ::FindResourceExA(hinst, RT_RCDATA, szDataName, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)); 185 hRsrc = ::FindResourceExA(hinst, RT_RCDATA, szDataName, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
171#pragma prefast(pop) 186#pragma prefast(pop)
172 ExitOnNullWithLastError(hRsrc, hr, "Failed to find resource."); 187 ResrExitOnNullWithLastError(hRsrc, hr, "Failed to find resource.");
173 188
174 hData = ::LoadResource(hinst, hRsrc); 189 hData = ::LoadResource(hinst, hRsrc);
175 ExitOnNullWithLastError(hData, hr, "Failed to load resource."); 190 ResrExitOnNullWithLastError(hData, hr, "Failed to load resource.");
176 191
177 cbData = ::SizeofResource(hinst, hRsrc); 192 cbData = ::SizeofResource(hinst, hRsrc);
178 if (!cbData) 193 if (!cbData)
179 { 194 {
180 ExitWithLastError(hr, "Failed to get size of resource."); 195 ResrExitWithLastError(hr, "Failed to get size of resource.");
181 } 196 }
182 197
183 *ppv = ::LockResource(hData); 198 *ppv = ::LockResource(hData);
184 ExitOnNullWithLastError(*ppv, hr, "Failed to lock data resource."); 199 ResrExitOnNullWithLastError(*ppv, hr, "Failed to lock data resource.");
185 *pcb = cbData; 200 *pcb = cbData;
186 201
187LExit: 202LExit:
@@ -207,18 +222,18 @@ extern "C" HRESULT DAPI ResExportDataToFile(
207 BOOL bCreatedFile = FALSE; 222 BOOL bCreatedFile = FALSE;
208 223
209 hr = ResReadData(NULL, szDataName, &pData, &cbData); 224 hr = ResReadData(NULL, szDataName, &pData, &cbData);
210 ExitOnFailure(hr, "Failed to GetData from %s.", szDataName); 225 ResrExitOnFailure(hr, "Failed to GetData from %s.", szDataName);
211 226
212 hFile = ::CreateFileW(wzTargetFile, GENERIC_WRITE, 0, NULL, dwCreationDisposition, FILE_ATTRIBUTE_NORMAL, NULL); 227 hFile = ::CreateFileW(wzTargetFile, GENERIC_WRITE, 0, NULL, dwCreationDisposition, FILE_ATTRIBUTE_NORMAL, NULL);
213 if (INVALID_HANDLE_VALUE == hFile) 228 if (INVALID_HANDLE_VALUE == hFile)
214 { 229 {
215 ExitWithLastError(hr, "Failed to CreateFileW for %ls.", wzTargetFile); 230 ResrExitWithLastError(hr, "Failed to CreateFileW for %ls.", wzTargetFile);
216 } 231 }
217 bCreatedFile = TRUE; 232 bCreatedFile = TRUE;
218 233
219 if (!::WriteFile(hFile, pData, cbData, &cbWritten, NULL)) 234 if (!::WriteFile(hFile, pData, cbData, &cbWritten, NULL))
220 { 235 {
221 ExitWithLastError(hr, "Failed to ::WriteFile for %ls.", wzTargetFile); 236 ResrExitWithLastError(hr, "Failed to ::WriteFile for %ls.", wzTargetFile);
222 } 237 }
223 238
224LExit: 239LExit: