@joebigelow / wix-1 / commits / 10ebf674

Update rest of dutil to use their own source with the Exit* macros. Fix some CA warnings.

Update rest of dutil to use their own source with the Exit* macros. Fix some CA warnings.

Sean Hall committed Mar 2, 2021 at 14:19 UTC 10ebf674da5df9224e4eddd3545518434c5b455b
73 files changed +2779 -1953
src/dutil/acl2util.cpp
+22 -8
@@ -2,6 +2,20 @@
2
3 #include "precomp.h"
4
5 +// Exit macros
6 +#define AclExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_ACLUTIL, x, s, __VA_ARGS__)
7 +#define AclExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_ACLUTIL, x, s, __VA_ARGS__)
8 +#define AclExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_ACLUTIL, x, s, __VA_ARGS__)
9 +#define AclExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_ACLUTIL, x, s, __VA_ARGS__)
10 +#define AclExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_ACLUTIL, x, s, __VA_ARGS__)
11 +#define AclExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_ACLUTIL, x, s, __VA_ARGS__)
12 +#define AclExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_ACLUTIL, p, x, e, s, __VA_ARGS__)
13 +#define AclExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_ACLUTIL, p, x, s, __VA_ARGS__)
14 +#define AclExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_ACLUTIL, p, x, e, s, __VA_ARGS__)
15 +#define AclExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_ACLUTIL, p, x, s, __VA_ARGS__)
16 +#define AclExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_ACLUTIL, e, x, s, __VA_ARGS__)
17 +#define AclExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_ACLUTIL, g, x, s, __VA_ARGS__)
18 +
19 /********************************************************************
20 AclCalculateServiceSidString - gets the SID string for the given service name
21
@@ -26,17 +40,17 @@ extern "C" HRESULT DAPI AclCalculateServiceSidString(
40 if (0 == cchServiceName)
41 {
42 hr = ::StringCchLengthW(wzServiceName, INT_MAX, reinterpret_cast<size_t*>(&cchServiceName));
29 - ExitOnFailure(hr, "Failed to get the length of the service name.");
43 + AclExitOnFailure(hr, "Failed to get the length of the service name.");
44 }
45
46 hr = StrAllocStringToUpperInvariant(&sczUpperServiceName, wzServiceName, cchServiceName);
33 - ExitOnFailure(hr, "Failed to upper case the service name.");
47 + AclExitOnFailure(hr, "Failed to upper case the service name.");
48
49 pbHash = reinterpret_cast<BYTE*>(MemAlloc(cbHash, TRUE));
36 - ExitOnNull(pbHash, hr, E_OUTOFMEMORY, "Failed to allocate hash byte array.");
50 + AclExitOnNull(pbHash, hr, E_OUTOFMEMORY, "Failed to allocate hash byte array.");
51
52 hr = CrypHashBuffer(reinterpret_cast<BYTE*>(sczUpperServiceName), cchServiceName * 2, PROV_RSA_FULL, CALG_SHA1, pbHash, cbHash);
39 - ExitOnNull(pbHash, hr, E_OUTOFMEMORY, "Failed to hash the service name.");
53 + AclExitOnNull(pbHash, hr, E_OUTOFMEMORY, "Failed to hash the service name.");
54
55 hr = StrAllocFormatted(psczSid, L"S-1-5-80-%u-%u-%u-%u-%u",
56 MAKEDWORD(MAKEWORD(pbHash[0], pbHash[1]), MAKEWORD(pbHash[2], pbHash[3])),
@@ -80,7 +94,7 @@ extern "C" HRESULT DAPI AclGetAccountSidStringEx(
94
95 if (!::ConvertSidToStringSidW(psid, &pwz))
96 {
83 - ExitWithLastError(hr, "Failed to convert SID to string for Account: %ls", wzAccount);
97 + AclExitWithLastError(hr, "Failed to convert SID to string for Account: %ls", wzAccount);
98 }
99
100 hr = StrAllocString(psczSid, pwz, 0);
@@ -90,20 +104,20 @@ extern "C" HRESULT DAPI AclGetAccountSidStringEx(
104 if (HRESULT_FROM_WIN32(ERROR_NONE_MAPPED) == hr)
105 {
106 HRESULT hrLength = ::StringCchLengthW(wzAccount, INT_MAX, reinterpret_cast<size_t*>(&cchAccount));
93 - ExitOnFailure(hrLength, "Failed to get the length of the account name.");
107 + AclExitOnFailure(hrLength, "Failed to get the length of the account name.");
108
109 if (11 < cchAccount && CSTR_EQUAL == CompareStringW(LOCALE_NEUTRAL, NORM_IGNORECASE, L"NT SERVICE\\", 11, wzAccount, 11))
110 {
111 // If the service is not installed then LookupAccountName doesn't resolve the SID, but we can calculate it.
112 LPCWSTR wzServiceName = &wzAccount[11];
113 hr = AclCalculateServiceSidString(wzServiceName, cchAccount - 11, &sczSid);
100 - ExitOnFailure(hr, "Failed to calculate the service SID for %ls", wzServiceName);
114 + AclExitOnFailure(hr, "Failed to calculate the service SID for %ls", wzServiceName);
115
116 *psczSid = sczSid;
117 sczSid = NULL;
118 }
119 }
106 - ExitOnFailure(hr, "Failed to get SID for account: %ls", wzAccount);
120 + AclExitOnFailure(hr, "Failed to get SID for account: %ls", wzAccount);
121 }
122
123 LExit:
src/dutil/aclutil.cpp
+70 -56
@@ -2,6 +2,20 @@
2
3 #include "precomp.h"
4
5 +// Exit macros
6 +#define AclExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_ACLUTIL, x, s, __VA_ARGS__)
7 +#define AclExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_ACLUTIL, x, s, __VA_ARGS__)
8 +#define AclExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_ACLUTIL, x, s, __VA_ARGS__)
9 +#define AclExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_ACLUTIL, x, s, __VA_ARGS__)
10 +#define AclExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_ACLUTIL, x, s, __VA_ARGS__)
11 +#define AclExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_ACLUTIL, x, s, __VA_ARGS__)
12 +#define AclExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_ACLUTIL, p, x, e, s, __VA_ARGS__)
13 +#define AclExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_ACLUTIL, p, x, s, __VA_ARGS__)
14 +#define AclExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_ACLUTIL, p, x, e, s, __VA_ARGS__)
15 +#define AclExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_ACLUTIL, p, x, s, __VA_ARGS__)
16 +#define AclExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_ACLUTIL, e, x, s, __VA_ARGS__)
17 +#define AclExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_ACLUTIL, g, x, s, __VA_ARGS__)
18 +
19 /********************************************************************
20 AclCheckAccess - determines if token has appropriate privileges
21
@@ -18,25 +32,25 @@ extern "C" HRESULT DAPI AclCheckAccess(
32 PSID psid = NULL;
33 BOOL fIsMember = FALSE;
34
21 - ExitOnNull(paa, hr, E_INVALIDARG, "Failed to check ACL access, because no acl access provided to check");
35 + AclExitOnNull(paa, hr, E_INVALIDARG, "Failed to check ACL access, because no acl access provided to check");
36 Assert(0 == paa->fDenyAccess && 0 == paa->dwAccessMask);
37
38 if (paa->pwzAccountName)
39 {
40 hr = AclGetAccountSid(NULL, paa->pwzAccountName, &psid);
27 - ExitOnFailure(hr, "failed to get SID for account: %ls", paa->pwzAccountName);
41 + AclExitOnFailure(hr, "failed to get SID for account: %ls", paa->pwzAccountName);
42 }
43 else
44 {
45 if (!::AllocateAndInitializeSid(&paa->sia, paa->nSubAuthorityCount, paa->nSubAuthority[0], paa->nSubAuthority[1], paa->nSubAuthority[2], paa->nSubAuthority[3], paa->nSubAuthority[4], paa->nSubAuthority[5], paa->nSubAuthority[6], paa->nSubAuthority[7], &psid))
46 {
33 - ExitWithLastError(hr, "failed to initialize SID");
47 + AclExitWithLastError(hr, "failed to initialize SID");
48 }
49 }
50
51 if (!::CheckTokenMembership(hToken, psid, &fIsMember))
52 {
39 - ExitWithLastError(hr, "failed to check membership");
53 + AclExitWithLastError(hr, "failed to check membership");
54 }
55
56 fIsMember ? hr = S_OK : hr = S_FALSE;
@@ -123,7 +137,7 @@ extern "C" HRESULT DAPI AclGetWellKnownSid(
137 // allocate memory for the SID and get it
138 //
139 psid = static_cast<PSID>(MemAlloc(cbSid, TRUE));
126 - ExitOnNull(psid, hr, E_OUTOFMEMORY, "failed allocate memory for well known SID");
140 + AclExitOnNull(psid, hr, E_OUTOFMEMORY, "failed allocate memory for well known SID");
141
142 #if(_WIN32_WINNT < 0x0501)
143 switch (wkst)
@@ -160,19 +174,19 @@ extern "C" HRESULT DAPI AclGetWellKnownSid(
174 break;
175 default:
176 hr = E_INVALIDARG;
163 - ExitOnFailure(hr, "unknown well known SID: %d", wkst);
177 + AclExitOnFailure(hr, "unknown well known SID: %d", wkst);
178 }
179
180 if (!fSuccess)
167 - ExitOnLastError(hr, "failed to allocate well known SID: %d", wkst);
181 + AclExitOnLastError(hr, "failed to allocate well known SID: %d", wkst);
182
183 if (!::CopySid(cbSid, psid, psidTemp))
170 - ExitOnLastError(hr, "failed to create well known SID: %d", wkst);
184 + AclExitOnLastError(hr, "failed to create well known SID: %d", wkst);
185 #else
186 Assert(NULL == psidTemp);
187 if (!::CreateWellKnownSid(wkst, NULL, psid, &cbSid))
188 {
175 - ExitWithLastError(hr, "failed to create well known SID: %d", wkst);
189 + AclExitWithLastError(hr, "failed to create well known SID: %d", wkst);
190 }
191 #endif
192
@@ -216,9 +230,9 @@ extern "C" HRESULT DAPI AclGetAccountSid(
230 // allocate memory for the SID and domain name
231 //
232 psid = static_cast<PSID>(MemAlloc(cbSid, TRUE));
219 - ExitOnNull(psid, hr, E_OUTOFMEMORY, "failed to allocate memory for SID");
233 + AclExitOnNull(psid, hr, E_OUTOFMEMORY, "failed to allocate memory for SID");
234 hr = StrAlloc(&pwzDomainName, cbDomainName);
221 - ExitOnFailure(hr, "failed to allocate string for domain name");
235 + AclExitOnFailure(hr, "failed to allocate string for domain name");
236
237 //
238 // try to lookup the account now
@@ -232,24 +246,24 @@ extern "C" HRESULT DAPI AclGetAccountSid(
246 if (SECURITY_MAX_SID_SIZE < cbSid)
247 {
248 PSID psidNew = static_cast<PSID>(MemReAlloc(psid, cbSid, TRUE));
235 - ExitOnNullWithLastError(psidNew, hr, "failed to allocate memory for account: %ls", wzAccount);
249 + AclExitOnNullWithLastError(psidNew, hr, "failed to allocate memory for account: %ls", wzAccount);
250
251 psid = psidNew;
252 }
253 if (255 < cbDomainName)
254 {
255 hr = StrAlloc(&pwzDomainName, cbDomainName);
242 - ExitOnFailure(hr, "failed to allocate string for domain name");
256 + AclExitOnFailure(hr, "failed to allocate string for domain name");
257 }
258
259 if (!::LookupAccountNameW(wzSystem, wzAccount, psid, &cbSid, pwzDomainName, &cbDomainName, &peUse))
260 {
247 - ExitWithLastError(hr, "failed to lookup account: %ls", wzAccount);
261 + AclExitWithLastError(hr, "failed to lookup account: %ls", wzAccount);
262 }
263 }
264 else
265 {
252 - ExitOnWin32Error(er, hr, "failed to lookup account: %ls", wzAccount);
266 + AclExitOnWin32Error(er, hr, "failed to lookup account: %ls", wzAccount);
267 }
268 }
269
@@ -284,12 +298,12 @@ extern "C" HRESULT DAPI AclGetAccountSidString(
298 *ppwzSid = NULL;
299
300 hr = AclGetAccountSid(wzSystem, wzAccount, &psid);
287 - ExitOnFailure(hr, "failed to get SID for account: %ls", wzAccount);
301 + AclExitOnFailure(hr, "failed to get SID for account: %ls", wzAccount);
302 Assert(::IsValidSid(psid));
303
304 if (!::ConvertSidToStringSidW(psid, &pwz))
305 {
292 - ExitWithLastError(hr, "failed to convert SID to string for Account: %ls", wzAccount);
306 + AclExitWithLastError(hr, "failed to convert SID to string for Account: %ls", wzAccount);
307 }
308
309 hr = StrAllocString(ppwzSid, pwz, 0);
@@ -347,14 +361,14 @@ extern "C" HRESULT DAPI AclCreateDacl(
361 }
362
363 pAcl = static_cast<ACL*>(MemAlloc(cbAcl, TRUE));
350 - ExitOnNull(pAcl, hr, E_OUTOFMEMORY, "failed to allocate ACL");
364 + AclExitOnNull(pAcl, hr, E_OUTOFMEMORY, "failed to allocate ACL");
365
366 #pragma prefast(push)
367 #pragma prefast(disable:25029)
368 if (!::InitializeAcl(pAcl, cbAcl, ACL_REVISION))
369 #pragma prefast(pop)
370 {
357 - ExitWithLastError(hr, "failed to initialize ACL");
371 + AclExitWithLastError(hr, "failed to initialize ACL");
372 }
373
374 // add in the ACEs (denied first)
@@ -365,7 +379,7 @@ extern "C" HRESULT DAPI AclCreateDacl(
379 if (!::AddAccessDeniedAceEx(pAcl, ACL_REVISION, rgaaDeny[i].dwFlags, rgaaDeny[i].dwMask, rgaaDeny[i].psid))
380 #pragma prefast(pop)
381 {
368 - ExitWithLastError(hr, "failed to add access denied ACE #%d to ACL", i);
382 + AclExitWithLastError(hr, "failed to add access denied ACE #%d to ACL", i);
383 }
384 }
385 for (i = 0; i < cAllow; ++i)
@@ -375,7 +389,7 @@ extern "C" HRESULT DAPI AclCreateDacl(
389 if (!::AddAccessAllowedAceEx(pAcl, ACL_REVISION, rgaaAllow[i].dwFlags, rgaaAllow[i].dwMask, rgaaAllow[i].psid))
390 #pragma prefast(pop)
391 {
378 - ExitWithLastError(hr, "failed to add access allowed ACE #$d to ACL", i);
392 + AclExitWithLastError(hr, "failed to add access allowed ACE #%d to ACL", i);
393 }
394 }
395
@@ -422,7 +436,7 @@ extern "C" HRESULT DAPI AclAddToDacl(
436 // allocate memory for all the new ACEs (NOTE: this over calculates the memory necessary, but that's okay)
437 if (!::GetAclInformation(pAcl, &asi, sizeof(asi), AclSizeInformation))
438 {
425 - ExitWithLastError(hr, "failed to get information about original ACL");
439 + AclExitWithLastError(hr, "failed to get information about original ACL");
440 }
441
442 if ((asi.AceCount + cDeny) < asi.AceCount || // check for overflow
@@ -430,29 +444,29 @@ extern "C" HRESULT DAPI AclAddToDacl(
444 (asi.AceCount + cDeny) >= MAXSIZE_T / sizeof(ACL_ACE))
445 {
446 hr = E_OUTOFMEMORY;
433 - ExitOnFailure(hr, "Not enough memory to allocate %d ACEs", (asi.AceCount + cDeny));
447 + AclExitOnFailure(hr, "Not enough memory to allocate %d ACEs", (asi.AceCount + cDeny));
448 }
449
450 paaNewDeny = static_cast<ACL_ACE*>(MemAlloc(sizeof(ACL_ACE) * (asi.AceCount + cDeny), TRUE));
437 - ExitOnNull(paaNewDeny, hr, E_OUTOFMEMORY, "failed to allocate memory for new deny ACEs");
451 + AclExitOnNull(paaNewDeny, hr, E_OUTOFMEMORY, "failed to allocate memory for new deny ACEs");
452
453 if ((asi.AceCount + cAllow) < asi.AceCount || // check for overflow
454 (asi.AceCount + cAllow) < cAllow || // check for overflow
455 (asi.AceCount + cAllow) >= MAXSIZE_T / sizeof(ACL_ACE))
456 {
457 hr = E_OUTOFMEMORY;
444 - ExitOnFailure(hr, "Not enough memory to allocate %d ACEs", (asi.AceCount + cAllow));
458 + AclExitOnFailure(hr, "Not enough memory to allocate %d ACEs", (asi.AceCount + cAllow));
459 }
460
461 paaNewAllow = static_cast<ACL_ACE*>(MemAlloc(sizeof(ACL_ACE) * (asi.AceCount + cAllow), TRUE));
448 - ExitOnNull(paaNewAllow, hr, E_OUTOFMEMORY, "failed to allocate memory for new allow ACEs");
462 + AclExitOnNull(paaNewAllow, hr, E_OUTOFMEMORY, "failed to allocate memory for new allow ACEs");
463
464 // fill in the new structures with old data then new data (denied first)
465 for (i = 0; i < asi.AceCount; ++i)
466 {
467 if (!::GetAce(pAcl, i, reinterpret_cast<LPVOID*>(&pada)))
468 {
455 - ExitWithLastError(hr, "failed to get ACE #%d from ACL", i);
469 + AclExitWithLastError(hr, "failed to get ACE #%d from ACL", i);
470 }
471
472 if (ACCESS_DENIED_ACE_TYPE != pada->Header.AceType)
@@ -474,7 +488,7 @@ extern "C" HRESULT DAPI AclAddToDacl(
488 {
489 if (!::GetAce(pAcl, i, reinterpret_cast<LPVOID*>(&paaa)))
490 {
477 - ExitWithLastError(hr, "failed to get ACE #%d from ACL", i);
491 + AclExitWithLastError(hr, "failed to get ACE #%d from ACL", i);
492 }
493
494 if (ACCESS_ALLOWED_ACE_TYPE != paaa->Header.AceType)
@@ -493,7 +507,7 @@ extern "C" HRESULT DAPI AclAddToDacl(
507
508 // create the dacl with the new
509 hr = AclCreateDacl(paaNewDeny, cNewDeny, paaNewAllow, cNewAllow, ppAclNew);
496 - ExitOnFailure(hr, "failed to create new ACL from existing ACL");
510 + AclExitOnFailure(hr, "failed to create new ACL from existing ACL");
511
512 AssertSz(::IsValidAcl(*ppAclNew), "AclAddToDacl() - created invalid ACL");
513 Assert(S_OK == hr);
@@ -551,9 +565,9 @@ extern "C" HRESULT DAPI AclCreateDaclOld(
565 // create the SIDs and calculate the space for the ACL
566 //
567 pdwAccessMask = static_cast<DWORD*>(MemAlloc(sizeof(DWORD) * cAclAccesses, TRUE));
554 - ExitOnNull(pdwAccessMask, hr, E_OUTOFMEMORY, "failed allocate memory for access mask");
568 + AclExitOnNull(pdwAccessMask, hr, E_OUTOFMEMORY, "failed allocate memory for access mask");
569 ppsid = static_cast<PSID*>(MemAlloc(sizeof(PSID) * cAclAccesses, TRUE));
556 - ExitOnNull(ppsid, hr, E_OUTOFMEMORY, "failed allocate memory for sid");
570 + AclExitOnNull(ppsid, hr, E_OUTOFMEMORY, "failed allocate memory for sid");
571
572 cbAcl = sizeof (ACL); // start with the size of the header
573 for (i = 0; i < cAclAccesses; ++i)
@@ -561,7 +575,7 @@ extern "C" HRESULT DAPI AclCreateDaclOld(
575 if (paa[i].pwzAccountName)
576 {
577 hr = AclGetAccountSid(NULL, paa[i].pwzAccountName, ppsid + i);
564 - ExitOnFailure(hr, "failed to get SID for account: %ls", paa[i].pwzAccountName);
578 + AclExitOnFailure(hr, "failed to get SID for account: %ls", paa[i].pwzAccountName);
579 }
580 else
581 {
@@ -572,7 +586,7 @@ extern "C" HRESULT DAPI AclCreateDaclOld(
586 paa[i].nSubAuthority[6], paa[i].nSubAuthority[7],
587 (void**)(ppsid + i))))
588 {
575 - ExitWithLastError(hr, "failed to initialize SIDs #%u", i);
589 + AclExitWithLastError(hr, "failed to initialize SIDs #%u", i);
590 }
591 }
592
@@ -594,14 +608,14 @@ extern "C" HRESULT DAPI AclCreateDaclOld(
608 // allocate the ACL and set the appropriate ACEs
609 //
610 *ppACL = static_cast<ACL*>(MemAlloc(cbAcl, FALSE));
597 - ExitOnNull(*ppACL, hr, E_OUTOFMEMORY, "failed allocate memory for ACL");
611 + AclExitOnNull(*ppACL, hr, E_OUTOFMEMORY, "failed allocate memory for ACL");
612
613 #pragma prefast(push)
614 #pragma prefast(disable:25029)
615 if (!::InitializeAcl(*ppACL, cbAcl, ACL_REVISION))
616 #pragma prefast(pop)
617 {
604 - ExitWithLastError(hr, "failed to initialize ACLs");
618 + AclExitWithLastError(hr, "failed to initialize ACLs");
619 }
620
621 // add an access-allowed ACE for each of the SIDs
@@ -614,7 +628,7 @@ extern "C" HRESULT DAPI AclCreateDaclOld(
628 if (!::AddAccessDeniedAceEx(*ppACL, ACL_REVISION, CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE, pdwAccessMask[i], *(ppsid + i)))
629 #pragma prefast(pop)
630 {
617 - ExitWithLastError(hr, "failed to add access denied for ACE");
631 + AclExitWithLastError(hr, "failed to add access denied for ACE");
632 }
633 }
634 else
@@ -624,7 +638,7 @@ extern "C" HRESULT DAPI AclCreateDaclOld(
638 if (!::AddAccessAllowedAceEx(*ppACL, ACL_REVISION, CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE, pdwAccessMask[i], *(ppsid + i)))
639 #pragma prefast(pop)
640 {
627 - ExitWithLastError(hr, "failed to add access allowed for ACE");
641 + AclExitWithLastError(hr, "failed to add access allowed for ACE");
642 }
643 }
644 }
@@ -669,8 +683,8 @@ extern "C" HRESULT DAPI AclCreateSecurityDescriptorFromDacl(
683 SECURITY_DESCRIPTOR sd;
684 DWORD cbSD;
685
672 - ExitOnNull(pACL, hr, E_INVALIDARG, "Failed to create security descriptor from DACL, because no DACL was provided");
673 - ExitOnNull(ppsd, hr, E_INVALIDARG, "Failed to create security descriptor from DACL, because no output object was provided");
686 + AclExitOnNull(pACL, hr, E_INVALIDARG, "Failed to create security descriptor from DACL, because no DACL was provided");
687 + AclExitOnNull(ppsd, hr, E_INVALIDARG, "Failed to create security descriptor from DACL, because no output object was provided");
688
689 *ppsd = NULL;
690
@@ -687,7 +701,7 @@ extern "C" HRESULT DAPI AclCreateSecurityDescriptorFromDacl(
701 (!::SetSecurityDescriptorOwner(&sd, NULL, FALSE)))
702 #pragma prefast(pop)
703 {
690 - ExitWithLastError(hr, "failed to initialize security descriptor");
704 + AclExitWithLastError(hr, "failed to initialize security descriptor");
705 }
706
707 //
@@ -695,7 +709,7 @@ extern "C" HRESULT DAPI AclCreateSecurityDescriptorFromDacl(
709 //
710 cbSD = ::GetSecurityDescriptorLength(&sd);
711 *ppsd = static_cast<SECURITY_DESCRIPTOR*>(MemAlloc(cbSD, FALSE));
698 - ExitOnNull(*ppsd, hr, E_OUTOFMEMORY, "failed allocate memory for security descriptor");
712 + AclExitOnNull(*ppsd, hr, E_OUTOFMEMORY, "failed allocate memory for security descriptor");
713
714 ::MakeSelfRelativeSD(&sd, (BYTE*)*ppsd, &cbSD);
715 Assert(::IsValidSecurityDescriptor(*ppsd));
@@ -734,7 +748,7 @@ extern "C" HRESULT DAPI AclCreateSecurityDescriptor(
748 // create the DACL
749 //
750 hr = AclCreateDaclOld(paa, cAclAccesses, &pACL);
737 - ExitOnFailure(hr, "failed to create DACL for security descriptor");
751 + AclExitOnFailure(hr, "failed to create DACL for security descriptor");
752
753 //
754 // create self-relative security descriptor
@@ -770,15 +784,15 @@ extern "C" HRESULT DAPI AclCreateSecurityDescriptorFromString(
784 va_start(args, wzSddlFormat);
785 hr = StrAllocFormattedArgs(&pwzSddl, wzSddlFormat, args);
786 va_end(args);
773 - ExitOnFailure(hr, "failed to create SDDL string for format: %ls", wzSddlFormat);
787 + AclExitOnFailure(hr, "failed to create SDDL string for format: %ls", wzSddlFormat);
788
789 if (!::ConvertStringSecurityDescriptorToSecurityDescriptorW(pwzSddl, SDDL_REVISION_1, &psd, &cbSD))
790 {
777 - ExitWithLastError(hr, "failed to create security descriptor from SDDL: %ls", pwzSddl);
791 + AclExitWithLastError(hr, "failed to create security descriptor from SDDL: %ls", pwzSddl);
792 }
793
794 *ppsd = static_cast<SECURITY_DESCRIPTOR*>(MemAlloc(cbSD, FALSE));
781 - ExitOnNull(*ppsd, hr, E_OUTOFMEMORY, "failed to allocate memory for security descriptor");
795 + AclExitOnNull(*ppsd, hr, E_OUTOFMEMORY, "failed to allocate memory for security descriptor");
796
797 memcpy(*ppsd, psd, cbSD);
798 Assert(::IsValidSecurityDescriptor(*ppsd));
@@ -815,7 +829,7 @@ extern "C" HRESULT DAPI AclDuplicateSecurityDescriptor(
829 HRESULT hr = S_OK;
830 DWORD cbSD;
831
818 - ExitOnNull(ppsd, hr, E_INVALIDARG, "Failed to get duplicate ACL security descriptor because no place to output was provided");
832 + AclExitOnNull(ppsd, hr, E_INVALIDARG, "Failed to get duplicate ACL security descriptor because no place to output was provided");
833 *ppsd = NULL;
834
835 //
@@ -823,7 +837,7 @@ extern "C" HRESULT DAPI AclDuplicateSecurityDescriptor(
837 //
838 cbSD = ::GetSecurityDescriptorLength(psd);
839 *ppsd = static_cast<SECURITY_DESCRIPTOR*>(MemAlloc(cbSD, 0));
826 - ExitOnNull(*ppsd, hr, E_OUTOFMEMORY, "failed allocate memory for security descriptor");
840 + AclExitOnNull(*ppsd, hr, E_OUTOFMEMORY, "failed allocate memory for security descriptor");
841
842 memcpy(*ppsd, psd, cbSD);
843 Assert(::IsValidSecurityDescriptor(*ppsd));
@@ -856,18 +870,18 @@ extern "C" HRESULT DAPI AclGetSecurityDescriptor(
870 PSECURITY_DESCRIPTOR psd = NULL;
871 DWORD cbSD;
872
859 - ExitOnNull(ppsd, hr, E_INVALIDARG, "Failed to get ACL Security Descriptor because no place to output was provided");
873 + AclExitOnNull(ppsd, hr, E_INVALIDARG, "Failed to get ACL Security Descriptor because no place to output was provided");
874 *ppsd = NULL;
875
876 // get the security descriptor for the object
877 er = ::GetNamedSecurityInfoW(const_cast<LPWSTR>(wzObject), sot, securityInformation, NULL, NULL, NULL, NULL, &psd);
864 - ExitOnWin32Error(er, hr, "failed to get security info from object: %ls", wzObject);
878 + AclExitOnWin32Error(er, hr, "failed to get security info from object: %ls", wzObject);
879 Assert(::IsValidSecurityDescriptor(psd));
880
881 // copy the self-relative security descriptor
882 cbSD = ::GetSecurityDescriptorLength(psd);
883 *ppsd = static_cast<SECURITY_DESCRIPTOR*>(MemAlloc(cbSD, 0));
870 - ExitOnNull(*ppsd, hr, E_OUTOFMEMORY, "failed allocate memory for security descriptor");
884 + AclExitOnNull(*ppsd, hr, E_OUTOFMEMORY, "failed allocate memory for security descriptor");
885
886 memcpy(*ppsd, psd, cbSD);
887 Assert(::IsValidSecurityDescriptor(*ppsd));
@@ -905,7 +919,7 @@ extern "C" HRESULT DAPI AclSetSecurityWithRetry(
919 DWORD i = 0;
920
921 hr = StrAllocString(&sczObject, wzObject, 0);
908 - ExitOnFailure(hr, "Failed to copy object to secure.");
922 + AclExitOnFailure(hr, "Failed to copy object to secure.");
923
924 hr = E_FAIL;
925 for (i = 0; FAILED(hr) && i <= cRetry; ++i)
@@ -918,7 +932,7 @@ extern "C" HRESULT DAPI AclSetSecurityWithRetry(
932 DWORD er = ::SetNamedSecurityInfoW(sczObject, sot, securityInformation, psidOwner, psidGroup, pDacl, pSacl);
933 hr = HRESULT_FROM_WIN32(er);
934 }
921 - ExitOnRootFailure(hr, "Failed to set security on object '%ls' after %u retries.", wzObject, i);
935 + AclExitOnRootFailure(hr, "Failed to set security on object '%ls' after %u retries.", wzObject, i);
936
937 LExit:
938 ReleaseStr(sczObject);
@@ -996,20 +1010,20 @@ extern "C" HRESULT DAPI AclAddAdminToSecurityDescriptor(
1010
1011 if (!::GetSecurityDescriptorDacl(pSecurity, &fValid, &pAcl, &fDaclDefaulted) || !fValid)
1012 {
999 - ExitOnLastError(hr, "Failed to get acl from security descriptor");
1013 + AclExitOnLastError(hr, "Failed to get acl from security descriptor");
1014 }
1015
1016 hr = AclGetWellKnownSid(WinBuiltinAdministratorsSid, &ace[0].psid);
1003 - ExitOnFailure(hr, "failed to get sid for Administrators group");
1017 + AclExitOnFailure(hr, "failed to get sid for Administrators group");
1018
1019 ace[0].dwFlags = NO_PROPAGATE_INHERIT_ACE;
1020 ace[0].dwMask = GENERIC_ALL;
1021
1022 hr = AclAddToDacl(pAcl, NULL, 0, ace, 1, &pAclNew);
1009 - ExitOnFailure(hr, "failed to add Administrators ACE to ACL");
1023 + AclExitOnFailure(hr, "failed to add Administrators ACE to ACL");
1024
1025 hr = AclCreateSecurityDescriptorFromDacl(pAclNew, &pSecurityNew);
1012 - ExitOnLastError(hr, "Failed to create new security descriptor");
1026 + AclExitOnLastError(hr, "Failed to create new security descriptor");
1027
1028 // The DACL is referenced by, not copied into, the security descriptor. Make sure not to free it.
1029 pAclNew = NULL;
src/dutil/apputil.cpp
+18 -3
@@ -2,6 +2,20 @@
2
3 #include "precomp.h"
4
5 +// Exit macros
6 +#define AppExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__)
7 +#define AppExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__)
8 +#define AppExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__)
9 +#define AppExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__)
10 +#define AppExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__)
11 +#define AppExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__)
12 +#define AppExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_APPUTIL, p, x, e, s, __VA_ARGS__)
13 +#define AppExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_APPUTIL, p, x, s, __VA_ARGS__)
14 +#define AppExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_APPUTIL, p, x, e, s, __VA_ARGS__)
15 +#define AppExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_APPUTIL, p, x, s, __VA_ARGS__)
16 +#define AppExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_APPUTIL, e, x, s, __VA_ARGS__)
17 +#define AppExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_APPUTIL, g, x, s, __VA_ARGS__)
18 +
19 const DWORD PRIVATE_LOAD_LIBRARY_SEARCH_SYSTEM32 = 0x00000800;
20 typedef BOOL(WINAPI *LPFN_SETDEFAULTDLLDIRECTORIES)(DWORD);
21 typedef BOOL(WINAPI *LPFN_SETDLLDIRECTORYW)(LPCWSTR);
@@ -33,6 +47,7 @@ extern "C" void DAPI AppInitialize(
47
48 // Best effort call to initialize default DLL directories to system only.
49 HMODULE hKernel32 = ::GetModuleHandleW(L"kernel32");
50 + Assert(hKernel32);
51 LPFN_SETDEFAULTDLLDIRECTORIES pfnSetDefaultDllDirectories = (LPFN_SETDEFAULTDLLDIRECTORIES)::GetProcAddress(hKernel32, "SetDefaultDllDirectories");
52 if (pfnSetDefaultDllDirectories)
53 {
@@ -90,13 +105,13 @@ extern "C" DAPI_(HRESULT) AppParseCommandLine(
105 // which fails pretty miserably if your first argument is something like
106 // FOO="C:\Program Files\My Company". So give it something harmless to play with.
107 hr = StrAllocConcat(&sczCommandLine, L"ignored ", 0);
93 - ExitOnFailure(hr, "Failed to initialize command line.");
108 + AppExitOnFailure(hr, "Failed to initialize command line.");
109
110 hr = StrAllocConcat(&sczCommandLine, wzCommandLine, 0);
96 - ExitOnFailure(hr, "Failed to copy command line.");
111 + AppExitOnFailure(hr, "Failed to copy command line.");
112
113 argv = ::CommandLineToArgvW(sczCommandLine, &argc);
99 - ExitOnNullWithLastError(argv, hr, "Failed to parse command line.");
114 + AppExitOnNullWithLastError(argv, hr, "Failed to parse command line.");
115
116 // Skip "ignored" argument/hack.
117 *pArgv = argv + 1;
src/dutil/apuputil.cpp
+65 -51
@@ -2,6 +2,20 @@
2
3 #include "precomp.h"
4
5 +// Exit macros
6 +#define ApupExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_APUPUTIL, x, s, __VA_ARGS__)
7 +#define ApupExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_APUPUTIL, x, s, __VA_ARGS__)
8 +#define ApupExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_APUPUTIL, x, s, __VA_ARGS__)
9 +#define ApupExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_APUPUTIL, x, s, __VA_ARGS__)
10 +#define ApupExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_APUPUTIL, x, s, __VA_ARGS__)
11 +#define ApupExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_APUPUTIL, x, s, __VA_ARGS__)
12 +#define ApupExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_APUPUTIL, p, x, e, s, __VA_ARGS__)
13 +#define ApupExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_APUPUTIL, p, x, s, __VA_ARGS__)
14 +#define ApupExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_APUPUTIL, p, x, e, s, __VA_ARGS__)
15 +#define ApupExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_APUPUTIL, p, x, s, __VA_ARGS__)
16 +#define ApupExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_APUPUTIL, e, x, s, __VA_ARGS__)
17 +#define ApupExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_APUPUTIL, g, x, s, __VA_ARGS__)
18 +
19 // prototypes
20 static HRESULT ProcessEntry(
21 __in ATOM_ENTRY* pAtomEntry,
@@ -61,14 +75,14 @@ extern "C" HRESULT DAPI ApupAllocChainFromAtom(
75 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pElement->wzElement, -1, L"application", -1))
76 {
77 hr = StrAllocString(&pChain->wzDefaultApplicationId, pElement->wzValue, 0);
64 - ExitOnFailure(hr, "Failed to allocate default application id.");
78 + ApupExitOnFailure(hr, "Failed to allocate default application id.");
79
80 for (ATOM_UNKNOWN_ATTRIBUTE* pAttribute = pElement->pAttributes; pAttribute; pAttribute = pAttribute->pNext)
81 {
82 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pAttribute->wzAttribute, -1, L"type", -1))
83 {
84 hr = StrAllocString(&pChain->wzDefaultApplicationType, pAttribute->wzValue, 0);
71 - ExitOnFailure(hr, "Failed to allocate default application type.");
85 + ApupExitOnFailure(hr, "Failed to allocate default application type.");
86 }
87 }
88 }
@@ -79,13 +93,13 @@ extern "C" HRESULT DAPI ApupAllocChainFromAtom(
93 if (pFeed->cEntries)
94 {
95 pChain->rgEntries = static_cast<APPLICATION_UPDATE_ENTRY*>(MemAlloc(sizeof(APPLICATION_UPDATE_ENTRY) * pFeed->cEntries, TRUE));
82 - ExitOnNull(pChain->rgEntries, hr, E_OUTOFMEMORY, "Failed to allocate memory for update entries.");
96 + ApupExitOnNull(pChain->rgEntries, hr, E_OUTOFMEMORY, "Failed to allocate memory for update entries.");
97
98 // Process each entry, building up the chain.
99 for (DWORD i = 0; i < pFeed->cEntries; ++i)
100 {
101 hr = ProcessEntry(pFeed->rgEntries + i, pChain->wzDefaultApplicationId, pChain->rgEntries + pChain->cEntries);
88 - ExitOnFailure(hr, "Failed to process ATOM entry.");
102 + ApupExitOnFailure(hr, "Failed to process ATOM entry.");
103
104 if (S_FALSE != hr)
105 {
@@ -103,7 +117,7 @@ extern "C" HRESULT DAPI ApupAllocChainFromAtom(
117 if (pChain->cEntries > 0)
118 {
119 pChain->rgEntries = static_cast<APPLICATION_UPDATE_ENTRY*>(MemReAlloc(pChain->rgEntries, sizeof(APPLICATION_UPDATE_ENTRY) * pChain->cEntries, FALSE));
106 - ExitOnNull(pChain->rgEntries, hr, E_OUTOFMEMORY, "Failed to reallocate memory for update entries.");
120 + ApupExitOnNull(pChain->rgEntries, hr, E_OUTOFMEMORY, "Failed to reallocate memory for update entries.");
121 }
122 else
123 {
@@ -136,21 +150,21 @@ HRESULT DAPI ApupFilterChain(
150 DWORD cEntries = NULL;
151
152 pNewChain = static_cast<APPLICATION_UPDATE_CHAIN*>(MemAlloc(sizeof(APPLICATION_UPDATE_CHAIN), TRUE));
139 - ExitOnNull(pNewChain, hr, E_OUTOFMEMORY, "Failed to allocate filtered chain.");
153 + ApupExitOnNull(pNewChain, hr, E_OUTOFMEMORY, "Failed to allocate filtered chain.");
154
155 hr = FilterEntries(pChain->rgEntries, pChain->cEntries, pVersion, &prgEntries, &cEntries);
142 - ExitOnFailure(hr, "Failed to filter entries by version.");
156 + ApupExitOnFailure(hr, "Failed to filter entries by version.");
157
158 if (pChain->wzDefaultApplicationId)
159 {
160 hr = StrAllocString(&pNewChain->wzDefaultApplicationId, pChain->wzDefaultApplicationId, 0);
147 - ExitOnFailure(hr, "Failed to copy default application id.");
161 + ApupExitOnFailure(hr, "Failed to copy default application id.");
162 }
163
164 if (pChain->wzDefaultApplicationType)
165 {
166 hr = StrAllocString(&pNewChain->wzDefaultApplicationType, pChain->wzDefaultApplicationType, 0);
153 - ExitOnFailure(hr, "Failed to copy default application type.");
167 + ApupExitOnFailure(hr, "Failed to copy default application type.");
168 }
169
170 pNewChain->rgEntries = prgEntries;
@@ -205,28 +219,28 @@ static HRESULT ProcessEntry(
219 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pElement->wzElement, -1, L"application", -1))
220 {
221 hr = StrAllocString(&pApupEntry->wzApplicationId, pElement->wzValue, 0);
208 - ExitOnFailure(hr, "Failed to allocate application identity.");
222 + ApupExitOnFailure(hr, "Failed to allocate application identity.");
223
224 for (ATOM_UNKNOWN_ATTRIBUTE* pAttribute = pElement->pAttributes; pAttribute; pAttribute = pAttribute->pNext)
225 {
226 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pAttribute->wzAttribute, -1, L"type", -1))
227 {
228 hr = StrAllocString(&pApupEntry->wzApplicationType, pAttribute->wzValue, 0);
215 - ExitOnFailure(hr, "Failed to allocate application type.");
229 + ApupExitOnFailure(hr, "Failed to allocate application type.");
230 }
231 }
232 }
233 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pElement->wzElement, -1, L"upgrade", -1))
234 {
235 hr = StrAllocString(&pApupEntry->wzUpgradeId, pElement->wzValue, 0);
222 - ExitOnFailure(hr, "Failed to allocate upgrade id.");
236 + ApupExitOnFailure(hr, "Failed to allocate upgrade id.");
237
238 for (ATOM_UNKNOWN_ATTRIBUTE* pAttribute = pElement->pAttributes; pAttribute; pAttribute = pAttribute->pNext)
239 {
240 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pAttribute->wzAttribute, -1, L"version", -1))
241 {
242 hr = VerParseVersion(pAttribute->wzValue, 0, FALSE, &pApupEntry->pUpgradeVersion);
229 - ExitOnFailure(hr, "Failed to parse upgrade version string '%ls' from ATOM entry.", pAttribute->wzValue);
243 + ApupExitOnFailure(hr, "Failed to parse upgrade version string '%ls' from ATOM entry.", pAttribute->wzValue);
244 }
245 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pAttribute->wzAttribute, -1, L"exclusive", -1))
246 {
@@ -240,7 +254,7 @@ static HRESULT ProcessEntry(
254 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pElement->wzElement, -1, L"version", -1))
255 {
256 hr = VerParseVersion(pElement->wzValue, 0, FALSE, &pApupEntry->pVersion);
243 - ExitOnFailure(hr, "Failed to parse version string '%ls' from ATOM entry.", pElement->wzValue);
257 + ApupExitOnFailure(hr, "Failed to parse version string '%ls' from ATOM entry.", pElement->wzValue);
258
259 fVersionFound = TRUE;
260 }
@@ -254,24 +268,24 @@ static HRESULT ProcessEntry(
268 }
269
270 hr = VerCompareParsedVersions(pApupEntry->pUpgradeVersion, pApupEntry->pVersion, &nCompareResult);
257 - ExitOnFailure(hr, "Failed to compare version to upgrade version.");
271 + ApupExitOnFailure(hr, "Failed to compare version to upgrade version.");
272
273 if (nCompareResult >= 0)
274 {
275 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
262 - ExitOnRootFailure(hr, "Upgrade version is greater than or equal to application version.");
276 + ApupExitOnRootFailure(hr, "Upgrade version is greater than or equal to application version.");
277 }
278
279 if (pAtomEntry->wzTitle)
280 {
281 hr = StrAllocString(&pApupEntry->wzTitle, pAtomEntry->wzTitle, 0);
268 - ExitOnFailure(hr, "Failed to allocate application title.");
282 + ApupExitOnFailure(hr, "Failed to allocate application title.");
283 }
284
285 if (pAtomEntry->wzSummary)
286 {
287 hr = StrAllocString(&pApupEntry->wzSummary, pAtomEntry->wzSummary, 0);
274 - ExitOnFailure(hr, "Failed to allocate application summary.");
288 + ApupExitOnFailure(hr, "Failed to allocate application summary.");
289 }
290
291 if (pAtomEntry->pContent)
@@ -279,18 +293,18 @@ static HRESULT ProcessEntry(
293 if (pAtomEntry->pContent->wzType)
294 {
295 hr = StrAllocString(&pApupEntry->wzContentType, pAtomEntry->pContent->wzType, 0);
282 - ExitOnFailure(hr, "Failed to allocate content type.");
296 + ApupExitOnFailure(hr, "Failed to allocate content type.");
297 }
298
299 if (pAtomEntry->pContent->wzValue)
300 {
301 hr = StrAllocString(&pApupEntry->wzContent, pAtomEntry->pContent->wzValue, 0);
288 - ExitOnFailure(hr, "Failed to allocate content.");
302 + ApupExitOnFailure(hr, "Failed to allocate content.");
303 }
304 }
305 // Now process the enclosures. Assume every link in the ATOM entry is an enclosure.
306 pApupEntry->rgEnclosures = static_cast<APPLICATION_UPDATE_ENCLOSURE*>(MemAlloc(sizeof(APPLICATION_UPDATE_ENCLOSURE) * pAtomEntry->cLinks, TRUE));
293 - ExitOnNull(pApupEntry->rgEnclosures, hr, E_OUTOFMEMORY, "Failed to allocate enclosures for application update entry.");
307 + ApupExitOnNull(pApupEntry->rgEnclosures, hr, E_OUTOFMEMORY, "Failed to allocate enclosures for application update entry.");
308
309 for (DWORD i = 0; i < pAtomEntry->cLinks; ++i)
310 {
@@ -298,7 +312,7 @@ static HRESULT ProcessEntry(
312 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pLink->wzRel, -1, L"enclosure", -1))
313 {
314 hr = ParseEnclosure(pLink, pApupEntry->rgEnclosures + pApupEntry->cEnclosures);
301 - ExitOnFailure(hr, "Failed to parse enclosure.");
315 + ApupExitOnFailure(hr, "Failed to parse enclosure.");
316
317 pApupEntry->dw64TotalSize += pApupEntry->rgEnclosures[pApupEntry->cEnclosures].dw64Size; // total up the size of the enclosures
318
@@ -369,25 +383,25 @@ static HRESULT ParseEnclosure(
383 dwDigestStringLength = 2 * dwDigestLength;
384
385 hr = ::StringCchLengthW(pElement->wzValue, STRSAFE_MAX_CCH, &cchDigestString);
372 - ExitOnFailure(hr, "Failed to get string length of digest value.");
386 + ApupExitOnFailure(hr, "Failed to get string length of digest value.");
387
388 if (dwDigestStringLength != cchDigestString)
389 {
390 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
377 - ExitOnRootFailure(hr, "Invalid digest length (%zu) for digest algorithm (%u).", cchDigestString, dwDigestStringLength);
391 + ApupExitOnRootFailure(hr, "Invalid digest length (%zu) for digest algorithm (%u).", cchDigestString, dwDigestStringLength);
392 }
393
394 pEnclosure->cbDigest = sizeof(BYTE) * dwDigestLength;
395 pEnclosure->rgbDigest = static_cast<BYTE*>(MemAlloc(pEnclosure->cbDigest, TRUE));
382 - ExitOnNull(pEnclosure->rgbDigest, hr, E_OUTOFMEMORY, "Failed to allocate memory for digest.");
396 + ApupExitOnNull(pEnclosure->rgbDigest, hr, E_OUTOFMEMORY, "Failed to allocate memory for digest.");
397
398 hr = StrHexDecode(pElement->wzValue, pEnclosure->rgbDigest, pEnclosure->cbDigest);
385 - ExitOnFailure(hr, "Failed to decode digest value.");
399 + ApupExitOnFailure(hr, "Failed to decode digest value.");
400 }
401 else
402 {
403 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
390 - ExitOnRootFailure(hr, "Unknown algorithm type for digest.");
404 + ApupExitOnRootFailure(hr, "Unknown algorithm type for digest.");
405 }
406
407 break;
@@ -395,7 +409,7 @@ static HRESULT ParseEnclosure(
409 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, L"name", -1, pElement->wzElement, -1))
410 {
411 hr = StrAllocString(&pEnclosure->wzLocalName, pElement->wzValue, 0);
398 - ExitOnFailure(hr, "Failed to copy local name.");
412 + ApupExitOnFailure(hr, "Failed to copy local name.");
413 }
414 }
415 }
@@ -403,7 +417,7 @@ static HRESULT ParseEnclosure(
417 pEnclosure->dw64Size = pLink->dw64Length;
418
419 hr = StrAllocString(&pEnclosure->wzUrl, pLink->wzUrl, 0);
406 - ExitOnFailure(hr, "Failed to allocate enclosure URL.");
420 + ApupExitOnFailure(hr, "Failed to allocate enclosure URL.");
421
422 pEnclosure->fInstaller = FALSE;
423 pEnclosure->wzLocalName = NULL;
@@ -459,7 +473,7 @@ static HRESULT FilterEntries(
473 const APPLICATION_UPDATE_ENTRY* pEntry = rgEntries + i;
474
475 hr = VerCompareParsedVersions(pCurrentVersion, pEntry->pVersion, &nCompareResult);
462 - ExitOnFailure(hr, "Failed to compare versions.");
476 + ApupExitOnFailure(hr, "Failed to compare versions.");
477
478 if (nCompareResult >= 0)
479 {
@@ -467,7 +481,7 @@ static HRESULT FilterEntries(
481 }
482
483 hr = VerCompareParsedVersions(pCurrentVersion, pEntry->pUpgradeVersion, &nCompareResult);
470 - ExitOnFailure(hr, "Failed to compare upgrade versions.");
484 + ApupExitOnFailure(hr, "Failed to compare upgrade versions.");
485
486 if (nCompareResult > 0 || (!pEntry->fUpgradeExclusive && nCompareResult == 0))
487 {
@@ -481,17 +495,17 @@ static HRESULT FilterEntries(
495 DWORD cNewFilteredEntries = *pcFilteredEntries + 1;
496
497 hr = ::SizeTMult(sizeof(APPLICATION_UPDATE_ENTRY), cNewFilteredEntries, &cbAllocSize);
484 - ExitOnFailure(hr, "Overflow while calculating alloc size for more entries - number of entries: %u", cNewFilteredEntries);
498 + ApupExitOnFailure(hr, "Overflow while calculating alloc size for more entries - number of entries: %u", cNewFilteredEntries);
499
500 if (*prgFilteredEntries)
501 {
502 pv = MemReAlloc(*prgFilteredEntries, cbAllocSize, FALSE);
489 - ExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to reallocate memory for more entries.");
503 + ApupExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to reallocate memory for more entries.");
504 }
505 else
506 {
507 pv = MemAlloc(cbAllocSize, TRUE);
494 - ExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to allocate memory for entries.");
508 + ApupExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to allocate memory for entries.");
509 }
510
511 *pcFilteredEntries = cNewFilteredEntries;
@@ -499,10 +513,10 @@ static HRESULT FilterEntries(
513 pv = NULL;
514
515 hr = CopyEntry(pRequired, *prgFilteredEntries + *pcFilteredEntries - 1);
502 - ExitOnFailure(hr, "Failed to deep copy entry.");
516 + ApupExitOnFailure(hr, "Failed to deep copy entry.");
517
518 hr = VerCompareParsedVersions(pRequired->pVersion, rgEntries[0].pVersion, &nCompareResult);
505 - ExitOnFailure(hr, "Failed to compare required version.");
519 + ApupExitOnFailure(hr, "Failed to compare required version.");
520
521 if (nCompareResult < 0)
522 {
@@ -530,67 +544,67 @@ static HRESULT CopyEntry(
544 if (pSrc->wzApplicationId)
545 {
546 hr = StrAllocString(&pDest->wzApplicationId, pSrc->wzApplicationId, 0);
533 - ExitOnFailure(hr, "Failed to copy application id.");
547 + ApupExitOnFailure(hr, "Failed to copy application id.");
548 }
549
550 if (pSrc->wzApplicationType)
551 {
552 hr = StrAllocString(&pDest->wzApplicationType, pSrc->wzApplicationType, 0);
539 - ExitOnFailure(hr, "Failed to copy application type.");
553 + ApupExitOnFailure(hr, "Failed to copy application type.");
554 }
555
556 if (pSrc->wzUpgradeId)
557 {
558 hr = StrAllocString(&pDest->wzUpgradeId, pSrc->wzUpgradeId, 0);
545 - ExitOnFailure(hr, "Failed to copy upgrade id.");
559 + ApupExitOnFailure(hr, "Failed to copy upgrade id.");
560 }
561
562 if (pSrc->wzTitle)
563 {
564 hr = StrAllocString(&pDest->wzTitle, pSrc->wzTitle, 0);
551 - ExitOnFailure(hr, "Failed to copy title.");
565 + ApupExitOnFailure(hr, "Failed to copy title.");
566 }
567
568 if (pSrc->wzSummary)
569 {
570 hr = StrAllocString(&pDest->wzSummary, pSrc->wzSummary, 0);
557 - ExitOnFailure(hr, "Failed to copy summary.");
571 + ApupExitOnFailure(hr, "Failed to copy summary.");
572 }
573
574 if (pSrc->wzContentType)
575 {
576 hr = StrAllocString(&pDest->wzContentType, pSrc->wzContentType, 0);
563 - ExitOnFailure(hr, "Failed to copy content type.");
577 + ApupExitOnFailure(hr, "Failed to copy content type.");
578 }
579
580 if (pSrc->wzContent)
581 {
582 hr = StrAllocString(&pDest->wzContent, pSrc->wzContent, 0);
569 - ExitOnFailure(hr, "Failed to copy content.");
583 + ApupExitOnFailure(hr, "Failed to copy content.");
584 }
585
586 pDest->dw64TotalSize = pSrc->dw64TotalSize;
587
588 hr = VerCopyVersion(pSrc->pUpgradeVersion, &pDest->pUpgradeVersion);
575 - ExitOnFailure(hr, "Failed to copy upgrade version.");
589 + ApupExitOnFailure(hr, "Failed to copy upgrade version.");
590
591 hr = VerCopyVersion(pSrc->pVersion, &pDest->pVersion);
578 - ExitOnFailure(hr, "Failed to copy version.");
592 + ApupExitOnFailure(hr, "Failed to copy version.");
593
594 pDest->fUpgradeExclusive = pSrc->fUpgradeExclusive;
595
596 hr = ::SizeTMult(sizeof(APPLICATION_UPDATE_ENCLOSURE), pSrc->cEnclosures, &cbAllocSize);
583 - ExitOnRootFailure(hr, "Overflow while calculating memory allocation size");
597 + ApupExitOnRootFailure(hr, "Overflow while calculating memory allocation size");
598
599 pDest->rgEnclosures = static_cast<APPLICATION_UPDATE_ENCLOSURE*>(MemAlloc(cbAllocSize, TRUE));
586 - ExitOnNull(pDest->rgEnclosures, hr, E_OUTOFMEMORY, "Failed to allocate copy of enclosures.");
600 + ApupExitOnNull(pDest->rgEnclosures, hr, E_OUTOFMEMORY, "Failed to allocate copy of enclosures.");
601
602 pDest->cEnclosures = pSrc->cEnclosures;
603
604 for (DWORD i = 0; i < pDest->cEnclosures; ++i)
605 {
606 hr = CopyEnclosure(pSrc->rgEnclosures + i, pDest->rgEnclosures + i);
593 - ExitOnFailure(hr, "Failed to copy enclosure.");
607 + ApupExitOnFailure(hr, "Failed to copy enclosure.");
608 }
609
610 LExit:
@@ -615,17 +629,17 @@ static HRESULT CopyEnclosure(
629 if (pSrc->wzUrl)
630 {
631 hr = StrAllocString(&pDest->wzUrl, pSrc->wzUrl, 0);
618 - ExitOnFailure(hr, "Failed copy url.");
632 + ApupExitOnFailure(hr, "Failed copy url.");
633 }
634
635 if (pSrc->wzLocalName)
636 {
637 hr = StrAllocString(&pDest->wzLocalName, pSrc->wzLocalName, 0);
624 - ExitOnFailure(hr, "Failed copy url.");
638 + ApupExitOnFailure(hr, "Failed copy url.");
639 }
640
641 pDest->rgbDigest = static_cast<BYTE*>(MemAlloc(sizeof(BYTE) * pSrc->cbDigest, FALSE));
628 - ExitOnNull(pDest->rgbDigest, hr, E_OUTOFMEMORY, "Failed to allocate memory for copy of digest.");
642 + ApupExitOnNull(pDest->rgbDigest, hr, E_OUTOFMEMORY, "Failed to allocate memory for copy of digest.");
643
644 pDest->cbDigest = pSrc->cbDigest;
645
src/dutil/atomutil.cpp
+123 -110
@@ -2,6 +2,19 @@
2
3 #include "precomp.h"
4
5 +// Exit macros
6 +#define AtomExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_ATOMUTIL, x, s, __VA_ARGS__)
7 +#define AtomExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_ATOMUTIL, x, s, __VA_ARGS__)
8 +#define AtomExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_ATOMUTIL, x, s, __VA_ARGS__)
9 +#define AtomExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_ATOMUTIL, x, s, __VA_ARGS__)
10 +#define AtomExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_ATOMUTIL, x, s, __VA_ARGS__)
11 +#define AtomExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_ATOMUTIL, x, s, __VA_ARGS__)
12 +#define AtomExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_ATOMUTIL, p, x, e, s, __VA_ARGS__)
13 +#define AtomExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_ATOMUTIL, p, x, s, __VA_ARGS__)
14 +#define AtomExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_ATOMUTIL, p, x, e, s, __VA_ARGS__)
15 +#define AtomExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_ATOMUTIL, p, x, s, __VA_ARGS__)
16 +#define AtomExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_ATOMUTIL, e, x, s, __VA_ARGS__)
17 +#define AtomExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_ATOMUTIL, g, x, s, __VA_ARGS__)
18
19 static HRESULT ParseAtomDocument(
20 __in IXMLDOMDocument *pixd,
@@ -98,7 +111,7 @@ extern "C" void DAPI AtomUninitialize()
111
112 *********************************************************************/
113 extern "C" HRESULT DAPI AtomParseFromString(
101 - __in LPCWSTR wzAtomString,
114 + __in_z LPCWSTR wzAtomString,
115 __out ATOM_FEED **ppFeed
116 )
117 {
@@ -110,10 +123,10 @@ extern "C" HRESULT DAPI AtomParseFromString(
123 IXMLDOMDocument *pixdAtom = NULL;
124
125 hr = XmlLoadDocument(wzAtomString, &pixdAtom);
113 - ExitOnFailure(hr, "Failed to load ATOM string as XML document.");
126 + AtomExitOnFailure(hr, "Failed to load ATOM string as XML document.");
127
128 hr = ParseAtomDocument(pixdAtom, &pNewFeed);
116 - ExitOnFailure(hr, "Failed to parse ATOM document.");
129 + AtomExitOnFailure(hr, "Failed to parse ATOM document.");
130
131 *ppFeed = pNewFeed;
132 pNewFeed = NULL;
@@ -131,7 +144,7 @@ LExit:
144
145 *********************************************************************/
146 extern "C" HRESULT DAPI AtomParseFromFile(
134 - __in LPCWSTR wzAtomFile,
147 + __in_z LPCWSTR wzAtomFile,
148 __out ATOM_FEED **ppFeed
149 )
150 {
@@ -143,10 +156,10 @@ extern "C" HRESULT DAPI AtomParseFromFile(
156 IXMLDOMDocument *pixdAtom = NULL;
157
158 hr = XmlLoadDocumentFromFile(wzAtomFile, &pixdAtom);
146 - ExitOnFailure(hr, "Failed to load ATOM string as XML document.");
159 + AtomExitOnFailure(hr, "Failed to load ATOM string as XML document.");
160
161 hr = ParseAtomDocument(pixdAtom, &pNewFeed);
149 - ExitOnFailure(hr, "Failed to parse ATOM document.");
162 + AtomExitOnFailure(hr, "Failed to parse ATOM document.");
163
164 *ppFeed = pNewFeed;
165 pNewFeed = NULL;
@@ -175,7 +188,7 @@ extern "C" HRESULT DAPI AtomParseFromDocument(
188 ATOM_FEED *pNewFeed = NULL;
189
190 hr = ParseAtomDocument(pixdDocument, &pNewFeed);
178 - ExitOnFailure(hr, "Failed to parse ATOM document.");
191 + AtomExitOnFailure(hr, "Failed to parse ATOM document.");
192
193 *ppFeed = pNewFeed;
194 pNewFeed = NULL;
@@ -192,7 +205,7 @@ LExit:
205
206 *********************************************************************/
207 extern "C" void DAPI AtomFreeFeed(
195 - __in_xcount(pFeed->cItems) ATOM_FEED *pFeed
208 + __in_xcount(pFeed->cItems) ATOM_FEED* pFeed
209 )
210 {
211 if (pFeed)
@@ -257,10 +270,10 @@ static HRESULT ParseAtomDocument(
270 // Get the document element and start processing feeds.
271 //
272 hr = pixd->get_documentElement(&pFeedElement);
260 - ExitOnFailure(hr, "failed get_documentElement in ParseAtomDocument");
273 + AtomExitOnFailure(hr, "failed get_documentElement in ParseAtomDocument");
274
275 hr = ParseAtomFeed(pFeedElement, &pNewFeed);
263 - ExitOnFailure(hr, "Failed to parse ATOM feed.");
276 + AtomExitOnFailure(hr, "Failed to parse ATOM feed.");
277
278 if (S_FALSE == hr)
279 {
@@ -305,96 +318,96 @@ static HRESULT ParseAtomFeed(
318
319 // First, allocate the new feed and all the possible sub elements.
320 pNewFeed = (ATOM_FEED*)MemAlloc(sizeof(ATOM_FEED), TRUE);
308 - ExitOnNull(pNewFeed, hr, E_OUTOFMEMORY, "Failed to allocate ATOM feed structure.");
321 + AtomExitOnNull(pNewFeed, hr, E_OUTOFMEMORY, "Failed to allocate ATOM feed structure.");
322
323 pNewFeed->pixn = pixnFeed;
324 pNewFeed->pixn->AddRef();
325
326 hr = AllocateAtomType<ATOM_AUTHOR>(pixnFeed, L"author", &pNewFeed->rgAuthors, &pNewFeed->cAuthors);
314 - ExitOnFailure(hr, "Failed to allocate ATOM feed authors.");
327 + AtomExitOnFailure(hr, "Failed to allocate ATOM feed authors.");
328
329 hr = AllocateAtomType<ATOM_CATEGORY>(pixnFeed, L"category", &pNewFeed->rgCategories, &pNewFeed->cCategories);
317 - ExitOnFailure(hr, "Failed to allocate ATOM feed categories.");
330 + AtomExitOnFailure(hr, "Failed to allocate ATOM feed categories.");
331
332 hr = AllocateAtomType<ATOM_ENTRY>(pixnFeed, L"entry", &pNewFeed->rgEntries, &pNewFeed->cEntries);
320 - ExitOnFailure(hr, "Failed to allocate ATOM feed entries.");
333 + AtomExitOnFailure(hr, "Failed to allocate ATOM feed entries.");
334
335 hr = AllocateAtomType<ATOM_LINK>(pixnFeed, L"link", &pNewFeed->rgLinks, &pNewFeed->cLinks);
323 - ExitOnFailure(hr, "Failed to allocate ATOM feed links.");
336 + AtomExitOnFailure(hr, "Failed to allocate ATOM feed links.");
337
338 // Second, process the elements under a feed.
339 hr = pixnFeed->get_childNodes(&pNodeList);
327 - ExitOnFailure(hr, "Failed to get child nodes of ATOM feed element.");
340 + AtomExitOnFailure(hr, "Failed to get child nodes of ATOM feed element.");
341
342 while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, &bstrNodeName)))
343 {
344 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"generator", -1))
345 {
346 hr = AssignString(&pNewFeed->wzGenerator, pNode);
334 - ExitOnFailure(hr, "Failed to allocate ATOM feed generator.");
347 + AtomExitOnFailure(hr, "Failed to allocate ATOM feed generator.");
348 }
349 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"icon", -1))
350 {
351 hr = AssignString(&pNewFeed->wzIcon, pNode);
339 - ExitOnFailure(hr, "Failed to allocate ATOM feed icon.");
352 + AtomExitOnFailure(hr, "Failed to allocate ATOM feed icon.");
353 }
354 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"id", -1))
355 {
356 hr = AssignString(&pNewFeed->wzId, pNode);
344 - ExitOnFailure(hr, "Failed to allocate ATOM feed id.");
357 + AtomExitOnFailure(hr, "Failed to allocate ATOM feed id.");
358 }
359 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"logo", -1))
360 {
361 hr = AssignString(&pNewFeed->wzLogo, pNode);
349 - ExitOnFailure(hr, "Failed to allocate ATOM feed logo.");
362 + AtomExitOnFailure(hr, "Failed to allocate ATOM feed logo.");
363 }
364 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"subtitle", -1))
365 {
366 hr = AssignString(&pNewFeed->wzSubtitle, pNode);
354 - ExitOnFailure(hr, "Failed to allocate ATOM feed subtitle.");
367 + AtomExitOnFailure(hr, "Failed to allocate ATOM feed subtitle.");
368 }
369 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"title", -1))
370 {
371 hr = AssignString(&pNewFeed->wzTitle, pNode);
359 - ExitOnFailure(hr, "Failed to allocate ATOM feed title.");
372 + AtomExitOnFailure(hr, "Failed to allocate ATOM feed title.");
373 }
374 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"updated", -1))
375 {
376 hr = AssignDateTime(&pNewFeed->ftUpdated, pNode);
364 - ExitOnFailure(hr, "Failed to allocate ATOM feed updated.");
377 + AtomExitOnFailure(hr, "Failed to allocate ATOM feed updated.");
378 }
379 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"author", -1))
380 {
381 hr = ParseAtomAuthor(pNode, &pNewFeed->rgAuthors[cAuthors]);
369 - ExitOnFailure(hr, "Failed to parse ATOM author.");
382 + AtomExitOnFailure(hr, "Failed to parse ATOM author.");
383
384 ++cAuthors;
385 }
386 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"category", -1))
387 {
388 hr = ParseAtomCategory(pNode, &pNewFeed->rgCategories[cCategories]);
376 - ExitOnFailure(hr, "Failed to parse ATOM category.");
389 + AtomExitOnFailure(hr, "Failed to parse ATOM category.");
390
391 ++cCategories;
392 }
393 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"entry", -1))
394 {
395 hr = ParseAtomEntry(pNode, &pNewFeed->rgEntries[cEntries]);
383 - ExitOnFailure(hr, "Failed to parse ATOM entry.");
396 + AtomExitOnFailure(hr, "Failed to parse ATOM entry.");
397
398 ++cEntries;
399 }
400 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"link", -1))
401 {
402 hr = ParseAtomLink(pNode, &pNewFeed->rgLinks[cLinks]);
390 - ExitOnFailure(hr, "Failed to parse ATOM link.");
403 + AtomExitOnFailure(hr, "Failed to parse ATOM link.");
404
405 ++cLinks;
406 }
407 else
408 {
409 hr = ParseAtomUnknownElement(pNode, &pNewFeed->pUnknownElements);
397 - ExitOnFailure(hr, "Failed to parse unknown ATOM feed element: %ls", bstrNodeName);
410 + AtomExitOnFailure(hr, "Failed to parse unknown ATOM feed element: %ls", bstrNodeName);
411 }
412
413 ReleaseNullBSTR(bstrNodeName);
@@ -404,17 +417,17 @@ static HRESULT ParseAtomFeed(
417 if (!pNewFeed->wzId || !*pNewFeed->wzId)
418 {
419 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
407 - ExitOnRootFailure(hr, "Failed to find required feed/id element.");
420 + AtomExitOnRootFailure(hr, "Failed to find required feed/id element.");
421 }
422 else if (!pNewFeed->wzTitle || !*pNewFeed->wzTitle)
423 {
424 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
412 - ExitOnRootFailure(hr, "Failed to find required feed/title element.");
425 + AtomExitOnRootFailure(hr, "Failed to find required feed/title element.");
426 }
427 else if (0 == pNewFeed->ftUpdated.dwHighDateTime && 0 == pNewFeed->ftUpdated.dwLowDateTime)
428 {
429 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
417 - ExitOnRootFailure(hr, "Failed to find required feed/updated element.");
430 + AtomExitOnRootFailure(hr, "Failed to find required feed/updated element.");
431 }
432
433 *ppFeed = pNewFeed;
@@ -450,12 +463,12 @@ template<class T> static HRESULT AllocateAtomType(
463 T* prgT = NULL;
464
465 hr = XmlSelectNodes(pixnParent, wzT, &pNodeList);
453 - ExitOnFailure(hr, "Failed to select all ATOM %ls.", wzT);
466 + AtomExitOnFailure(hr, "Failed to select all ATOM %ls.", wzT);
467
468 if (S_OK == hr)
469 {
470 hr = pNodeList->get_length(&cT);
458 - ExitOnFailure(hr, "Failed to count the number of ATOM %ls.", wzT);
471 + AtomExitOnFailure(hr, "Failed to count the number of ATOM %ls.", wzT);
472
473 if (cT == 0)
474 {
@@ -463,7 +476,7 @@ template<class T> static HRESULT AllocateAtomType(
476 }
477
478 prgT = static_cast<T*>(MemAlloc(sizeof(T) * cT, TRUE));
466 - ExitOnNull(prgT, hr, E_OUTOFMEMORY, "Failed to allocate ATOM.");
479 + AtomExitOnNull(prgT, hr, E_OUTOFMEMORY, "Failed to allocate ATOM.");
480
481 *pcT = cT;
482 *pprgT = prgT;
@@ -499,30 +512,30 @@ static HRESULT ParseAtomAuthor(
512 BSTR bstrNodeName = NULL;
513
514 hr = pixnAuthor->get_childNodes(&pNodeList);
502 - ExitOnFailure(hr, "Failed to get child nodes of ATOM author element.");
515 + AtomExitOnFailure(hr, "Failed to get child nodes of ATOM author element.");
516
517 while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, &bstrNodeName)))
518 {
519 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"name", -1))
520 {
521 hr = AssignString(&pAuthor->wzName, pNode);
509 - ExitOnFailure(hr, "Failed to allocate ATOM author name.");
522 + AtomExitOnFailure(hr, "Failed to allocate ATOM author name.");
523 }
524 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"email", -1))
525 {
526 hr = AssignString(&pAuthor->wzEmail, pNode);
514 - ExitOnFailure(hr, "Failed to allocate ATOM author email.");
527 + AtomExitOnFailure(hr, "Failed to allocate ATOM author email.");
528 }
529 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"uri", -1))
530 {
531 hr = AssignString(&pAuthor->wzUrl, pNode);
519 - ExitOnFailure(hr, "Failed to allocate ATOM author uri.");
532 + AtomExitOnFailure(hr, "Failed to allocate ATOM author uri.");
533 }
534
535 ReleaseNullBSTR(bstrNodeName);
536 ReleaseNullObject(pNode);
537 }
525 - ExitOnFailure(hr, "Failed to process all ATOM author elements.");
538 + AtomExitOnFailure(hr, "Failed to process all ATOM author elements.");
539
540 hr = S_OK;
541
@@ -553,44 +566,44 @@ static HRESULT ParseAtomCategory(
566
567 // Process attributes first.
568 hr = pixnCategory->get_attributes(&pixnnmAttributes);
556 - ExitOnFailure(hr, "Failed get attributes on ATOM unknown element.");
569 + AtomExitOnFailure(hr, "Failed get attributes on ATOM unknown element.");
570
571 while (S_OK == (hr = XmlNextAttribute(pixnnmAttributes, &pNode, &bstrNodeName)))
572 {
573 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"label", -1))
574 {
575 hr = AssignString(&pCategory->wzLabel, pNode);
563 - ExitOnFailure(hr, "Failed to allocate ATOM category label.");
576 + AtomExitOnFailure(hr, "Failed to allocate ATOM category label.");
577 }
578 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"scheme", -1))
579 {
580 hr = AssignString(&pCategory->wzScheme, pNode);
568 - ExitOnFailure(hr, "Failed to allocate ATOM category scheme.");
581 + AtomExitOnFailure(hr, "Failed to allocate ATOM category scheme.");
582 }
583 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"term", -1))
584 {
585 hr = AssignString(&pCategory->wzTerm, pNode);
573 - ExitOnFailure(hr, "Failed to allocate ATOM category term.");
586 + AtomExitOnFailure(hr, "Failed to allocate ATOM category term.");
587 }
588
589 ReleaseNullBSTR(bstrNodeName);
590 ReleaseNullObject(pNode);
591 }
579 - ExitOnFailure(hr, "Failed to process all ATOM category attributes.");
592 + AtomExitOnFailure(hr, "Failed to process all ATOM category attributes.");
593
594 // Process elements second.
595 hr = pixnCategory->get_childNodes(&pNodeList);
583 - ExitOnFailure(hr, "Failed to get child nodes of ATOM category element.");
596 + AtomExitOnFailure(hr, "Failed to get child nodes of ATOM category element.");
597
598 while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, &bstrNodeName)))
599 {
600 hr = ParseAtomUnknownElement(pNode, &pCategory->pUnknownElements);
588 - ExitOnFailure(hr, "Failed to parse unknown ATOM category element: %ls", bstrNodeName);
601 + AtomExitOnFailure(hr, "Failed to parse unknown ATOM category element: %ls", bstrNodeName);
602
603 ReleaseNullBSTR(bstrNodeName);
604 ReleaseNullObject(pNode);
605 }
593 - ExitOnFailure(hr, "Failed to process all ATOM category elements.");
606 + AtomExitOnFailure(hr, "Failed to process all ATOM category elements.");
607
608 hr = S_OK;
609
@@ -622,42 +635,42 @@ static HRESULT ParseAtomContent(
635
636 // Process attributes first.
637 hr = pixnContent->get_attributes(&pixnnmAttributes);
625 - ExitOnFailure(hr, "Failed get attributes on ATOM unknown element.");
638 + AtomExitOnFailure(hr, "Failed get attributes on ATOM unknown element.");
639
640 while (S_OK == (hr = XmlNextAttribute(pixnnmAttributes, &pNode, &bstrNodeName)))
641 {
642 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"type", -1))
643 {
644 hr = AssignString(&pContent->wzType, pNode);
632 - ExitOnFailure(hr, "Failed to allocate ATOM content type.");
645 + AtomExitOnFailure(hr, "Failed to allocate ATOM content type.");
646 }
647 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"url", -1))
648 {
649 hr = AssignString(&pContent->wzUrl, pNode);
637 - ExitOnFailure(hr, "Failed to allocate ATOM content scheme.");
650 + AtomExitOnFailure(hr, "Failed to allocate ATOM content scheme.");
651 }
652
653 ReleaseNullBSTR(bstrNodeName);
654 ReleaseNullObject(pNode);
655 }
643 - ExitOnFailure(hr, "Failed to process all ATOM content attributes.");
656 + AtomExitOnFailure(hr, "Failed to process all ATOM content attributes.");
657
658 // Process elements second.
659 hr = pixnContent->get_childNodes(&pNodeList);
647 - ExitOnFailure(hr, "Failed to get child nodes of ATOM content element.");
660 + AtomExitOnFailure(hr, "Failed to get child nodes of ATOM content element.");
661
662 while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, &bstrNodeName)))
663 {
664 hr = ParseAtomUnknownElement(pNode, &pContent->pUnknownElements);
652 - ExitOnFailure(hr, "Failed to parse unknown ATOM content element: %ls", bstrNodeName);
665 + AtomExitOnFailure(hr, "Failed to parse unknown ATOM content element: %ls", bstrNodeName);
666
667 ReleaseNullBSTR(bstrNodeName);
668 ReleaseNullObject(pNode);
669 }
657 - ExitOnFailure(hr, "Failed to process all ATOM content elements.");
670 + AtomExitOnFailure(hr, "Failed to process all ATOM content elements.");
671
672 hr = AssignString(&pContent->wzValue, pixnContent);
660 - ExitOnFailure(hr, "Failed to allocate ATOM content value.");
673 + AtomExitOnFailure(hr, "Failed to allocate ATOM content value.");
674
675 LExit:
676 ReleaseBSTR(bstrNodeName);
@@ -694,56 +707,56 @@ static HRESULT ParseAtomEntry(
707
708 // First, allocate all the possible sub elements.
709 hr = AllocateAtomType<ATOM_AUTHOR>(pixnEntry, L"author", &pEntry->rgAuthors, &pEntry->cAuthors);
697 - ExitOnFailure(hr, "Failed to allocate ATOM entry authors.");
710 + AtomExitOnFailure(hr, "Failed to allocate ATOM entry authors.");
711
712 hr = AllocateAtomType<ATOM_CATEGORY>(pixnEntry, L"category", &pEntry->rgCategories, &pEntry->cCategories);
700 - ExitOnFailure(hr, "Failed to allocate ATOM entry categories.");
713 + AtomExitOnFailure(hr, "Failed to allocate ATOM entry categories.");
714
715 hr = AllocateAtomType<ATOM_LINK>(pixnEntry, L"link", &pEntry->rgLinks, &pEntry->cLinks);
703 - ExitOnFailure(hr, "Failed to allocate ATOM entry links.");
716 + AtomExitOnFailure(hr, "Failed to allocate ATOM entry links.");
717
718 // Second, process elements.
719 hr = pixnEntry->get_childNodes(&pNodeList);
707 - ExitOnFailure(hr, "Failed to get child nodes of ATOM entry element.");
720 + AtomExitOnFailure(hr, "Failed to get child nodes of ATOM entry element.");
721
722 while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, &bstrNodeName)))
723 {
724 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"id", -1))
725 {
726 hr = AssignString(&pEntry->wzId, pNode);
714 - ExitOnFailure(hr, "Failed to allocate ATOM entry id.");
727 + AtomExitOnFailure(hr, "Failed to allocate ATOM entry id.");
728 }
729 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"summary", -1))
730 {
731 hr = AssignString(&pEntry->wzSummary, pNode);
719 - ExitOnFailure(hr, "Failed to allocate ATOM entry summary.");
732 + AtomExitOnFailure(hr, "Failed to allocate ATOM entry summary.");
733 }
734 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"title", -1))
735 {
736 hr = AssignString(&pEntry->wzTitle, pNode);
724 - ExitOnFailure(hr, "Failed to allocate ATOM entry title.");
737 + AtomExitOnFailure(hr, "Failed to allocate ATOM entry title.");
738 }
739 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"published", -1))
740 {
741 hr = AssignDateTime(&pEntry->ftPublished, pNode);
729 - ExitOnFailure(hr, "Failed to allocate ATOM entry published.");
742 + AtomExitOnFailure(hr, "Failed to allocate ATOM entry published.");
743 }
744 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"updated", -1))
745 {
746 hr = AssignDateTime(&pEntry->ftUpdated, pNode);
734 - ExitOnFailure(hr, "Failed to allocate ATOM entry updated.");
747 + AtomExitOnFailure(hr, "Failed to allocate ATOM entry updated.");
748 }
749 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"author", -1))
750 {
751 hr = ParseAtomAuthor(pNode, &pEntry->rgAuthors[cAuthors]);
739 - ExitOnFailure(hr, "Failed to parse ATOM entry author.");
752 + AtomExitOnFailure(hr, "Failed to parse ATOM entry author.");
753
754 ++cAuthors;
755 }
756 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"category", -1))
757 {
758 hr = ParseAtomCategory(pNode, &pEntry->rgCategories[cCategories]);
746 - ExitOnFailure(hr, "Failed to parse ATOM entry category.");
759 + AtomExitOnFailure(hr, "Failed to parse ATOM entry category.");
760
761 ++cCategories;
762 }
@@ -752,47 +765,47 @@ static HRESULT ParseAtomEntry(
765 if (NULL != pEntry->pContent)
766 {
767 hr = E_UNEXPECTED;
755 - ExitOnFailure(hr, "Cannot have two content elements in ATOM entry.");
768 + AtomExitOnFailure(hr, "Cannot have two content elements in ATOM entry.");
769 }
770
771 pEntry->pContent = static_cast<ATOM_CONTENT*>(MemAlloc(sizeof(ATOM_CONTENT), TRUE));
759 - ExitOnNull(pEntry->pContent, hr, E_OUTOFMEMORY, "Failed to allocate ATOM entry content.");
772 + AtomExitOnNull(pEntry->pContent, hr, E_OUTOFMEMORY, "Failed to allocate ATOM entry content.");
773
774 hr = ParseAtomContent(pNode, pEntry->pContent);
762 - ExitOnFailure(hr, "Failed to parse ATOM entry content.");
775 + AtomExitOnFailure(hr, "Failed to parse ATOM entry content.");
776 }
777 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"link", -1))
778 {
779 hr = ParseAtomLink(pNode, &pEntry->rgLinks[cLinks]);
767 - ExitOnFailure(hr, "Failed to parse ATOM entry link.");
780 + AtomExitOnFailure(hr, "Failed to parse ATOM entry link.");
781
782 ++cLinks;
783 }
784 else
785 {
786 hr = ParseAtomUnknownElement(pNode, &pEntry->pUnknownElements);
774 - ExitOnFailure(hr, "Failed to parse unknown ATOM entry element: %ls", bstrNodeName);
787 + AtomExitOnFailure(hr, "Failed to parse unknown ATOM entry element: %ls", bstrNodeName);
788 }
789
790 ReleaseNullBSTR(bstrNodeName);
791 ReleaseNullObject(pNode);
792 }
780 - ExitOnFailure(hr, "Failed to process all ATOM entry elements.");
793 + AtomExitOnFailure(hr, "Failed to process all ATOM entry elements.");
794
795 if (!pEntry->wzId || !*pEntry->wzId)
796 {
797 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
785 - ExitOnRootFailure(hr, "Failed to find required feed/entry/id element.");
798 + AtomExitOnRootFailure(hr, "Failed to find required feed/entry/id element.");
799 }
800 else if (!pEntry->wzTitle || !*pEntry->wzTitle)
801 {
802 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
790 - ExitOnRootFailure(hr, "Failed to find required feed/entry/title element.");
803 + AtomExitOnRootFailure(hr, "Failed to find required feed/entry/title element.");
804 }
805 else if (0 == pEntry->ftUpdated.dwHighDateTime && 0 == pEntry->ftUpdated.dwLowDateTime)
806 {
807 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
795 - ExitOnRootFailure(hr, "Failed to find required feed/entry/updated element.");
808 + AtomExitOnRootFailure(hr, "Failed to find required feed/entry/updated element.");
809 }
810
811 hr = S_OK;
@@ -825,19 +838,19 @@ static HRESULT ParseAtomLink(
838
839 // Process attributes first.
840 hr = pixnLink->get_attributes(&pixnnmAttributes);
828 - ExitOnFailure(hr, "Failed get attributes for ATOM link.");
841 + AtomExitOnFailure(hr, "Failed get attributes for ATOM link.");
842
843 while (S_OK == (hr = XmlNextAttribute(pixnnmAttributes, &pNode, &bstrNodeName)))
844 {
845 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"rel", -1))
846 {
847 hr = AssignString(&pLink->wzRel, pNode);
835 - ExitOnFailure(hr, "Failed to allocate ATOM link rel.");
848 + AtomExitOnFailure(hr, "Failed to allocate ATOM link rel.");
849 }
850 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"href", -1))
851 {
852 hr = AssignString(&pLink->wzUrl, pNode);
840 - ExitOnFailure(hr, "Failed to allocate ATOM link href.");
853 + AtomExitOnFailure(hr, "Failed to allocate ATOM link href.");
854 }
855 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"length", -1))
856 {
@@ -846,45 +859,45 @@ static HRESULT ParseAtomLink(
859 {
860 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
861 }
849 - ExitOnFailure(hr, "Failed to parse ATOM link length.");
862 + AtomExitOnFailure(hr, "Failed to parse ATOM link length.");
863 }
864 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"title", -1))
865 {
866 hr = AssignString(&pLink->wzTitle, pNode);
854 - ExitOnFailure(hr, "Failed to allocate ATOM link title.");
867 + AtomExitOnFailure(hr, "Failed to allocate ATOM link title.");
868 }
869 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"type", -1))
870 {
871 hr = AssignString(&pLink->wzType, pNode);
859 - ExitOnFailure(hr, "Failed to allocate ATOM link type.");
872 + AtomExitOnFailure(hr, "Failed to allocate ATOM link type.");
873 }
874 else
875 {
876 hr = ParseAtomUnknownAttribute(pNode, &pLink->pUnknownAttributes);
864 - ExitOnFailure(hr, "Failed to parse unknown ATOM link attribute: %ls", bstrNodeName);
877 + AtomExitOnFailure(hr, "Failed to parse unknown ATOM link attribute: %ls", bstrNodeName);
878 }
879
880 ReleaseNullBSTR(bstrNodeName);
881 ReleaseNullObject(pNode);
882 }
870 - ExitOnFailure(hr, "Failed to process all ATOM link attributes.");
883 + AtomExitOnFailure(hr, "Failed to process all ATOM link attributes.");
884
885 // Process elements second.
886 hr = pixnLink->get_childNodes(&pNodeList);
874 - ExitOnFailure(hr, "Failed to get child nodes of ATOM link element.");
887 + AtomExitOnFailure(hr, "Failed to get child nodes of ATOM link element.");
888
889 while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, &bstrNodeName)))
890 {
891 hr = ParseAtomUnknownElement(pNode, &pLink->pUnknownElements);
879 - ExitOnFailure(hr, "Failed to parse unknown ATOM link element: %ls", bstrNodeName);
892 + AtomExitOnFailure(hr, "Failed to parse unknown ATOM link element: %ls", bstrNodeName);
893
894 ReleaseNullBSTR(bstrNodeName);
895 ReleaseNullObject(pNode);
896 }
884 - ExitOnFailure(hr, "Failed to process all ATOM link elements.");
897 + AtomExitOnFailure(hr, "Failed to process all ATOM link elements.");
898
899 hr = AssignString(&pLink->wzValue, pixnLink);
887 - ExitOnFailure(hr, "Failed to allocate ATOM link value.");
900 + AtomExitOnFailure(hr, "Failed to allocate ATOM link value.");
901
902 LExit:
903 ReleaseBSTR(bstrNodeName);
@@ -916,39 +929,39 @@ static HRESULT ParseAtomUnknownElement(
929 ATOM_UNKNOWN_ELEMENT* pNewUnknownElement;
930
931 pNewUnknownElement = (ATOM_UNKNOWN_ELEMENT*)MemAlloc(sizeof(ATOM_UNKNOWN_ELEMENT), TRUE);
919 - ExitOnNull(pNewUnknownElement, hr, E_OUTOFMEMORY, "Failed to allocate unknown element.");
932 + AtomExitOnNull(pNewUnknownElement, hr, E_OUTOFMEMORY, "Failed to allocate unknown element.");
933
934 hr = pNode->get_namespaceURI(&bstrNodeNamespace);
935 if (S_OK == hr)
936 {
937 hr = StrAllocString(&pNewUnknownElement->wzNamespace, bstrNodeNamespace, 0);
925 - ExitOnFailure(hr, "Failed to allocate ATOM unknown element namespace.");
938 + AtomExitOnFailure(hr, "Failed to allocate ATOM unknown element namespace.");
939 }
940 else if (S_FALSE == hr)
941 {
942 hr = S_OK;
943 }
931 - ExitOnFailure(hr, "Failed to get unknown element namespace.");
944 + AtomExitOnFailure(hr, "Failed to get unknown element namespace.");
945
946 hr = pNode->get_baseName(&bstrNodeName);
934 - ExitOnFailure(hr, "Failed to get unknown element name.");
947 + AtomExitOnFailure(hr, "Failed to get unknown element name.");
948
949 hr = StrAllocString(&pNewUnknownElement->wzElement, bstrNodeName, 0);
937 - ExitOnFailure(hr, "Failed to allocate ATOM unknown element name.");
950 + AtomExitOnFailure(hr, "Failed to allocate ATOM unknown element name.");
951
952 hr = XmlGetText(pNode, &bstrNodeValue);
940 - ExitOnFailure(hr, "Failed to get unknown element value.");
953 + AtomExitOnFailure(hr, "Failed to get unknown element value.");
954
955 hr = StrAllocString(&pNewUnknownElement->wzValue, bstrNodeValue, 0);
943 - ExitOnFailure(hr, "Failed to allocate ATOM unknown element value.");
956 + AtomExitOnFailure(hr, "Failed to allocate ATOM unknown element value.");
957
958 hr = pNode->get_attributes(&pixnnmAttributes);
946 - ExitOnFailure(hr, "Failed get attributes on ATOM unknown element.");
959 + AtomExitOnFailure(hr, "Failed get attributes on ATOM unknown element.");
960
961 while (S_OK == (hr = pixnnmAttributes->nextNode(&pixnAttribute)))
962 {
963 hr = ParseAtomUnknownAttribute(pixnAttribute, &pNewUnknownElement->pAttributes);
951 - ExitOnFailure(hr, "Failed to parse attribute on ATOM unknown element.");
964 + AtomExitOnFailure(hr, "Failed to parse attribute on ATOM unknown element.");
965
966 ReleaseNullObject(pixnAttribute);
967 }
@@ -957,7 +970,7 @@ static HRESULT ParseAtomUnknownElement(
970 {
971 hr = S_OK;
972 }
960 - ExitOnFailure(hr, "Failed to enumerate all attributes on ATOM unknown element.");
973 + AtomExitOnFailure(hr, "Failed to enumerate all attributes on ATOM unknown element.");
974
975 ATOM_UNKNOWN_ELEMENT** ppTail = ppUnknownElement;
976 while (*ppTail)
@@ -999,31 +1012,31 @@ static HRESULT ParseAtomUnknownAttribute(
1012 ATOM_UNKNOWN_ATTRIBUTE* pNewUnknownAttribute;
1013
1014 pNewUnknownAttribute = (ATOM_UNKNOWN_ATTRIBUTE*)MemAlloc(sizeof(ATOM_UNKNOWN_ATTRIBUTE), TRUE);
1002 - ExitOnNull(pNewUnknownAttribute, hr, E_OUTOFMEMORY, "Failed to allocate unknown attribute.");
1015 + AtomExitOnNull(pNewUnknownAttribute, hr, E_OUTOFMEMORY, "Failed to allocate unknown attribute.");
1016
1017 hr = pNode->get_namespaceURI(&bstrNodeNamespace);
1018 if (S_OK == hr)
1019 {
1020 hr = StrAllocString(&pNewUnknownAttribute->wzNamespace, bstrNodeNamespace, 0);
1008 - ExitOnFailure(hr, "Failed to allocate ATOM unknown attribute namespace.");
1021 + AtomExitOnFailure(hr, "Failed to allocate ATOM unknown attribute namespace.");
1022 }
1023 else if (S_FALSE == hr)
1024 {
1025 hr = S_OK;
1026 }
1014 - ExitOnFailure(hr, "Failed to get unknown attribute namespace.");
1027 + AtomExitOnFailure(hr, "Failed to get unknown attribute namespace.");
1028
1029 hr = pNode->get_baseName(&bstrNodeName);
1017 - ExitOnFailure(hr, "Failed to get unknown attribute name.");
1030 + AtomExitOnFailure(hr, "Failed to get unknown attribute name.");
1031
1032 hr = StrAllocString(&pNewUnknownAttribute->wzAttribute, bstrNodeName, 0);
1020 - ExitOnFailure(hr, "Failed to allocate ATOM unknown attribute name.");
1033 + AtomExitOnFailure(hr, "Failed to allocate ATOM unknown attribute name.");
1034
1035 hr = XmlGetText(pNode, &bstrNodeValue);
1023 - ExitOnFailure(hr, "Failed to get unknown attribute value.");
1036 + AtomExitOnFailure(hr, "Failed to get unknown attribute value.");
1037
1038 hr = StrAllocString(&pNewUnknownAttribute->wzValue, bstrNodeValue, 0);
1026 - ExitOnFailure(hr, "Failed to allocate ATOM unknown attribute value.");
1039 + AtomExitOnFailure(hr, "Failed to allocate ATOM unknown attribute value.");
1040
1041 ATOM_UNKNOWN_ATTRIBUTE** ppTail = ppUnknownAttribute;
1042 while (*ppTail)
@@ -1060,16 +1073,16 @@ static HRESULT AssignDateTime(
1073 if (0 != pft->dwHighDateTime || 0 != pft->dwLowDateTime)
1074 {
1075 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
1063 - ExitOnRootFailure(hr, "Already process this datetime value.");
1076 + AtomExitOnRootFailure(hr, "Already process this datetime value.");
1077 }
1078
1079 hr = XmlGetText(pNode, &bstrValue);
1067 - ExitOnFailure(hr, "Failed to get value.");
1080 + AtomExitOnFailure(hr, "Failed to get value.");
1081
1082 if (S_OK == hr)
1083 {
1084 hr = TimeFromString3339(bstrValue, pft);
1072 - ExitOnFailure(hr, "Failed to convert value to time.");
1085 + AtomExitOnFailure(hr, "Failed to convert value to time.");
1086 }
1087 else
1088 {
@@ -1099,16 +1112,16 @@ static HRESULT AssignString(
1112 if (pwzValue && *pwzValue)
1113 {
1114 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
1102 - ExitOnRootFailure(hr, "Already processed this value.");
1115 + AtomExitOnRootFailure(hr, "Already processed this value.");
1116 }
1117
1118 hr = XmlGetText(pNode, &bstrValue);
1106 - ExitOnFailure(hr, "Failed to get value.");
1119 + AtomExitOnFailure(hr, "Failed to get value.");
1120
1121 if (S_OK == hr)
1122 {
1123 hr = StrAllocString(pwzValue, bstrValue, 0);
1111 - ExitOnFailure(hr, "Failed to allocate value.");
1124 + AtomExitOnFailure(hr, "Failed to allocate value.");
1125 }
1126 else
1127 {
src/dutil/buffutil.cpp
+57 -42
@@ -3,6 +3,21 @@
3 #include "precomp.h"
4
5
6 +// Exit macros
7 +#define BuffExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_BUFFUTIL, x, s, __VA_ARGS__)
8 +#define BuffExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_BUFFUTIL, x, s, __VA_ARGS__)
9 +#define BuffExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_BUFFUTIL, x, s, __VA_ARGS__)
10 +#define BuffExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_BUFFUTIL, x, s, __VA_ARGS__)
11 +#define BuffExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_BUFFUTIL, x, s, __VA_ARGS__)
12 +#define BuffExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_BUFFUTIL, x, s, __VA_ARGS__)
13 +#define BuffExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_BUFFUTIL, p, x, e, s, __VA_ARGS__)
14 +#define BuffExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_BUFFUTIL, p, x, s, __VA_ARGS__)
15 +#define BuffExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_BUFFUTIL, p, x, e, s, __VA_ARGS__)
16 +#define BuffExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_BUFFUTIL, p, x, s, __VA_ARGS__)
17 +#define BuffExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_BUFFUTIL, e, x, s, __VA_ARGS__)
18 +#define BuffExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_BUFFUTIL, g, x, s, __VA_ARGS__)
19 +
20 +
21 // constants
22
23 #define BUFFER_INCREMENT 128
@@ -11,7 +26,7 @@
26 // helper function declarations
27
28 static HRESULT EnsureBufferSize(
14 - __deref_out_bcount(cbSize) BYTE** ppbBuffer,
29 + __deref_inout_bcount(cbSize) BYTE** ppbBuffer,
30 __in SIZE_T cbSize
31 );
32
@@ -34,13 +49,13 @@ extern "C" HRESULT BuffReadNumber(
49
50 // get availiable data size
51 hr = ::SIZETSub(cbBuffer, *piBuffer, &cbAvailable);
37 - ExitOnRootFailure(hr, "Failed to calculate available data size.");
52 + BuffExitOnRootFailure(hr, "Failed to calculate available data size.");
53
54 // verify buffer size
55 if (sizeof(DWORD) > cbAvailable)
56 {
57 hr = E_INVALIDARG;
43 - ExitOnRootFailure(hr, "Buffer too small.");
58 + BuffExitOnRootFailure(hr, "Buffer too small.");
59 }
60
61 *pdw = *(const DWORD*)(pbBuffer + *piBuffer);
@@ -66,13 +81,13 @@ extern "C" HRESULT BuffReadNumber64(
81
82 // get availiable data size
83 hr = ::SIZETSub(cbBuffer, *piBuffer, &cbAvailable);
69 - ExitOnRootFailure(hr, "Failed to calculate available data size.");
84 + BuffExitOnRootFailure(hr, "Failed to calculate available data size.");
85
86 // verify buffer size
87 if (sizeof(DWORD64) > cbAvailable)
88 {
89 hr = E_INVALIDARG;
75 - ExitOnRootFailure(hr, "Buffer too small.");
90 + BuffExitOnRootFailure(hr, "Buffer too small.");
91 }
92
93 *pdw64 = *(const DWORD64*)(pbBuffer + *piBuffer);
@@ -98,13 +113,13 @@ extern "C" HRESULT BuffReadPointer(
113
114 // get availiable data size
115 hr = ::SIZETSub(cbBuffer, *piBuffer, &cbAvailable);
101 - ExitOnRootFailure(hr, "Failed to calculate available data size.");
116 + BuffExitOnRootFailure(hr, "Failed to calculate available data size.");
117
118 // verify buffer size
119 if (sizeof(DWORD_PTR) > cbAvailable)
120 {
121 hr = E_INVALIDARG;
107 - ExitOnRootFailure(hr, "Buffer too small.");
122 + BuffExitOnRootFailure(hr, "Buffer too small.");
123 }
124
125 *pdw64 = *(const DWORD_PTR*)(pbBuffer + *piBuffer);
@@ -132,38 +147,38 @@ extern "C" HRESULT BuffReadString(
147
148 // get availiable data size
149 hr = ::SIZETSub(cbBuffer, *piBuffer, &cbAvailable);
135 - ExitOnRootFailure(hr, "Failed to calculate available data size for character count.");
150 + BuffExitOnRootFailure(hr, "Failed to calculate available data size for character count.");
151
152 // verify buffer size
153 if (sizeof(DWORD) > cbAvailable)
154 {
155 hr = E_INVALIDARG;
141 - ExitOnRootFailure(hr, "Buffer too small.");
156 + BuffExitOnRootFailure(hr, "Buffer too small.");
157 }
158
159 // read character count
160 cch = *(const DWORD*)(pbBuffer + *piBuffer);
161
162 hr = ::DWordMult(cch, static_cast<DWORD>(sizeof(WCHAR)), &cb);
148 - ExitOnRootFailure(hr, "Overflow while multiplying to calculate buffer size");
163 + BuffExitOnRootFailure(hr, "Overflow while multiplying to calculate buffer size");
164
165 hr = ::SIZETAdd(*piBuffer, sizeof(DWORD), piBuffer);
151 - ExitOnRootFailure(hr, "Overflow while adding to calculate buffer size");
166 + BuffExitOnRootFailure(hr, "Overflow while adding to calculate buffer size");
167
168 // get availiable data size
169 hr = ::SIZETSub(cbBuffer, *piBuffer, &cbAvailable);
155 - ExitOnRootFailure(hr, "Failed to calculate available data size for character buffer.");
170 + BuffExitOnRootFailure(hr, "Failed to calculate available data size for character buffer.");
171
172 // verify buffer size
173 if (cb > cbAvailable)
174 {
175 hr = E_INVALIDARG;
161 - ExitOnRootFailure(hr, "Buffer too small to hold character data.");
176 + BuffExitOnRootFailure(hr, "Buffer too small to hold character data.");
177 }
178
179 // copy character data
180 hr = StrAllocString(pscz, cch ? (LPCWSTR)(pbBuffer + *piBuffer) : L"", cch);
166 - ExitOnFailure(hr, "Failed to copy character data.");
181 + BuffExitOnFailure(hr, "Failed to copy character data.");
182
183 *piBuffer += cb;
184
@@ -189,38 +204,38 @@ extern "C" HRESULT BuffReadStringAnsi(
204
205 // get availiable data size
206 hr = ::SIZETSub(cbBuffer, *piBuffer, &cbAvailable);
192 - ExitOnRootFailure(hr, "Failed to calculate available data size for character count.");
207 + BuffExitOnRootFailure(hr, "Failed to calculate available data size for character count.");
208
209 // verify buffer size
210 if (sizeof(DWORD) > cbAvailable)
211 {
212 hr = E_INVALIDARG;
198 - ExitOnRootFailure(hr, "Buffer too small.");
213 + BuffExitOnRootFailure(hr, "Buffer too small.");
214 }
215
216 // read character count
217 cch = *(const DWORD*)(pbBuffer + *piBuffer);
218
219 hr = ::DWordMult(cch, static_cast<DWORD>(sizeof(CHAR)), &cb);
205 - ExitOnRootFailure(hr, "Overflow while multiplying to calculate buffer size");
220 + BuffExitOnRootFailure(hr, "Overflow while multiplying to calculate buffer size");
221
222 hr = ::SIZETAdd(*piBuffer, sizeof(DWORD), piBuffer);
208 - ExitOnRootFailure(hr, "Overflow while adding to calculate buffer size");
223 + BuffExitOnRootFailure(hr, "Overflow while adding to calculate buffer size");
224
225 // get availiable data size
226 hr = ::SIZETSub(cbBuffer, *piBuffer, &cbAvailable);
212 - ExitOnRootFailure(hr, "Failed to calculate available data size for character buffer.");
227 + BuffExitOnRootFailure(hr, "Failed to calculate available data size for character buffer.");
228
229 // verify buffer size
230 if (cb > cbAvailable)
231 {
232 hr = E_INVALIDARG;
218 - ExitOnRootFailure(hr, "Buffer too small to hold character count.");
233 + BuffExitOnRootFailure(hr, "Buffer too small to hold character count.");
234 }
235
236 // copy character data
237 hr = StrAnsiAllocStringAnsi(pscz, cch ? (LPCSTR)(pbBuffer + *piBuffer) : "", cch);
223 - ExitOnFailure(hr, "Failed to copy character data.");
238 + BuffExitOnFailure(hr, "Failed to copy character data.");
239
240 *piBuffer += cb;
241
@@ -232,7 +247,7 @@ extern "C" HRESULT BuffReadStream(
247 __in_bcount(cbBuffer) const BYTE* pbBuffer,
248 __in SIZE_T cbBuffer,
249 __inout SIZE_T* piBuffer,
235 - __deref_out_bcount(*pcbStream) BYTE** ppbStream,
250 + __deref_inout_bcount(*pcbStream) BYTE** ppbStream,
251 __out SIZE_T* pcbStream
252 )
253 {
@@ -247,13 +262,13 @@ extern "C" HRESULT BuffReadStream(
262
263 // get availiable data size
264 hr = ::SIZETSub(cbBuffer, *piBuffer, &cbAvailable);
250 - ExitOnRootFailure(hr, "Failed to calculate available data size for stream size.");
265 + BuffExitOnRootFailure(hr, "Failed to calculate available data size for stream size.");
266
267 // verify buffer size
268 if (sizeof(DWORD64) > cbAvailable)
269 {
270 hr = E_INVALIDARG;
256 - ExitOnRootFailure(hr, "Buffer too small.");
271 + BuffExitOnRootFailure(hr, "Buffer too small.");
272 }
273
274 // read stream size
@@ -262,18 +277,18 @@ extern "C" HRESULT BuffReadStream(
277
278 // get availiable data size
279 hr = ::SIZETSub(cbBuffer, *piBuffer, &cbAvailable);
265 - ExitOnRootFailure(hr, "Failed to calculate available data size for stream buffer.");
280 + BuffExitOnRootFailure(hr, "Failed to calculate available data size for stream buffer.");
281
282 // verify buffer size
283 if (cb > cbAvailable)
284 {
285 hr = E_INVALIDARG;
271 - ExitOnRootFailure(hr, "Buffer too small to hold byte count.");
286 + BuffExitOnRootFailure(hr, "Buffer too small to hold byte count.");
287 }
288
289 // allocate buffer
290 *ppbStream = (BYTE*)MemAlloc((SIZE_T)cb, TRUE);
276 - ExitOnNull(*ppbStream, hr, E_OUTOFMEMORY, "Failed to allocate stream.");
291 + BuffExitOnNull(*ppbStream, hr, E_OUTOFMEMORY, "Failed to allocate stream.");
292
293 // read stream data
294 memcpy_s(*ppbStream, cbBuffer - *piBuffer, pbBuffer + *piBuffer, (SIZE_T)cb);
@@ -287,7 +302,7 @@ LExit:
302 }
303
304 extern "C" HRESULT BuffWriteNumber(
290 - __deref_out_bcount(*piBuffer) BYTE** ppbBuffer,
305 + __deref_inout_bcount(*piBuffer) BYTE** ppbBuffer,
306 __inout SIZE_T* piBuffer,
307 __in DWORD_PTR dw
308 )
@@ -299,7 +314,7 @@ extern "C" HRESULT BuffWriteNumber(
314
315 // make sure we have a buffer with sufficient space
316 hr = EnsureBufferSize(ppbBuffer, *piBuffer + sizeof(DWORD));
302 - ExitOnFailure(hr, "Failed to ensure buffer size.");
317 + BuffExitOnFailure(hr, "Failed to ensure buffer size.");
318
319 // copy data to buffer
320 *(DWORD_PTR*)(*ppbBuffer + *piBuffer) = dw;
@@ -310,7 +325,7 @@ LExit:
325 }
326
327 extern "C" HRESULT BuffWriteNumber64(
313 - __deref_out_bcount(*piBuffer) BYTE** ppbBuffer,
328 + __deref_inout_bcount(*piBuffer) BYTE** ppbBuffer,
329 __inout SIZE_T* piBuffer,
330 __in DWORD64 dw64
331 )
@@ -322,7 +337,7 @@ extern "C" HRESULT BuffWriteNumber64(
337
338 // make sure we have a buffer with sufficient space
339 hr = EnsureBufferSize(ppbBuffer, *piBuffer + sizeof(DWORD64));
325 - ExitOnFailure(hr, "Failed to ensure buffer size.");
340 + BuffExitOnFailure(hr, "Failed to ensure buffer size.");
341
342 // copy data to buffer
343 *(DWORD64*)(*ppbBuffer + *piBuffer) = dw64;
@@ -333,7 +348,7 @@ LExit:
348 }
349
350 extern "C" HRESULT BuffWritePointer(
336 - __deref_out_bcount(*piBuffer) BYTE** ppbBuffer,
351 + __deref_inout_bcount(*piBuffer) BYTE** ppbBuffer,
352 __inout SIZE_T* piBuffer,
353 __in DWORD_PTR dw
354 )
@@ -345,7 +360,7 @@ extern "C" HRESULT BuffWritePointer(
360
361 // make sure we have a buffer with sufficient space
362 hr = EnsureBufferSize(ppbBuffer, *piBuffer + sizeof(DWORD_PTR));
348 - ExitOnFailure(hr, "Failed to ensure buffer size.");
363 + BuffExitOnFailure(hr, "Failed to ensure buffer size.");
364
365 // copy data to buffer
366 *(DWORD_PTR*)(*ppbBuffer + *piBuffer) = dw;
@@ -356,7 +371,7 @@ LExit:
371 }
372
373 extern "C" HRESULT BuffWriteString(
359 - __deref_out_bcount(*piBuffer) BYTE** ppbBuffer,
374 + __deref_inout_bcount(*piBuffer) BYTE** ppbBuffer,
375 __inout SIZE_T* piBuffer,
376 __in_z_opt LPCWSTR scz
377 )
@@ -370,7 +385,7 @@ extern "C" HRESULT BuffWriteString(
385
386 // make sure we have a buffer with sufficient space
387 hr = EnsureBufferSize(ppbBuffer, *piBuffer + (sizeof(DWORD) + cb));
373 - ExitOnFailure(hr, "Failed to ensure buffer size.");
388 + BuffExitOnFailure(hr, "Failed to ensure buffer size.");
389
390 // copy character count to buffer
391 *(DWORD*)(*ppbBuffer + *piBuffer) = cch;
@@ -385,7 +400,7 @@ LExit:
400 }
401
402 extern "C" HRESULT BuffWriteStringAnsi(
388 - __deref_out_bcount(*piBuffer) BYTE** ppbBuffer,
403 + __deref_inout_bcount(*piBuffer) BYTE** ppbBuffer,
404 __inout SIZE_T* piBuffer,
405 __in_z_opt LPCSTR scz
406 )
@@ -399,7 +414,7 @@ extern "C" HRESULT BuffWriteStringAnsi(
414
415 // make sure we have a buffer with sufficient space
416 hr = EnsureBufferSize(ppbBuffer, *piBuffer + (sizeof(DWORD) + cb));
402 - ExitOnFailure(hr, "Failed to ensure buffer size.");
417 + BuffExitOnFailure(hr, "Failed to ensure buffer size.");
418
419 // copy character count to buffer
420 *(DWORD*)(*ppbBuffer + *piBuffer) = cch;
@@ -414,7 +429,7 @@ LExit:
429 }
430
431 extern "C" HRESULT BuffWriteStream(
417 - __deref_out_bcount(*piBuffer) BYTE** ppbBuffer,
432 + __deref_inout_bcount(*piBuffer) BYTE** ppbBuffer,
433 __inout SIZE_T* piBuffer,
434 __in_bcount(cbStream) const BYTE* pbStream,
435 __in SIZE_T cbStream
@@ -429,7 +444,7 @@ extern "C" HRESULT BuffWriteStream(
444
445 // make sure we have a buffer with sufficient space
446 hr = EnsureBufferSize(ppbBuffer, *piBuffer + cbStream + sizeof(DWORD64));
432 - ExitOnFailure(hr, "Failed to ensure buffer size.");
447 + BuffExitOnFailure(hr, "Failed to ensure buffer size.");
448
449 // copy byte count to buffer
450 *(DWORD64*)(*ppbBuffer + *piBuffer) = cb;
@@ -447,7 +462,7 @@ LExit:
462 // helper functions
463
464 static HRESULT EnsureBufferSize(
450 - __deref_out_bcount(cbSize) BYTE** ppbBuffer,
465 + __deref_inout_bcount(cbSize) BYTE** ppbBuffer,
466 __in SIZE_T cbSize
467 )
468 {
@@ -459,14 +474,14 @@ static HRESULT EnsureBufferSize(
474 if (MemSize(*ppbBuffer) < cbTarget)
475 {
476 LPVOID pv = MemReAlloc(*ppbBuffer, cbTarget, TRUE);
462 - ExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to reallocate buffer.");
477 + BuffExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to reallocate buffer.");
478 *ppbBuffer = (BYTE*)pv;
479 }
480 }
481 else
482 {
483 *ppbBuffer = (BYTE*)MemAlloc(cbTarget, TRUE);
469 - ExitOnNull(*ppbBuffer, hr, E_OUTOFMEMORY, "Failed to allocate buffer.");
484 + BuffExitOnNull(*ppbBuffer, hr, E_OUTOFMEMORY, "Failed to allocate buffer.");
485 }
486
487 LExit:
src/dutil/cabcutil.cpp
+117 -101
@@ -2,6 +2,22 @@
2
3 #include "precomp.h"
4
5 +
6 +// Exit macros
7 +#define CabcExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_CABCUTIL, x, s, __VA_ARGS__)
8 +#define CabcExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_CABCUTIL, x, s, __VA_ARGS__)
9 +#define CabcExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_CABCUTIL, x, s, __VA_ARGS__)
10 +#define CabcExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_CABCUTIL, x, s, __VA_ARGS__)
11 +#define CabcExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_CABCUTIL, x, s, __VA_ARGS__)
12 +#define CabcExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_CABCUTIL, x, s, __VA_ARGS__)
13 +#define CabcExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_CABCUTIL, p, x, e, s, __VA_ARGS__)
14 +#define CabcExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_CABCUTIL, p, x, s, __VA_ARGS__)
15 +#define CabcExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_CABCUTIL, p, x, e, s, __VA_ARGS__)
16 +#define CabcExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_CABCUTIL, p, x, s, __VA_ARGS__)
17 +#define CabcExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_CABCUTIL, e, x, s, __VA_ARGS__)
18 +#define CabcExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_CABCUTIL, g, x, s, __VA_ARGS__)
19 +
20 +
21 static const WCHAR CABC_MAGIC_UNICODE_STRING_MARKER = '?';
22 static const DWORD MAX_CABINET_HEADER_SIZE = 16 * 1024 * 1024;
23
@@ -144,19 +160,19 @@ static HRESULT UtcFileTimeToLocalDosDateTime(
160 __out USHORT* pTime
161 );
162
147 -static __callback int DIAMONDAPI CabCFilePlaced(__in PCCAB pccab, __in_z PSTR szFile, __in long cbFile, __in BOOL fContinuation, __out_bcount(CABC_HANDLE_BYTES) void *pv);
163 +static __callback int DIAMONDAPI CabCFilePlaced(__in PCCAB pccab, __in_z PSTR szFile, __in long cbFile, __in BOOL fContinuation, __inout_bcount(CABC_HANDLE_BYTES) void *pv);
164 static __callback void * DIAMONDAPI CabCAlloc(__in ULONG cb);
165 static __callback void DIAMONDAPI CabCFree(__out_bcount(CABC_HANDLE_BYTES) void *pv);
150 -static __callback INT_PTR DIAMONDAPI CabCOpen(__in_z PSTR pszFile, __in int oflag, __in int pmode, __out int *err, __out_bcount(CABC_HANDLE_BYTES) void *pv);
151 -static __callback UINT FAR DIAMONDAPI CabCRead(__in INT_PTR hf, __out_bcount(cb) void FAR *memory, __in UINT cb, __out int *err, __out_bcount(CABC_HANDLE_BYTES) void *pv);
152 -static __callback UINT FAR DIAMONDAPI CabCWrite(__in INT_PTR hf, __in_bcount(cb) void FAR *memory, __in UINT cb, __out int *err, __out_bcount(CABC_HANDLE_BYTES) void *pv);
153 -static __callback long FAR DIAMONDAPI CabCSeek(__in INT_PTR hf, __in long dist, __in int seektype, __out int *err, __out_bcount(CABC_HANDLE_BYTES) void *pv);
154 -static __callback int FAR DIAMONDAPI CabCClose(__in INT_PTR hf, __out int *err, __out_bcount(CABC_HANDLE_BYTES) void *pv);
155 -static __callback int DIAMONDAPI CabCDelete(__in_z PSTR szFile, __out int *err, __out_bcount(CABC_HANDLE_BYTES) void *pv);
156 -__success(return != FALSE) static __callback BOOL DIAMONDAPI CabCGetTempFile(__out_bcount_z(cbFile) char *szFile, __in int cbFile, __out_bcount(CABC_HANDLE_BYTES) void *pv);
166 +static __callback INT_PTR DIAMONDAPI CabCOpen(__in_z PSTR pszFile, __in int oflag, __in int pmode, __out int *err, __inout_bcount(CABC_HANDLE_BYTES) void *pv);
167 +static __callback UINT FAR DIAMONDAPI CabCRead(__in INT_PTR hf, __out_bcount(cb) void FAR *memory, __in UINT cb, __out int *err, __inout_bcount(CABC_HANDLE_BYTES) void *pv);
168 +static __callback UINT FAR DIAMONDAPI CabCWrite(__in INT_PTR hf, __in_bcount(cb) void FAR *memory, __in UINT cb, __out int *err, __inout_bcount(CABC_HANDLE_BYTES) void *pv);
169 +static __callback long FAR DIAMONDAPI CabCSeek(__in INT_PTR hf, __in long dist, __in int seektype, __out int *err, __inout_bcount(CABC_HANDLE_BYTES) void *pv);
170 +static __callback int FAR DIAMONDAPI CabCClose(__in INT_PTR hf, __out int *err, __inout_bcount(CABC_HANDLE_BYTES) void *pv);
171 +static __callback int DIAMONDAPI CabCDelete(__in_z PSTR szFile, __out int *err, __inout_bcount(CABC_HANDLE_BYTES) void *pv);
172 +__success(return != FALSE) static __callback BOOL DIAMONDAPI CabCGetTempFile(__out_bcount_z(cbFile) char *szFile, __in int cbFile, __inout_bcount(CABC_HANDLE_BYTES) void *pv);
173 __success(return != FALSE) static __callback BOOL DIAMONDAPI CabCGetNextCabinet(__in PCCAB pccab, __in ULONG ul, __out_bcount(CABC_HANDLE_BYTES) void *pv);
174 static __callback INT_PTR DIAMONDAPI CabCGetOpenInfo(__in_z PSTR pszName, __out USHORT *pdate, __out USHORT *ptime, __out USHORT *pattribs, __out int *err, __out_bcount(CABC_HANDLE_BYTES) void *pv);
159 -static __callback long DIAMONDAPI CabCStatus(__in UINT uiTypeStatus, __in ULONG cb1, __in ULONG cb2, __out_bcount(CABC_HANDLE_BYTES) void *pv);
175 +static __callback long DIAMONDAPI CabCStatus(__in UINT uiTypeStatus, __in ULONG cb1, __in ULONG cb2, __inout_bcount(CABC_HANDLE_BYTES) void *pv);
176
177
178 /********************************************************************
@@ -174,7 +190,7 @@ extern "C" HRESULT DAPI CabCBegin(
190 __in DWORD dwMaxSize,
191 __in DWORD dwMaxThresh,
192 __in COMPRESSION_TYPE ct,
177 - __out HANDLE *phContext
193 + __out_bcount(CABC_HANDLE_BYTES) HANDLE *phContext
194 )
195 {
196 Assert(wzCab && *wzCab && phContext);
@@ -190,28 +206,28 @@ extern "C" HRESULT DAPI CabCBegin(
206 if (wzCabDir)
207 {
208 hr = ::StringCchLengthW(wzCabDir, MAX_PATH, &cchPathBuffer);
193 - ExitOnFailure(hr, "Failed to get length of cab directory");
209 + CabcExitOnFailure(hr, "Failed to get length of cab directory");
210
211 // Need room to terminate with L'\\' and L'\0'
212 if((MAX_PATH - 1) <= cchPathBuffer || 0 == cchPathBuffer)
213 {
214 hr = E_INVALIDARG;
199 - ExitOnFailure(hr, "Cab directory had invalid length: %u", cchPathBuffer);
215 + CabcExitOnFailure(hr, "Cab directory had invalid length: %u", cchPathBuffer);
216 }
217
218 hr = ::StringCchCopyW(wzPathBuffer, countof(wzPathBuffer), wzCabDir);
203 - ExitOnFailure(hr, "Failed to copy cab directory to buffer");
219 + CabcExitOnFailure(hr, "Failed to copy cab directory to buffer");
220
221 if (L'\\' != wzPathBuffer[cchPathBuffer - 1])
222 {
223 hr = ::StringCchCatW(wzPathBuffer, countof(wzPathBuffer), L"\\");
208 - ExitOnFailure(hr, "Failed to cat \\ to end of buffer");
224 + CabcExitOnFailure(hr, "Failed to cat \\ to end of buffer");
225 ++cchPathBuffer;
226 }
227 }
228
229 pcd = static_cast<CABC_DATA*>(MemAlloc(sizeof(CABC_DATA), TRUE));
214 - ExitOnNull(pcd, hr, E_OUTOFMEMORY, "failed to allocate cab creation data structure");
230 + CabcExitOnNull(pcd, hr, E_OUTOFMEMORY, "failed to allocate cab creation data structure");
231
232 pcd->hrLastError = S_OK;
233 pcd->fGoodCab = TRUE;
@@ -266,35 +282,35 @@ extern "C" HRESULT DAPI CabCBegin(
282 else
283 {
284 hr = E_INVALIDARG;
269 - ExitOnFailure(hr, "Invalid compression type specified.");
285 + CabcExitOnFailure(hr, "Invalid compression type specified.");
286 }
287
288 if (0 == ::WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, wzCab, -1, pcd->ccab.szCab, sizeof(pcd->ccab.szCab), NULL, NULL))
289 {
274 - ExitWithLastError(hr, "failed to convert cab name to multi-byte");
290 + CabcExitWithLastError(hr, "failed to convert cab name to multi-byte");
291 }
292
293 if (0 == ::WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, wzPathBuffer, -1, pcd->ccab.szCabPath, sizeof(pcd->ccab.szCab), NULL, NULL))
294 {
279 - ExitWithLastError(hr, "failed to convert cab dir to multi-byte");
295 + CabcExitWithLastError(hr, "failed to convert cab dir to multi-byte");
296 }
297
298 // Remember the path to the cabinet.
299 hr= ::StringCchCopyW(pcd->wzCabinetPath, countof(pcd->wzCabinetPath), wzPathBuffer);
284 - ExitOnFailure(hr, "Failed to copy cabinet path from path: %ls", wzPathBuffer);
300 + CabcExitOnFailure(hr, "Failed to copy cabinet path from path: %ls", wzPathBuffer);
301
302 hr = ::StringCchCatW(pcd->wzCabinetPath, countof(pcd->wzCabinetPath), wzCab);
287 - ExitOnFailure(hr, "Failed to concat to cabinet path cabinet name: %ls", wzCab);
303 + CabcExitOnFailure(hr, "Failed to concat to cabinet path cabinet name: %ls", wzCab);
304
305 // Get the empty file to use as the blank marker for duplicates.
306 if (!::GetTempPathW(countof(wzTempPath), wzTempPath))
307 {
292 - ExitWithLastError(hr, "Failed to get temp path.");
308 + CabcExitWithLastError(hr, "Failed to get temp path.");
309 }
310
311 if (!::GetTempFileNameW(wzTempPath, L"WSC", 0, pcd->wzEmptyFile))
312 {
297 - ExitWithLastError(hr, "Failed to create a temp file name.");
313 + CabcExitWithLastError(hr, "Failed to create a temp file name.");
314 }
315
316 // Try to open the newly created empty file (remember, GetTempFileName() is kind enough to create a file for us)
@@ -303,7 +319,7 @@ extern "C" HRESULT DAPI CabCBegin(
319 pcd->hEmptyFile = ::CreateFileW(pcd->wzEmptyFile, 0, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE, NULL);
320
321 hr = DictCreateWithEmbeddedKey(&pcd->shDictHandle, dwMaxFiles, reinterpret_cast<void **>(&pcd->prgFiles), offsetof(CABC_FILE, pwzSourcePath), DICT_FLAG_CASEINSENSITIVE);
306 - ExitOnFailure(hr, "Failed to create dictionary to keep track of duplicate files");
322 + CabcExitOnFailure(hr, "Failed to create dictionary to keep track of duplicate files");
323
324 // Make sure to allocate at least some space, or we won't be able to realloc later if they "lied" about having zero files
325 if (1 > dwMaxFiles)
@@ -315,10 +331,10 @@ extern "C" HRESULT DAPI CabCBegin(
331 size_t cbFileAllocSize = 0;
332
333 hr = ::SizeTMult(pcd->cMaxFilePaths, sizeof(CABC_FILE), &(cbFileAllocSize));
318 - ExitOnFailure(hr, "Maximum allocation exceeded on initialization.");
334 + CabcExitOnFailure(hr, "Maximum allocation exceeded on initialization.");
335
336 pcd->prgFiles = static_cast<CABC_FILE*>(MemAlloc(cbFileAllocSize, TRUE));
321 - ExitOnNull(pcd->prgFiles, hr, E_OUTOFMEMORY, "Failed to allocate memory for files.");
337 + CabcExitOnNull(pcd->prgFiles, hr, E_OUTOFMEMORY, "Failed to allocate memory for files.");
338
339 // Tell cabinet API about our configuration.
340 pcd->hfci = ::FCICreate(&(pcd->erf), CabCFilePlaced, CabCAlloc, CabCFree, CabCOpen, CabCRead, CabCWrite, CabCClose, CabCSeek, CabCDelete, CabCGetTempFile, &(pcd->ccab), pcd);
@@ -331,12 +347,12 @@ extern "C" HRESULT DAPI CabCBegin(
347 }
348 else
349 {
334 - ExitWithLastError(hr, "failed to create FCI object Oper: 0x%x Type: 0x%x", pcd->erf.erfOper, pcd->erf.erfType);
350 + CabcExitWithLastError(hr, "failed to create FCI object Oper: 0x%x Type: 0x%x", pcd->erf.erfOper, pcd->erf.erfType);
351 }
352
353 pcd->fGoodCab = FALSE;
354
339 - ExitOnFailure(hr, "failed to create FCI object Oper: 0x%x Type: 0x%x", pcd->erf.erfOper, pcd->erf.erfType); // TODO: can these be converted to HRESULTS?
355 + CabcExitOnFailure(hr, "failed to create FCI object Oper: 0x%x Type: 0x%x", pcd->erf.erfOper, pcd->erf.erfType); // TODO: can these be converted to HRESULTS?
356 }
357
358 *phContext = pcd;
@@ -392,25 +408,25 @@ extern "C" HRESULT DAPI CabCAddFile(
408 {
409 // Store file size, primarily used to determine which files to hash for duplicates
410 hr = FileSize(wzFile, &llFileSize);
395 - ExitOnFailure(hr, "Failed to check size of file %ls", wzFile);
411 + CabcExitOnFailure(hr, "Failed to check size of file %ls", wzFile);
412
413 hr = CheckForDuplicateFile(pcd, &pcfDuplicate, wzFile, &pmfLocalHash, llFileSize);
398 - ExitOnFailure(hr, "Failed while checking for duplicate of file: %ls", wzFile);
414 + CabcExitOnFailure(hr, "Failed while checking for duplicate of file: %ls", wzFile);
415 }
416
417 if (pcfDuplicate) // This will be null for smart cabbing case
418 {
419 DWORD index;
420 hr = ::PtrdiffTToDWord(pcfDuplicate - pcd->prgFiles, &index);
405 - ExitOnFailure(hr, "Failed to calculate index of file name: %ls", pcfDuplicate->pwzSourcePath);
421 + CabcExitOnFailure(hr, "Failed to calculate index of file name: %ls", pcfDuplicate->pwzSourcePath);
422
423 hr = AddDuplicateFile(pcd, index, wzFile, wzToken, pcd->dwLastFileIndex);
408 - ExitOnFailure(hr, "Failed to add duplicate of file name: %ls", pcfDuplicate->pwzSourcePath);
424 + CabcExitOnFailure(hr, "Failed to add duplicate of file name: %ls", pcfDuplicate->pwzSourcePath);
425 }
426 else
427 {
428 hr = AddNonDuplicateFile(pcd, wzFile, wzToken, pmfLocalHash, llFileSize, pcd->dwLastFileIndex);
413 - ExitOnFailure(hr, "Failed to add non-duplicated file: %ls", wzFile);
429 + CabcExitOnFailure(hr, "Failed to add non-duplicated file: %ls", wzFile);
430 }
431
432 ++pcd->dwLastFileIndex;
@@ -483,13 +499,13 @@ extern "C" HRESULT DAPI CabCFinish(
499 {
500 LPCWSTR pwzTemp = pcd->prgFiles[dwArrayFileIndex].pwzToken;
501 hr = StrAnsiAllocString(&pszFileToken, pwzTemp, 0, CP_ACP);
486 - ExitOnFailure(hr, "failed to convert file token to ANSI: %ls", pwzTemp);
502 + CabcExitOnFailure(hr, "failed to convert file token to ANSI: %ls", pwzTemp);
503 }
504 else
505 {
506 LPCWSTR pwzTemp = FileFromPath(fileInfo.wzSourcePath);
507 hr = StrAnsiAllocString(&pszFileToken, pwzTemp, 0, CP_ACP);
492 - ExitOnFailure(hr, "failed to convert file name to ANSI: %ls", pwzTemp);
508 + CabcExitOnFailure(hr, "failed to convert file name to ANSI: %ls", pwzTemp);
509 }
510
511 if (pcd->prgFiles[dwArrayFileIndex].fHasDuplicates)
@@ -518,13 +534,13 @@ extern "C" HRESULT DAPI CabCFinish(
534 {
535 LPCWSTR pwzTemp = pcd->prgDuplicates[dwDupeArrayFileIndex].pwzToken;
536 hr = StrAnsiAllocString(&pszFileToken, pwzTemp, 0, CP_ACP);
521 - ExitOnFailure(hr, "failed to convert duplicate file token to ANSI: %ls", pwzTemp);
537 + CabcExitOnFailure(hr, "failed to convert duplicate file token to ANSI: %ls", pwzTemp);
538 }
539 else
540 {
541 LPCWSTR pwzTemp = FileFromPath(fileInfo.wzSourcePath);
542 hr = StrAnsiAllocString(&pszFileToken, pwzTemp, 0, CP_ACP);
527 - ExitOnFailure(hr, "failed to convert duplicate file name to ANSI: %ls", pwzTemp);
543 + CabcExitOnFailure(hr, "failed to convert duplicate file name to ANSI: %ls", pwzTemp);
544 }
545
546 // Flush afterward only if this isn't a duplicate of the previous file, and at least one non-duplicate file remains to be added to the cab
@@ -543,14 +559,14 @@ extern "C" HRESULT DAPI CabCFinish(
559 else // If it's neither duplicate nor non-duplicate, throw an error
560 {
561 hr = HRESULT_FROM_WIN32(ERROR_EA_LIST_INCONSISTENT);
546 - ExitOnRootFailure(hr, "Internal inconsistency in data structures while creating CAB file - a non-standard, non-duplicate file was encountered");
562 + CabcExitOnRootFailure(hr, "Internal inconsistency in data structures while creating CAB file - a non-standard, non-duplicate file was encountered");
563 }
564
565 if (fFlushBefore && pcd->llBytesSinceLastFlush > pcd->llFlushThreshhold)
566 {
567 if (!::FCIFlushFolder(pcd->hfci, CabCGetNextCabinet, CabCStatus))
568 {
553 - ExitWithLastError(hr, "failed to flush FCI folder before adding file, Oper: 0x%x Type: 0x%x", pcd->erf.erfOper, pcd->erf.erfType);
569 + CabcExitWithLastError(hr, "failed to flush FCI folder before adding file, Oper: 0x%x Type: 0x%x", pcd->erf.erfOper, pcd->erf.erfType);
570 }
571 pcd->llBytesSinceLastFlush = 0;
572 }
@@ -574,10 +590,10 @@ extern "C" HRESULT DAPI CabCFinish(
590 }
591 else
592 {
577 - ExitWithLastError(hr, "failed to add file to FCI object Oper: 0x%x Type: 0x%x File: %ls", pcd->erf.erfOper, pcd->erf.erfType, fileInfo.wzSourcePath);
593 + CabcExitWithLastError(hr, "failed to add file to FCI object Oper: 0x%x Type: 0x%x File: %ls", pcd->erf.erfOper, pcd->erf.erfType, fileInfo.wzSourcePath);
594 }
595
580 - ExitOnFailure(hr, "failed to add file to FCI object Oper: 0x%x Type: 0x%x File: %ls", pcd->erf.erfOper, pcd->erf.erfType, fileInfo.wzSourcePath); // TODO: can these be converted to HRESULTS?
596 + CabcExitOnFailure(hr, "failed to add file to FCI object Oper: 0x%x Type: 0x%x File: %ls", pcd->erf.erfOper, pcd->erf.erfType, fileInfo.wzSourcePath); // TODO: can these be converted to HRESULTS?
597 }
598
599 // For Cabinet Splitting case, check for pcd->hrLastError that may be set as result of Error in CabCGetNextCabinet
@@ -585,14 +601,14 @@ extern "C" HRESULT DAPI CabCFinish(
601 if (pcd->fCabinetSplittingEnabled && FAILED(pcd->hrLastError))
602 {
603 hr = pcd->hrLastError;
588 - ExitOnFailure(hr, "Failed to create next cabinet name while splitting cabinet.");
604 + CabcExitOnFailure(hr, "Failed to create next cabinet name while splitting cabinet.");
605 }
606
607 if (fFlushAfter && pcd->llBytesSinceLastFlush > pcd->llFlushThreshhold)
608 {
609 if (!::FCIFlushFolder(pcd->hfci, CabCGetNextCabinet, CabCStatus))
610 {
595 - ExitWithLastError(hr, "failed to flush FCI folder after adding file, Oper: 0x%x Type: 0x%x", pcd->erf.erfOper, pcd->erf.erfType);
611 + CabcExitWithLastError(hr, "failed to flush FCI folder after adding file, Oper: 0x%x Type: 0x%x", pcd->erf.erfOper, pcd->erf.erfType);
612 }
613 pcd->llBytesSinceLastFlush = 0;
614 }
@@ -610,10 +626,10 @@ extern "C" HRESULT DAPI CabCFinish(
626 }
627 else
628 {
613 - ExitWithLastError(hr, "failed while creating CAB FCI object Oper: 0x%x Type: 0x%x File: %s", pcd->erf.erfOper, pcd->erf.erfType);
629 + CabcExitWithLastError(hr, "failed while creating CAB FCI object Oper: 0x%x Type: 0x%x File: %ls", pcd->erf.erfOper, pcd->erf.erfType, fileInfo.wzSourcePath);
630 }
631
616 - ExitOnFailure(hr, "failed while creating CAB FCI object Oper: 0x%x Type: 0x%x File: %s", pcd->erf.erfOper, pcd->erf.erfType); // TODO: can these be converted to HRESULTS?
632 + CabcExitOnFailure(hr, "failed while creating CAB FCI object Oper: 0x%x Type: 0x%x File: %ls", pcd->erf.erfOper, pcd->erf.erfType, fileInfo.wzSourcePath); // TODO: can these be converted to HRESULTS?
633 }
634
635 // Only flush the cabinet if we actually succeeded in previous calls - otherwise we just waste time (a lot on big cabs)
@@ -621,13 +637,13 @@ extern "C" HRESULT DAPI CabCFinish(
637 {
638 // If we have a last error, use that, otherwise return the useless error
639 hr = FAILED(pcd->hrLastError) ? pcd->hrLastError : E_FAIL;
624 - ExitOnFailure(hr, "failed to flush FCI object Oper: 0x%x Type: 0x%x", pcd->erf.erfOper, pcd->erf.erfType); // TODO: can these be converted to HRESULTS?
640 + CabcExitOnFailure(hr, "failed to flush FCI object Oper: 0x%x Type: 0x%x", pcd->erf.erfOper, pcd->erf.erfType); // TODO: can these be converted to HRESULTS?
641 }
642
643 if (pcd->fGoodCab && pcd->cDuplicates)
644 {
645 hr = UpdateDuplicateFiles(pcd);
630 - ExitOnFailure(hr, "Failed to update duplicates in cabinet: %ls", pcd->wzCabinetPath);
646 + CabcExitOnFailure(hr, "Failed to update duplicates in cabinet: %ls", pcd->wzCabinetPath);
647 }
648
649 LExit:
@@ -697,8 +713,8 @@ static HRESULT CheckForDuplicateFile(
713 HRESULT hr = S_OK;
714 UINT er = ERROR_SUCCESS;
715
700 - ExitOnNull(ppcf, hr, E_INVALIDARG, "No file structure sent while checking for duplicate file");
701 - ExitOnNull(ppmfHash, hr, E_INVALIDARG, "No file hash structure pointer sent while checking for duplicate file");
716 + CabcExitOnNull(ppcf, hr, E_INVALIDARG, "No file structure sent while checking for duplicate file");
717 + CabcExitOnNull(ppmfHash, hr, E_INVALIDARG, "No file hash structure pointer sent while checking for duplicate file");
718
719 *ppcf = NULL; // By default, we'll set our output to NULL
720
@@ -712,7 +728,7 @@ static HRESULT CheckForDuplicateFile(
728 {
729 hr = S_OK;
730 }
715 - ExitOnFailure(hr, "Failed while searching for file in dictionary of previously added files");
731 + CabcExitOnFailure(hr, "Failed while searching for file in dictionary of previously added files");
732
733 for (i = 0; i < pcd->cFilePaths; ++i)
734 {
@@ -723,22 +739,22 @@ static HRESULT CheckForDuplicateFile(
739 if (pcd->prgFiles[i].pmfHash == NULL)
740 {
741 pcd->prgFiles[i].pmfHash = (PMSIFILEHASHINFO)MemAlloc(sizeof(MSIFILEHASHINFO), FALSE);
726 - ExitOnNull(pcd->prgFiles[i].pmfHash, hr, E_OUTOFMEMORY, "Failed to allocate memory for candidate duplicate file's MSI file hash");
742 + CabcExitOnNull(pcd->prgFiles[i].pmfHash, hr, E_OUTOFMEMORY, "Failed to allocate memory for candidate duplicate file's MSI file hash");
743
744 pcd->prgFiles[i].pmfHash->dwFileHashInfoSize = sizeof(MSIFILEHASHINFO);
745 er = ::MsiGetFileHashW(pcd->prgFiles[i].pwzSourcePath, 0, pcd->prgFiles[i].pmfHash);
730 - ExitOnWin32Error(er, hr, "Failed while getting MSI file hash of candidate duplicate file: %ls", pcd->prgFiles[i].pwzSourcePath);
746 + CabcExitOnWin32Error(er, hr, "Failed while getting MSI file hash of candidate duplicate file: %ls", pcd->prgFiles[i].pwzSourcePath);
747 }
748
749 // If our own file hasn't yet been hashed, hash it
750 if (NULL == *ppmfHash)
751 {
752 *ppmfHash = (PMSIFILEHASHINFO)MemAlloc(sizeof(MSIFILEHASHINFO), FALSE);
737 - ExitOnNull(*ppmfHash, hr, E_OUTOFMEMORY, "Failed to allocate memory for file's MSI file hash");
753 + CabcExitOnNull(*ppmfHash, hr, E_OUTOFMEMORY, "Failed to allocate memory for file's MSI file hash");
754
755 (*ppmfHash)->dwFileHashInfoSize = sizeof(MSIFILEHASHINFO);
756 er = ::MsiGetFileHashW(wzFileName, 0, *ppmfHash);
741 - ExitOnWin32Error(er, hr, "Failed while getting MSI file hash of file: %ls", pcd->prgFiles[i].pwzSourcePath);
757 + CabcExitOnWin32Error(er, hr, "Failed while getting MSI file hash of file: %ls", pcd->prgFiles[i].pwzSourcePath);
758 }
759
760 // If the two file hashes are both of the expected size, and they match, we've got a match, so return it!
@@ -779,17 +795,17 @@ static HRESULT AddDuplicateFile(
795 size_t cbDuplicates = 0;
796
797 hr = ::SizeTMult(pcd->cMaxDuplicates, sizeof(CABC_DUPLICATEFILE), &cbDuplicates);
782 - ExitOnFailure(hr, "Maximum allocation exceeded.");
798 + CabcExitOnFailure(hr, "Maximum allocation exceeded.");
799
800 if (pcd->cDuplicates)
801 {
802 pv = MemReAlloc(pcd->prgDuplicates, cbDuplicates, FALSE);
787 - ExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to reallocate memory for duplicate file.");
803 + CabcExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to reallocate memory for duplicate file.");
804 }
805 else
806 {
807 pv = MemAlloc(cbDuplicates, FALSE);
792 - ExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to allocate memory for duplicate file.");
808 + CabcExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to allocate memory for duplicate file.");
809 }
810
811 ZeroMemory(reinterpret_cast<BYTE*>(pv) + (pcd->cDuplicates * sizeof(CABC_DUPLICATEFILE)), (pcd->cMaxDuplicates - pcd->cDuplicates) * sizeof(CABC_DUPLICATEFILE));
@@ -804,12 +820,12 @@ static HRESULT AddDuplicateFile(
820 pcd->prgFiles[dwFileArrayIndex].fHasDuplicates = TRUE; // Mark original file as having duplicates
821
822 hr = StrAllocString(&pcd->prgDuplicates[pcd->cDuplicates].pwzSourcePath, wzSourcePath, 0);
807 - ExitOnFailure(hr, "Failed to copy duplicate file path: %ls", wzSourcePath);
823 + CabcExitOnFailure(hr, "Failed to copy duplicate file path: %ls", wzSourcePath);
824
825 if (wzToken && *wzToken)
826 {
827 hr = StrAllocString(&pcd->prgDuplicates[pcd->cDuplicates].pwzToken, wzToken, 0);
812 - ExitOnFailure(hr, "Failed to copy duplicate file token: %ls", wzToken);
828 + CabcExitOnFailure(hr, "Failed to copy duplicate file token: %ls", wzToken);
829 }
830
831 ++pcd->cDuplicates;
@@ -839,10 +855,10 @@ static HRESULT AddNonDuplicateFile(
855 size_t cbFilePaths = 0;
856
857 hr = ::SizeTMult(pcd->cMaxFilePaths, sizeof(CABC_FILE), &cbFilePaths);
842 - ExitOnFailure(hr, "Maximum allocation exceeded.");
858 + CabcExitOnFailure(hr, "Maximum allocation exceeded.");
859
860 pv = MemReAlloc(pcd->prgFiles, cbFilePaths, FALSE);
845 - ExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to reallocate memory for file.");
861 + CabcExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to reallocate memory for file.");
862
863 ZeroMemory(reinterpret_cast<BYTE*>(pv) + (pcd->cFilePaths * sizeof(CABC_FILE)), (pcd->cMaxFilePaths - pcd->cFilePaths) * sizeof(CABC_FILE));
864
@@ -859,7 +875,7 @@ static HRESULT AddNonDuplicateFile(
875 if (pmfHash && sizeof(MSIFILEHASHINFO) == pmfHash->dwFileHashInfoSize)
876 {
877 pcf->pmfHash = (PMSIFILEHASHINFO)MemAlloc(sizeof(MSIFILEHASHINFO), FALSE);
862 - ExitOnNull(pcf->pmfHash, hr, E_OUTOFMEMORY, "Failed to allocate memory for individual file's MSI file hash");
878 + CabcExitOnNull(pcf->pmfHash, hr, E_OUTOFMEMORY, "Failed to allocate memory for individual file's MSI file hash");
879
880 pcf->pmfHash->dwFileHashInfoSize = sizeof(MSIFILEHASHINFO);
881 pcf->pmfHash->dwData[0] = pmfHash->dwData[0];
@@ -869,18 +885,18 @@ static HRESULT AddNonDuplicateFile(
885 }
886
887 hr = StrAllocString(&pcf->pwzSourcePath, wzFile, 0);
872 - ExitOnFailure(hr, "Failed to copy file path: %ls", wzFile);
888 + CabcExitOnFailure(hr, "Failed to copy file path: %ls", wzFile);
889
890 if (wzToken && *wzToken)
891 {
892 hr = StrAllocString(&pcf->pwzToken, wzToken, 0);
877 - ExitOnFailure(hr, "Failed to copy file token: %ls", wzToken);
893 + CabcExitOnFailure(hr, "Failed to copy file token: %ls", wzToken);
894 }
895
896 ++pcd->cFilePaths;
897
898 hr = DictAddValue(pcd->shDictHandle, pcf);
883 - ExitOnFailure(hr, "Failed to add file to dictionary of added files");
899 + CabcExitOnFailure(hr, "Failed to add file to dictionary of added files");
900
901 LExit:
902 ReleaseMem(pv);
@@ -903,14 +919,14 @@ static HRESULT UpdateDuplicateFiles(
919 hCabinet = ::CreateFileW(pcd->wzCabinetPath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
920 if (INVALID_HANDLE_VALUE == hCabinet)
921 {
906 - ExitWithLastError(hr, "Failed to open cabinet: %ls", pcd->wzCabinetPath);
922 + CabcExitWithLastError(hr, "Failed to open cabinet: %ls", pcd->wzCabinetPath);
923 }
924
925 // Shouldn't need more than 16 MB to get the whole cabinet header into memory so use that as
926 // the upper bound for the memory map.
927 if (!::GetFileSizeEx(hCabinet, &liCabinetSize))
928 {
913 - ExitWithLastError(hr, "Failed to get size of cabinet: %ls", pcd->wzCabinetPath);
929 + CabcExitWithLastError(hr, "Failed to get size of cabinet: %ls", pcd->wzCabinetPath);
930 }
931
932 if (0 == liCabinetSize.HighPart && liCabinetSize.LowPart < MAX_CABINET_HEADER_SIZE)
@@ -926,11 +942,11 @@ static HRESULT UpdateDuplicateFiles(
942 hCabinetMapping = ::CreateFileMappingW(hCabinet, NULL, PAGE_READWRITE | SEC_COMMIT, 0, cbCabinet, NULL);
943 if (NULL == hCabinetMapping || INVALID_HANDLE_VALUE == hCabinetMapping)
944 {
929 - ExitWithLastError(hr, "Failed to memory map cabinet file: %ls", pcd->wzCabinetPath);
945 + CabcExitWithLastError(hr, "Failed to memory map cabinet file: %ls", pcd->wzCabinetPath);
946 }
947
948 pv = ::MapViewOfFile(hCabinetMapping, FILE_MAP_WRITE, 0, 0, 0);
933 - ExitOnNullWithLastError(pv, hr, "Failed to map view of cabinet file: %ls", pcd->wzCabinetPath);
949 + CabcExitOnNullWithLastError(pv, hr, "Failed to map view of cabinet file: %ls", pcd->wzCabinetPath);
950
951 pCabinetHeader = static_cast<MS_CABINET_HEADER*>(pv);
952
@@ -939,7 +955,7 @@ static HRESULT UpdateDuplicateFiles(
955 const CABC_DUPLICATEFILE *pDuplicateFile = pcd->prgDuplicates + i;
956
957 hr = DuplicateFile(pCabinetHeader, pcd, pDuplicateFile);
942 - ExitOnFailure(hr, "Failed to find cabinet file items at index: %d and %d", pDuplicateFile->dwFileArrayIndex, pDuplicateFile->dwDuplicateCabFileIndex);
958 + CabcExitOnFailure(hr, "Failed to find cabinet file items at index: %d and %d", pDuplicateFile->dwFileArrayIndex, pDuplicateFile->dwDuplicateCabFileIndex);
959 }
960
961 LExit:
@@ -974,7 +990,7 @@ static HRESULT DuplicateFile(
990 pDuplicate->dwDuplicateCabFileIndex <= pcd->prgFiles[pDuplicate->dwFileArrayIndex].dwCabFileIndex)
991 {
992 hr = E_UNEXPECTED;
977 - ExitOnFailure(hr, "Unexpected duplicate file indices, header cFiles: %d, file index: %d, duplicate index: %d", pHeader->cFiles, pcd->prgFiles[pDuplicate->dwFileArrayIndex].dwCabFileIndex, pDuplicate->dwDuplicateCabFileIndex);
993 + CabcExitOnFailure(hr, "Unexpected duplicate file indices, header cFiles: %d, file index: %d, duplicate index: %d", pHeader->cFiles, pcd->prgFiles[pDuplicate->dwFileArrayIndex].dwCabFileIndex, pDuplicate->dwDuplicateCabFileIndex);
994 }
995
996 // Step through each cabinet items until we get to the original
@@ -1002,7 +1018,7 @@ static HRESULT DuplicateFile(
1018 if (0 != pDuplicateItem->cbFile)
1019 {
1020 hr = E_UNEXPECTED;
1005 - ExitOnFailure(hr, "Failed because duplicate file does not have a file size of zero: %d", pDuplicateItem->cbFile);
1021 + CabcExitOnFailure(hr, "Failed because duplicate file does not have a file size of zero: %d", pDuplicateItem->cbFile);
1022 }
1023
1024 pDuplicateItem->cbFile = pOriginalItem->cbFile;
@@ -1031,12 +1047,12 @@ static HRESULT UtcFileTimeToLocalDosDateTime(
1047
1048 if (!::FileTimeToLocalFileTime(pFileTime, &ftLocal))
1049 {
1034 - ExitWithLastError(hr, "Filed to convert file time to local file time.");
1050 + CabcExitWithLastError(hr, "Filed to convert file time to local file time.");
1051 }
1052
1053 if (!::FileTimeToDosDateTime(&ftLocal, pDate, pTime))
1054 {
1039 - ExitWithLastError(hr, "Filed to convert file time to DOS date time.");
1055 + CabcExitWithLastError(hr, "Filed to convert file time to DOS date time.");
1056 }
1057
1058 LExit:
@@ -1053,7 +1069,7 @@ static __callback int DIAMONDAPI CabCFilePlaced(
1069 __in_z PSTR szFile,
1070 __in long cbFile,
1071 __in BOOL fContinuation,
1056 - __out_bcount(CABC_HANDLE_BYTES) void *pv
1072 + __inout_bcount(CABC_HANDLE_BYTES) void *pv
1073 )
1074 {
1075 UNREFERENCED_PARAMETER(pccab);
@@ -1085,7 +1101,7 @@ static __callback INT_PTR DIAMONDAPI CabCOpen(
1101 __in int oflag,
1102 __in int pmode,
1103 __out int *err,
1088 - __out_bcount(CABC_HANDLE_BYTES) void *pv
1104 + __inout_bcount(CABC_HANDLE_BYTES) void *pv
1105 )
1106 {
1107 CABC_DATA *pcd = reinterpret_cast<CABC_DATA*>(pv);
@@ -1139,7 +1155,7 @@ static __callback INT_PTR DIAMONDAPI CabCOpen(
1155
1156 if (INVALID_HANDLE_VALUE == reinterpret_cast<HANDLE>(pFile))
1157 {
1142 - ExitOnLastError(hr, "failed to open file: %s", pszFile);
1158 + CabcExitOnLastError(hr, "failed to open file: %s", pszFile);
1159 }
1160
1161 LExit:
@@ -1155,18 +1171,18 @@ static __callback UINT FAR DIAMONDAPI CabCRead(
1171 __out_bcount(cb) void FAR *memory,
1172 __in UINT cb,
1173 __out int *err,
1158 - __out_bcount(CABC_HANDLE_BYTES) void *pv
1174 + __inout_bcount(CABC_HANDLE_BYTES) void *pv
1175 )
1176 {
1177 CABC_DATA *pcd = reinterpret_cast<CABC_DATA*>(pv);
1178 HRESULT hr = S_OK;
1179 DWORD cbRead = 0;
1180
1165 - ExitOnNull(hf, *err, E_INVALIDARG, "Failed to read during cabinet extraction because no file handle was provided");
1181 + CabcExitOnNull(hf, *err, E_INVALIDARG, "Failed to read during cabinet extraction because no file handle was provided");
1182 if (!::ReadFile(reinterpret_cast<HANDLE>(hf), memory, cb, &cbRead, NULL))
1183 {
1184 *err = ::GetLastError();
1169 - ExitOnLastError(hr, "failed to read during cabinet extraction");
1185 + CabcExitOnLastError(hr, "failed to read during cabinet extraction");
1186 }
1187
1188 LExit:
@@ -1184,18 +1200,18 @@ static __callback UINT FAR DIAMONDAPI CabCWrite(
1200 __in_bcount(cb) void FAR *memory,
1201 __in UINT cb,
1202 __out int *err,
1187 - __out_bcount(CABC_HANDLE_BYTES) void *pv
1203 + __inout_bcount(CABC_HANDLE_BYTES) void *pv
1204 )
1205 {
1206 CABC_DATA *pcd = reinterpret_cast<CABC_DATA*>(pv);
1207 HRESULT hr = S_OK;
1208 DWORD cbWrite = 0;
1209
1194 - ExitOnNull(hf, *err, E_INVALIDARG, "Failed to write during cabinet extraction because no file handle was provided");
1210 + CabcExitOnNull(hf, *err, E_INVALIDARG, "Failed to write during cabinet extraction because no file handle was provided");
1211 if (!::WriteFile(reinterpret_cast<HANDLE>(hf), memory, cb, &cbWrite, NULL))
1212 {
1213 *err = ::GetLastError();
1198 - ExitOnLastError(hr, "failed to write during cabinet extraction");
1214 + CabcExitOnLastError(hr, "failed to write during cabinet extraction");
1215 }
1216
1217 LExit:
@@ -1211,7 +1227,7 @@ static __callback long FAR DIAMONDAPI CabCSeek(
1227 __in long dist,
1228 __in int seektype,
1229 __out int *err,
1214 - __out_bcount(CABC_HANDLE_BYTES) void *pv
1230 + __inout_bcount(CABC_HANDLE_BYTES) void *pv
1231 )
1232 {
1233 CABC_DATA *pcd = reinterpret_cast<CABC_DATA*>(pv);
@@ -1233,7 +1249,7 @@ static __callback long FAR DIAMONDAPI CabCSeek(
1249 default :
1250 dwMoveMethod = 0;
1251 hr = E_UNEXPECTED;
1236 - ExitOnFailure(hr, "unexpected seektype in FCISeek(): %d", seektype);
1252 + CabcExitOnFailure(hr, "unexpected seektype in FCISeek(): %d", seektype);
1253 }
1254
1255 // SetFilePointer returns -1 if it fails (this will cause FDI to quit with an FDIERROR_USER_ABORT error.
@@ -1243,7 +1259,7 @@ static __callback long FAR DIAMONDAPI CabCSeek(
1259 if (DWORD_MAX == lMove)
1260 {
1261 *err = ::GetLastError();
1246 - ExitOnLastError(hr, "failed to move file pointer %d bytes", dist);
1262 + CabcExitOnLastError(hr, "failed to move file pointer %d bytes", dist);
1263 }
1264
1265 LExit:
@@ -1259,7 +1275,7 @@ LExit:
1275 static __callback int FAR DIAMONDAPI CabCClose(
1276 __in INT_PTR hf,
1277 __out int *err,
1262 - __out_bcount(CABC_HANDLE_BYTES) void *pv
1278 + __inout_bcount(CABC_HANDLE_BYTES) void *pv
1279 )
1280 {
1281 CABC_DATA *pcd = reinterpret_cast<CABC_DATA*>(pv);
@@ -1268,7 +1284,7 @@ static __callback int FAR DIAMONDAPI CabCClose(
1284 if (!::CloseHandle(reinterpret_cast<HANDLE>(hf)))
1285 {
1286 *err = ::GetLastError();
1271 - ExitOnLastError(hr, "failed to close file during cabinet extraction");
1287 + CabcExitOnLastError(hr, "failed to close file during cabinet extraction");
1288 }
1289
1290 LExit:
@@ -1283,7 +1299,7 @@ LExit:
1299 static __callback int DIAMONDAPI CabCDelete(
1300 __in_z PSTR szFile,
1301 __out int *err,
1286 - __out_bcount(CABC_HANDLE_BYTES) void *pv
1302 + __inout_bcount(CABC_HANDLE_BYTES) void *pv
1303 )
1304 {
1305 UNREFERENCED_PARAMETER(err);
@@ -1302,7 +1318,7 @@ __success(return != FALSE)
1318 static __callback BOOL DIAMONDAPI CabCGetTempFile(
1319 __out_bcount_z(cbFile) char *szFile,
1320 __in int cbFile,
1305 - __out_bcount(CABC_HANDLE_BYTES) void *pv
1321 + __inout_bcount(CABC_HANDLE_BYTES) void *pv
1322 )
1323 {
1324 CABC_DATA *pcd = reinterpret_cast<CABC_DATA*>(pv);
@@ -1316,7 +1332,7 @@ static __callback BOOL DIAMONDAPI CabCGetTempFile(
1332
1333 if (MAX_PATH < ::GetTempPathA(cchTempPath, szTempPath))
1334 {
1319 - ExitWithLastError(hr, "Failed to get temp path during cabinet creation.");
1335 + CabcExitWithLastError(hr, "Failed to get temp path during cabinet creation.");
1336 }
1337
1338 for (DWORD i = 0; i < DWORD_MAX; ++i)
@@ -1324,7 +1340,7 @@ static __callback BOOL DIAMONDAPI CabCGetTempFile(
1340 LONG dwTempIndex = ::InterlockedIncrement(reinterpret_cast<volatile LONG*>(&dwIndex));
1341
1342 hr = ::StringCbPrintfA(szFile, cbFile, "%s\\%08x.%03x", szTempPath, dwTempIndex, dwProcessId);
1327 - ExitOnFailure(hr, "failed to format log file path.");
1343 + CabcExitOnFailure(hr, "failed to format log file path.");
1344
1345 hTempFile = ::CreateFileA(szFile, 0, FILE_SHARE_DELETE, NULL, CREATE_NEW, FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE, NULL);
1346 if (INVALID_HANDLE_VALUE != hTempFile)
@@ -1338,7 +1354,7 @@ static __callback BOOL DIAMONDAPI CabCGetTempFile(
1354 hr = E_FAIL; // this file was taken so be pessimistic and assume we're not going to find one.
1355 }
1356 }
1341 - ExitOnFailure(hr, "failed to find temporary file.");
1357 + CabcExitOnFailure(hr, "failed to find temporary file.");
1358
1359 LExit:
1360 ReleaseFileHandle(hTempFile);
@@ -1377,7 +1393,7 @@ static __callback BOOL DIAMONDAPI CabCGetNextCabinet(
1393 len -= 4; // remove Extention ".cab" of 8.3 Format
1394 }
1395 hr = ::StringCchCatNW(pcd->wzFirstCabinetName, countof(pcd->wzFirstCabinetName), pwzCabinetName, len);
1380 - ExitOnFailure(hr, "Failed to remove extension to create next Cabinet File Name");
1396 + CabcExitOnFailure(hr, "Failed to remove extension to create next Cabinet File Name");
1397 }
1398
1399 const int nAlphabets = 26; // Number of Alphabets from a to z
@@ -1385,9 +1401,9 @@ static __callback BOOL DIAMONDAPI CabCGetNextCabinet(
1401 {
1402 // Construct next cab names like cab1a.cab, cab1b.cab, cab1c.cab, ........
1403 hr = ::StringCchPrintfA(pccab->szCab, sizeof(pccab->szCab), "%ls%c.cab", pcd->wzFirstCabinetName, char(((int)('a') - 1) + pccab->iCab));
1388 - ExitOnFailure(hr, "Failed to create next Cabinet File Name");
1404 + CabcExitOnFailure(hr, "Failed to create next Cabinet File Name");
1405 hr = ::StringCchPrintfW(wzNewCabName, countof(wzNewCabName), L"%ls%c.cab", pcd->wzFirstCabinetName, WCHAR(((int)('a') - 1) + pccab->iCab));
1390 - ExitOnFailure(hr, "Failed to create next Cabinet File Name");
1406 + CabcExitOnFailure(hr, "Failed to create next Cabinet File Name");
1407 }
1408 else if (pccab->iCab <= nAlphabets*nAlphabets)
1409 {
@@ -1401,14 +1417,14 @@ static __callback BOOL DIAMONDAPI CabCGetNextCabinet(
1417 char1--; // First Char must be decremented by 1
1418 }
1419 hr = ::StringCchPrintfA(pccab->szCab, sizeof(pccab->szCab), "%ls%c%c.cab", pcd->wzFirstCabinetName, char(((int)('a') - 1) + char1), char(((int)('a') - 1) + char2));
1404 - ExitOnFailure(hr, "Failed to create next Cabinet File Name");
1420 + CabcExitOnFailure(hr, "Failed to create next Cabinet File Name");
1421 hr = ::StringCchPrintfW(wzNewCabName, countof(wzNewCabName), L"%ls%c%c.cab", pcd->wzFirstCabinetName, WCHAR(((int)('a') - 1) + char1), WCHAR(((int)('a') - 1) + char2));
1406 - ExitOnFailure(hr, "Failed to create next Cabinet File Name");
1422 + CabcExitOnFailure(hr, "Failed to create next Cabinet File Name");
1423 }
1424 else
1425 {
1426 hr = DISP_E_BADINDEX; // Value 0x8002000B stands for Invalid index.
1411 - ExitOnFailure(hr, "Cannot Split Cabinet more than 26*26 = 676 times. Failed to create next Cabinet File Name");
1427 + CabcExitOnFailure(hr, "Cannot Split Cabinet more than 26*26 = 676 times. Failed to create next Cabinet File Name");
1428 }
1429
1430 // Callback from PFNFCIGETNEXTCABINET CabCGetNextCabinet method
@@ -1478,7 +1494,7 @@ static __callback INT_PTR DIAMONDAPI CabCGetOpenInfo(
1494
1495 if (!::GetFileAttributesExW(pFileInfo->wzSourcePath, GetFileExInfoStandard, &fad))
1496 {
1481 - ExitWithLastError(hr, "Failed to get file attributes on '%s'.", pFileInfo->wzSourcePath);
1497 + CabcExitWithLastError(hr, "Failed to get file attributes on '%ls'.", pFileInfo->wzSourcePath);
1498 }
1499
1500 // Set the attributes but only allow the few attributes that CAB supports.
@@ -1492,7 +1508,7 @@ static __callback INT_PTR DIAMONDAPI CabCGetOpenInfo(
1508 // found. This would create further problems if the file was written to the CAB without this value. Windows
1509 // Installer would then fail to extract the file.
1510 hr = UtcFileTimeToLocalDosDateTime(&fad.ftCreationTime, pdate, ptime);
1495 - ExitOnFailure(hr, "Filed to read a valid file time stucture on file '%s'.", pszName);
1511 + CabcExitOnFailure(hr, "Filed to read a valid file time stucture on file '%s'.", pszName);
1512 }
1513
1514 iResult = CabCOpen(pszFilePlusMagic, _O_BINARY|_O_RDONLY, 0, err, pv);
@@ -1512,7 +1528,7 @@ static __callback long DIAMONDAPI CabCStatus(
1528 __in UINT ui,
1529 __in ULONG cb1,
1530 __in ULONG cb2,
1515 - __out_bcount(CABC_HANDLE_BYTES) void *pv
1531 + __inout_bcount(CABC_HANDLE_BYTES) void *pv
1532 )
1533 {
1534 UNREFERENCED_PARAMETER(ui);
src/dutil/cabutil.cpp
+56 -40
@@ -2,6 +2,22 @@
2
3 #include "precomp.h"
4
5 +
6 +// Exit macros
7 +#define CabExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_CABUTIL, x, s, __VA_ARGS__)
8 +#define CabExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_CABUTIL, x, s, __VA_ARGS__)
9 +#define CabExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_CABUTIL, x, s, __VA_ARGS__)
10 +#define CabExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_CABUTIL, x, s, __VA_ARGS__)
11 +#define CabExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_CABUTIL, x, s, __VA_ARGS__)
12 +#define CabExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_CABUTIL, x, s, __VA_ARGS__)
13 +#define CabExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_CABUTIL, p, x, e, s, __VA_ARGS__)
14 +#define CabExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_CABUTIL, p, x, s, __VA_ARGS__)
15 +#define CabExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_CABUTIL, p, x, e, s, __VA_ARGS__)
16 +#define CabExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_CABUTIL, p, x, s, __VA_ARGS__)
17 +#define CabExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_CABUTIL, e, x, s, __VA_ARGS__)
18 +#define CabExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_CABUTIL, g, x, s, __VA_ARGS__)
19 +
20 +
21 // external prototypes
22 typedef BOOL (FAR DIAMONDAPI *PFNFDIDESTROY)(VOID*);
23 typedef HFDI (FAR DIAMONDAPI *PFNFDICREATE)(PFNALLOC, PFNFREE, PFNOPEN, PFNREAD, PFNWRITE, PFNCLOSE, PFNSEEK, int, PERF);
@@ -59,20 +75,20 @@ inline HRESULT LoadCabinetDll()
75 if (!vhCabinetDll)
76 {
77 hr = LoadSystemLibrary(L"cabinet.dll", &vhCabinetDll);
62 - ExitOnFailure(hr, "failed to load cabinet.dll");
78 + CabExitOnFailure(hr, "failed to load cabinet.dll");
79
80 // retrieve all address functions
81 vpfnFDICreate = reinterpret_cast<PFNFDICREATE>(::GetProcAddress(vhCabinetDll, "FDICreate"));
66 - ExitOnNullWithLastError(vpfnFDICreate, hr, "failed to import FDICreate from CABINET.DLL");
82 + CabExitOnNullWithLastError(vpfnFDICreate, hr, "failed to import FDICreate from CABINET.DLL");
83 vpfnFDICopy = reinterpret_cast<PFNFDICOPY>(::GetProcAddress(vhCabinetDll, "FDICopy"));
68 - ExitOnNullWithLastError(vpfnFDICopy, hr, "failed to import FDICopy from CABINET.DLL");
84 + CabExitOnNullWithLastError(vpfnFDICopy, hr, "failed to import FDICopy from CABINET.DLL");
85 vpfnFDIIsCabinet = reinterpret_cast<PFNFDIISCABINET>(::GetProcAddress(vhCabinetDll, "FDIIsCabinet"));
70 - ExitOnNullWithLastError(vpfnFDIIsCabinet, hr, "failed to import FDIIsCabinetfrom CABINET.DLL");
86 + CabExitOnNullWithLastError(vpfnFDIIsCabinet, hr, "failed to import FDIIsCabinetfrom CABINET.DLL");
87 vpfnFDIDestroy = reinterpret_cast<PFNFDIDESTROY>(::GetProcAddress(vhCabinetDll, "FDIDestroy"));
72 - ExitOnNullWithLastError(vpfnFDIDestroy, hr, "failed to import FDIDestroyfrom CABINET.DLL");
88 + CabExitOnNullWithLastError(vpfnFDIDestroy, hr, "failed to import FDIDestroyfrom CABINET.DLL");
89
90 vhfdi = vpfnFDICreate(CabExtractAlloc, CabExtractFree, CabExtractOpen, CabExtractRead, CabExtractWrite, CabExtractClose, CabExtractSeek, cpuUNKNOWN, &verf);
75 - ExitOnNull(vhfdi, hr, E_FAIL, "failed to initialize cabinet.dll");
91 + CabExitOnNull(vhfdi, hr, E_FAIL, "failed to initialize cabinet.dll");
92 }
93
94 LExit:
@@ -99,7 +115,7 @@ extern "C" HRESULT DAPI CabInitialize(
115 if (!fDelayLoad)
116 {
117 hr = LoadCabinetDll();
102 - ExitOnFailure(hr, "failed to load CABINET.DLL");
118 + CabExitOnFailure(hr, "failed to load CABINET.DLL");
119 }
120
121 LExit:
@@ -143,8 +159,8 @@ extern "C" void DAPI CabUninitialize(
159 in the cabinet
160 ********************************************************************/
161 extern "C" HRESULT DAPI CabEnumerate(
146 - __in LPCWSTR wzCabinet,
147 - __in LPCWSTR wzEnumerateFile,
162 + __in_z LPCWSTR wzCabinet,
163 + __in_z LPCWSTR wzEnumerateFile,
164 __in STDCALL_PFNFDINOTIFY pfnNotify,
165 __in DWORD64 dw64EmbeddedOffset
166 )
@@ -161,9 +177,9 @@ extern "C" HRESULT DAPI CabEnumerate(
177 if pfnBeginFile is NULL pfnEndFile must be NULL and vice versa
178 ********************************************************************/
179 extern "C" HRESULT DAPI CabExtract(
164 - __in LPCWSTR wzCabinet,
165 - __in LPCWSTR wzExtractFile,
166 - __in LPCWSTR wzExtractDir,
180 + __in_z LPCWSTR wzCabinet,
181 + __in_z LPCWSTR wzExtractFile,
182 + __in_z LPCWSTR wzExtractDir,
183 __in_opt CAB_CALLBACK_PROGRESS pfnProgress,
184 __in_opt LPVOID pvContext,
185 __in DWORD64 dw64EmbeddedOffset
@@ -238,21 +254,21 @@ static HRESULT DAPI CabOperation(
254 if (!vhfdi)
255 {
256 hr = LoadCabinetDll();
241 - ExitOnFailure(hr, "failed to load CABINET.DLL");
257 + CabExitOnFailure(hr, "failed to load CABINET.DLL");
258 }
259
260 hr = StrAllocString(&sczCabinet, wzCabinet, 0);
245 - ExitOnFailure(hr, "Failed to make copy of cabinet name:%ls", wzCabinet);
261 + CabExitOnFailure(hr, "Failed to make copy of cabinet name:%ls", wzCabinet);
262
263 //
264 // split the cabinet full path into directory and filename and convert to multi-byte (ick!)
265 //
266 pwz = FileFromPath(sczCabinet);
251 - ExitOnNull(pwz, hr, E_INVALIDARG, "failed to process cabinet path: %ls", wzCabinet);
267 + CabExitOnNull(pwz, hr, E_INVALIDARG, "failed to process cabinet path: %ls", wzCabinet);
268
269 if (!::WideCharToMultiByte(CP_UTF8, 0, pwz, -1, szCabFile, countof(szCabFile), NULL, NULL))
270 {
255 - ExitWithLastError(hr, "failed to convert cabinet filename to ASCII: %ls", pwz);
271 + CabExitWithLastError(hr, "failed to convert cabinet filename to ASCII: %ls", pwz);
272 }
273
274 *pwz = '\0';
@@ -261,13 +277,13 @@ static HRESULT DAPI CabOperation(
277 if (wzCabinet == pwz)
278 {
279 hr = ::StringCchCopyA(szCabDirectory, countof(szCabDirectory), ".\\");
264 - ExitOnFailure(hr, "Failed to copy relative current directory as cabinet directory.");
280 + CabExitOnFailure(hr, "Failed to copy relative current directory as cabinet directory.");
281 }
282 else
283 {
284 if (!::WideCharToMultiByte(CP_UTF8, 0, sczCabinet, -1, szCabDirectory, countof(szCabDirectory), NULL, NULL))
285 {
270 - ExitWithLastError(hr, "failed to convert cabinet directory to ASCII: %ls", sczCabinet);
286 + CabExitWithLastError(hr, "failed to convert cabinet directory to ASCII: %ls", sczCabinet);
287 }
288 }
289
@@ -295,7 +311,7 @@ static HRESULT DAPI CabOperation(
311 fResult = vpfnFDICopy(vhfdi, szCabFile, szCabDirectory, 0, pfnFdiNotify, NULL, static_cast<void*>(&ccs));
312 if (!fResult && !ccs.fStopExtracting) // if something went wrong and it wasn't us just stopping the extraction, then return a failure
313 {
298 - ExitWithLastError(hr, "failed to extract cabinet file: %ls", sczCabinet);
314 + CabExitWithLastError(hr, "failed to extract cabinet file: %ls", sczCabinet);
315 }
316
317 LExit:
@@ -331,22 +347,22 @@ static __callback INT_PTR FAR DIAMONDAPI CabExtractOpen(__in_z PSTR pszFile, __i
347 if ((oflag != (/*_O_BINARY*/ 0x8000 | /*_O_RDONLY*/ 0x0000)) || (pmode != (_S_IREAD | _S_IWRITE)))
348 {
349 hr = E_OUTOFMEMORY;
334 - ExitOnFailure(hr, "FDI asked for a scratch file to be created, which is unsupported");
350 + CabExitOnFailure(hr, "FDI asked for a scratch file to be created, which is unsupported");
351 }
352
353 hr = StrAllocStringAnsi(&sczCabFile, pszFile, 0, CP_UTF8);
338 - ExitOnFailure(hr, "Failed to convert UTF8 cab file name to wide character string");
354 + CabExitOnFailure(hr, "Failed to convert UTF8 cab file name to wide character string");
355
356 pFile = reinterpret_cast<INT_PTR>(::CreateFileW(sczCabFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL));
357 if (INVALID_HANDLE_VALUE == reinterpret_cast<HANDLE>(pFile))
358 {
343 - ExitWithLastError(hr, "failed to open file: %ls", sczCabFile);
359 + CabExitWithLastError(hr, "failed to open file: %ls", sczCabFile);
360 }
361
362 if (vdw64EmbeddedOffset)
363 {
364 hr = CabExtractSeek(pFile, 0, 0);
349 - ExitOnFailure(hr, "Failed to seek to embedded offset %I64d", vdw64EmbeddedOffset);
365 + CabExitOnFailure(hr, "Failed to seek to embedded offset %I64d", vdw64EmbeddedOffset);
366 }
367
368 LExit:
@@ -361,10 +377,10 @@ static __callback UINT FAR DIAMONDAPI CabExtractRead(__in INT_PTR hf, __out void
377 HRESULT hr = S_OK;
378 DWORD cbRead = 0;
379
364 - ExitOnNull(hf, hr, E_INVALIDARG, "Failed to read file during cabinet extraction - no file given to read");
380 + CabExitOnNull(hf, hr, E_INVALIDARG, "Failed to read file during cabinet extraction - no file given to read");
381 if (!::ReadFile(reinterpret_cast<HANDLE>(hf), pv, cb, &cbRead, NULL))
382 {
367 - ExitWithLastError(hr, "failed to read during cabinet extraction");
383 + CabExitWithLastError(hr, "failed to read during cabinet extraction");
384 }
385
386 LExit:
@@ -377,10 +393,10 @@ static __callback UINT FAR DIAMONDAPI CabExtractWrite(__in INT_PTR hf, __in void
393 HRESULT hr = S_OK;
394 DWORD cbWrite = 0;
395
380 - ExitOnNull(hf, hr, E_INVALIDARG, "Failed to write file during cabinet extraction - no file given to write");
396 + CabExitOnNull(hf, hr, E_INVALIDARG, "Failed to write file during cabinet extraction - no file given to write");
397 if (!::WriteFile(reinterpret_cast<HANDLE>(hf), pv, cb, &cbWrite, NULL))
398 {
383 - ExitWithLastError(hr, "failed to write during cabinet extraction");
399 + CabExitWithLastError(hr, "failed to write during cabinet extraction");
400 }
401
402 LExit:
@@ -409,7 +425,7 @@ static __callback long FAR DIAMONDAPI CabExtractSeek(__in INT_PTR hf, __in long
425 default :
426 dwMoveMethod = 0;
427 hr = E_UNEXPECTED;
412 - ExitOnFailure(hr, "unexpected seektype in FDISeek(): %d", seektype);
428 + CabExitOnFailure(hr, "unexpected seektype in FDISeek(): %d", seektype);
429 }
430
431 // SetFilePointer returns -1 if it fails (this will cause FDI to quit with an FDIERROR_USER_ABORT error.
@@ -417,7 +433,7 @@ static __callback long FAR DIAMONDAPI CabExtractSeek(__in INT_PTR hf, __in long
433 lMove = ::SetFilePointer(reinterpret_cast<HANDLE>(hf), dist, NULL, dwMoveMethod);
434 if (0xFFFFFFFF == lMove)
435 {
420 - ExitWithLastError(hr, "failed to move file pointer %d bytes", dist);
436 + CabExitWithLastError(hr, "failed to move file pointer %d bytes", dist);
437 }
438
439 LExit:
@@ -431,7 +447,7 @@ static __callback int FAR DIAMONDAPI CabExtractClose(__in INT_PTR hf)
447
448 if (!::CloseHandle(reinterpret_cast<HANDLE>(hf)))
449 {
434 - ExitWithLastError(hr, "failed to close file during cabinet extraction");
450 + CabExitWithLastError(hr, "failed to close file during cabinet extraction");
451 }
452
453 LExit:
@@ -454,8 +470,8 @@ static __callback INT_PTR DIAMONDAPI CabExtractCallback(__in FDINOTIFICATIONTYPE
470 switch (iNotification)
471 {
472 case fdintCOPY_FILE: // begin extracting a resource from cabinet
457 - ExitOnNull(pFDINotify->psz1, hr, E_INVALIDARG, "No cabinet file ID given to convert");
458 - ExitOnNull(pccs, hr, E_INVALIDARG, "Failed to call cabextract callback, because no callback struct was provided");
473 + CabExitOnNull(pFDINotify->psz1, hr, E_INVALIDARG, "No cabinet file ID given to convert");
474 + CabExitOnNull(pccs, hr, E_INVALIDARG, "Failed to call cabextract callback, because no callback struct was provided");
475
476 if (pccs->fStopExtracting)
477 {
@@ -466,7 +482,7 @@ static __callback INT_PTR DIAMONDAPI CabExtractCallback(__in FDINOTIFICATIONTYPE
482 sz = static_cast<LPCSTR>(pFDINotify->psz1);
483 if (!::MultiByteToWideChar(CP_ACP, 0, sz, -1, wz, countof(wz)))
484 {
469 - ExitWithLastError(hr, "failed to convert cabinet file id to unicode: %s", sz);
485 + CabExitWithLastError(hr, "failed to convert cabinet file id to unicode: %s", sz);
486 }
487
488 if (pccs->pfnProgress)
@@ -484,21 +500,21 @@ static __callback INT_PTR DIAMONDAPI CabExtractCallback(__in FDINOTIFICATIONTYPE
500 FILETIME ftLocal;
501 if (!::DosDateTimeToFileTime(pFDINotify->date, pFDINotify->time, &ftLocal))
502 {
487 - ExitWithLastError(hr, "failed to get time for resource: %ls", wz);
503 + CabExitWithLastError(hr, "failed to get time for resource: %ls", wz);
504 }
505 ::LocalFileTimeToFileTime(&ftLocal, &ft);
506
507
508 WCHAR wzPath[MAX_PATH];
509 hr = ::StringCchCopyW(wzPath, countof(wzPath), pccs->pwzExtractDir);
494 - ExitOnFailure(hr, "failed to copy in extract directory: %ls for file: %ls", pccs->pwzExtractDir, wz);
510 + CabExitOnFailure(hr, "failed to copy in extract directory: %ls for file: %ls", pccs->pwzExtractDir, wz);
511 hr = ::StringCchCatW(wzPath, countof(wzPath), wz);
496 - ExitOnFailure(hr, "failed to concat onto path: %ls file: %ls", wzPath, wz);
512 + CabExitOnFailure(hr, "failed to concat onto path: %ls file: %ls", wzPath, wz);
513
514 ipResult = reinterpret_cast<INT_PTR>(::CreateFileW(wzPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL));
515 if (INVALID_HANDLE_VALUE == reinterpret_cast<HANDLE>(ipResult))
516 {
501 - ExitWithLastError(hr, "failed to create file: %s", wzPath);
517 + CabExitWithLastError(hr, "failed to create file: %ls", wzPath);
518 }
519
520 ::SetFileTime(reinterpret_cast<HANDLE>(ipResult), &ft, &ft, &ft); // try to set the file time (who cares if it fails)
@@ -520,15 +536,15 @@ static __callback INT_PTR DIAMONDAPI CabExtractCallback(__in FDINOTIFICATIONTYPE
536 break;
537 case fdintCLOSE_FILE_INFO: // resource extraction complete
538 Assert(pFDINotify->hf && pFDINotify->psz1);
523 - ExitOnNull(pccs, hr, E_INVALIDARG, "Failed to call cabextract callback, because no callback struct was provided");
539 + CabExitOnNull(pccs, hr, E_INVALIDARG, "Failed to call cabextract callback, because no callback struct was provided");
540
541 // convert params to useful variables
542 sz = static_cast<LPCSTR>(pFDINotify->psz1);
527 - ExitOnNull(sz, hr, E_INVALIDARG, "Failed to convert cabinet file id, because no cabinet file id was provided");
543 + CabExitOnNull(sz, hr, E_INVALIDARG, "Failed to convert cabinet file id, because no cabinet file id was provided");
544
545 if (!::MultiByteToWideChar(CP_ACP, 0, sz, -1, wz, countof(wz)))
546 {
531 - ExitWithLastError(hr, "failed to convert cabinet file id to unicode: %s", sz);
547 + CabExitWithLastError(hr, "failed to convert cabinet file id to unicode: %s", sz);
548 }
549
550 if (NULL != pFDINotify->hf) // just close the file
src/dutil/certutil.cpp
+37 -22
@@ -2,6 +2,21 @@
2
3 #include "precomp.h"
4
5 +
6 +// Exit macros
7 +#define CertExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_CERTUTIL, x, s, __VA_ARGS__)
8 +#define CertExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_CERTUTIL, x, s, __VA_ARGS__)
9 +#define CertExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_CERTUTIL, x, s, __VA_ARGS__)
10 +#define CertExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_CERTUTIL, x, s, __VA_ARGS__)
11 +#define CertExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_CERTUTIL, x, s, __VA_ARGS__)
12 +#define CertExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_CERTUTIL, x, s, __VA_ARGS__)
13 +#define CertExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_CERTUTIL, p, x, e, s, __VA_ARGS__)
14 +#define CertExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_CERTUTIL, p, x, s, __VA_ARGS__)
15 +#define CertExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_CERTUTIL, p, x, e, s, __VA_ARGS__)
16 +#define CertExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_CERTUTIL, p, x, s, __VA_ARGS__)
17 +#define CertExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_CERTUTIL, e, x, s, __VA_ARGS__)
18 +#define CertExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_CERTUTIL, g, x, s, __VA_ARGS__)
19 +
20 /********************************************************************
21 CertReadProperty - reads a property from the certificate.
22
@@ -20,15 +35,15 @@ extern "C" HRESULT DAPI CertReadProperty(
35
36 if (!::CertGetCertificateContextProperty(pCertContext, dwProperty, NULL, &cb))
37 {
23 - ExitWithLastError(hr, "Failed to get size of certificate property.");
38 + CertExitWithLastError(hr, "Failed to get size of certificate property.");
39 }
40
41 pv = MemAlloc(cb, TRUE);
27 - ExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to allocate memory for certificate property.");
42 + CertExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to allocate memory for certificate property.");
43
44 if (!::CertGetCertificateContextProperty(pCertContext, dwProperty, pv, &cb))
45 {
31 - ExitWithLastError(hr, "Failed to get certificate property.");
46 + CertExitWithLastError(hr, "Failed to get certificate property.");
47 }
48
49 *ppvValue = pv;
@@ -70,11 +85,11 @@ extern "C" HRESULT DAPI CertGetAuthenticodeSigningTimestamp(
85 if (!pBlob)
86 {
87 hr = TRUST_E_FAIL;
73 - ExitOnFailure(hr, "Failed to find countersigner in signer information.");
88 + CertExitOnFailure(hr, "Failed to find countersigner in signer information.");
89 }
90
91 hr = CrypDecodeObject(PKCS7_SIGNER_INFO, pBlob->pbData, pBlob->cbData, 0, reinterpret_cast<LPVOID*>(&pCounterSignerInfo), NULL);
77 - ExitOnFailure(hr, "Failed to decode countersigner information.");
92 + CertExitOnFailure(hr, "Failed to decode countersigner information.");
93
94 pBlob = NULL; // reset the blob before searching for the signing time.
95
@@ -91,12 +106,12 @@ extern "C" HRESULT DAPI CertGetAuthenticodeSigningTimestamp(
106 if (!pBlob)
107 {
108 hr = TRUST_E_FAIL;
94 - ExitOnFailure(hr, "Failed to find signing time in countersigner information.");
109 + CertExitOnFailure(hr, "Failed to find signing time in countersigner information.");
110 }
111
112 if (!::CryptDecodeObject(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, szOID_RSA_signingTime, pBlob->pbData, pBlob->cbData, 0, pftSigningTimestamp, &cbSigningTimestamp))
113 {
99 - ExitWithLastError(hr, "Failed to decode countersigner signing timestamp.");
114 + CertExitWithLastError(hr, "Failed to decode countersigner signing timestamp.");
115 }
116
117 LExit:
@@ -124,10 +139,10 @@ extern "C" HRESULT DAPI GetCryptProvFromCert(
139 GETCRYPTPROVFROMCERTPTR pGetCryptProvFromCert = NULL;
140
141 hr = LoadSystemLibrary(L"MsSign32.dll", &hMsSign32);
127 - ExitOnFailure(hr, "Failed to get handle to MsSign32.dll");
142 + CertExitOnFailure(hr, "Failed to get handle to MsSign32.dll");
143
144 pGetCryptProvFromCert = (GETCRYPTPROVFROMCERTPTR)::GetProcAddress(hMsSign32, "GetCryptProvFromCert");
130 - ExitOnNullWithLastError(hMsSign32, hr, "Failed to get handle to MsSign32.dll");
145 + CertExitOnNullWithLastError(hMsSign32, hr, "Failed to get handle to MsSign32.dll");
146
147 if (!pGetCryptProvFromCert(hwnd,
148 pCert,
@@ -138,7 +153,7 @@ extern "C" HRESULT DAPI GetCryptProvFromCert(
153 ppwszProviderName,
154 pdwProviderType))
155 {
141 - ExitWithLastError(hr, "Failed to get CSP from cert.");
156 + CertExitWithLastError(hr, "Failed to get CSP from cert.");
157 }
158 LExit:
159 return hr;
@@ -159,10 +174,10 @@ extern "C" HRESULT DAPI FreeCryptProvFromCert(
174 FREECRYPTPROVFROMCERT pFreeCryptProvFromCert = NULL;
175
176 hr = LoadSystemLibrary(L"MsSign32.dll", &hMsSign32);
162 - ExitOnFailure(hr, "Failed to get handle to MsSign32.dll");
177 + CertExitOnFailure(hr, "Failed to get handle to MsSign32.dll");
178
179 pFreeCryptProvFromCert = (FREECRYPTPROVFROMCERT)::GetProcAddress(hMsSign32, "FreeCryptProvFromCert");
165 - ExitOnNullWithLastError(hMsSign32, hr, "Failed to get handle to MsSign32.dll");
180 + CertExitOnNullWithLastError(hMsSign32, hr, "Failed to get handle to MsSign32.dll");
181
182 pFreeCryptProvFromCert(fAcquired, hProv, pwszCapiProvider, dwProviderType, pwszTmpContainer);
183 LExit:
@@ -185,12 +200,12 @@ extern "C" HRESULT DAPI GetProvSecurityDesc(
200 &ulSize,
201 DACL_SECURITY_INFORMATION))
202 {
188 - ExitWithLastError(hr, "Error getting security descriptor size for CSP.");
203 + CertExitWithLastError(hr, "Error getting security descriptor size for CSP.");
204 }
205
206 // Allocate the memory for the security descriptor.
207 pSecurity = static_cast<SECURITY_DESCRIPTOR *>(MemAlloc(ulSize, TRUE));
193 - ExitOnNullWithLastError(pSecurity, hr, "Error allocating memory for CSP DACL");
208 + CertExitOnNullWithLastError(pSecurity, hr, "Error allocating memory for CSP DACL");
209
210 // Get the security descriptor.
211 if (!::CryptGetProvParam(
@@ -201,7 +216,7 @@ extern "C" HRESULT DAPI GetProvSecurityDesc(
216 DACL_SECURITY_INFORMATION))
217 {
218 MemFree(pSecurity);
204 - ExitWithLastError(hr, "Error getting security descriptor for CSP.");
219 + CertExitWithLastError(hr, "Error getting security descriptor for CSP.");
220 }
221 *ppSecurity = pSecurity;
222
@@ -223,7 +238,7 @@ extern "C" HRESULT DAPI SetProvSecurityDesc(
238 (BYTE*)pSecurity,
239 DACL_SECURITY_INFORMATION))
240 {
226 - ExitWithLastError(hr, "Error setting security descriptor for CSP.");
241 + CertExitWithLastError(hr, "Error setting security descriptor for CSP.");
242 }
243 LExit:
244 return hr;
@@ -278,12 +293,12 @@ extern "C" HRESULT DAPI CertInstallSingleCertificate(
293
294 if (!::CertSetCertificateContextProperty(pCertContext, CERT_FRIENDLY_NAME_PROP_ID, 0, &blob))
295 {
281 - ExitWithLastError(hr, "Failed to set the friendly name of the certificate: %ls", wzName);
296 + CertExitWithLastError(hr, "Failed to set the friendly name of the certificate: %ls", wzName);
297 }
298
299 if (!::CertAddCertificateContextToStore(hStore, pCertContext, CERT_STORE_ADD_REPLACE_EXISTING, NULL))
300 {
286 - ExitWithLastError(hr, "Failed to add certificate to the store.");
301 + CertExitWithLastError(hr, "Failed to add certificate to the store.");
302 }
303
304 // if the certificate has a private key, grant Administrators access
@@ -293,16 +308,16 @@ extern "C" HRESULT DAPI CertInstallSingleCertificate(
308 {
309 // We added a CSP key
310 hr = GetCryptProvFromCert(NULL, pCertContext, &hCsp, &dwKeySpec, &fAcquired, &pwszTmpContainer, &pwszProviderName, &dwProviderType);
296 - ExitOnFailure(hr, "Failed to get handle to CSP");
311 + CertExitOnFailure(hr, "Failed to get handle to CSP");
312
313 hr = GetProvSecurityDesc(hCsp, &pSecurity);
299 - ExitOnFailure(hr, "Failed to get security descriptor of CSP");
314 + CertExitOnFailure(hr, "Failed to get security descriptor of CSP");
315
316 hr = AclAddAdminToSecurityDescriptor(pSecurity, &pSecurityNew);
302 - ExitOnFailure(hr, "Failed to create new security descriptor");
317 + CertExitOnFailure(hr, "Failed to create new security descriptor");
318
319 hr = SetProvSecurityDesc(hCsp, pSecurityNew);
305 - ExitOnFailure(hr, "Failed to set Admin ACL on CSP");
320 + CertExitOnFailure(hr, "Failed to set Admin ACL on CSP");
321 }
322
323 if (CERT_NCRYPT_KEY_SPEC == dwKeySpec)
src/dutil/conutil.cpp
+47 -30
@@ -3,6 +3,21 @@
3 #include "precomp.h"
4
5
6 +// Exit macros
7 +#define ConExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_CONUTIL, x, s, __VA_ARGS__)
8 +#define ConExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_CONUTIL, x, s, __VA_ARGS__)
9 +#define ConExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_CONUTIL, x, s, __VA_ARGS__)
10 +#define ConExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_CONUTIL, x, s, __VA_ARGS__)
11 +#define ConExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_CONUTIL, x, s, __VA_ARGS__)
12 +#define ConExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_CONUTIL, x, s, __VA_ARGS__)
13 +#define ConExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_CONUTIL, p, x, e, s, __VA_ARGS__)
14 +#define ConExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_CONUTIL, p, x, s, __VA_ARGS__)
15 +#define ConExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_CONUTIL, p, x, e, s, __VA_ARGS__)
16 +#define ConExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_CONUTIL, p, x, s, __VA_ARGS__)
17 +#define ConExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_CONUTIL, e, x, s, __VA_ARGS__)
18 +#define ConExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_CONUTIL, g, x, s, __VA_ARGS__)
19 +
20 +
21 static HANDLE vhStdIn = INVALID_HANDLE_VALUE;
22 static HANDLE vhStdOut = INVALID_HANDLE_VALUE;
23 static BOOL vfConsoleIn = FALSE;
@@ -19,13 +34,13 @@ extern "C" HRESULT DAPI ConsoleInitialize()
34 vhStdIn = ::GetStdHandle(STD_INPUT_HANDLE);
35 if (INVALID_HANDLE_VALUE == vhStdIn)
36 {
22 - ExitOnLastError(hr, "failed to open stdin");
37 + ConExitOnLastError(hr, "failed to open stdin");
38 }
39
40 vhStdOut = ::GetStdHandle(STD_OUTPUT_HANDLE);
41 if (INVALID_HANDLE_VALUE == vhStdOut)
42 {
28 - ExitOnLastError(hr, "failed to open stdout");
43 + ConExitOnLastError(hr, "failed to open stdout");
44 }
45
46 // check if we have a std in on the console
@@ -43,7 +58,7 @@ extern "C" HRESULT DAPI ConsoleInitialize()
58 }
59 else
60 {
46 - ExitOnWin32Error(er, hr, "failed to get input console screen buffer info");
61 + ConExitOnWin32Error(er, hr, "failed to get input console screen buffer info");
62 }
63 }
64
@@ -62,7 +77,7 @@ extern "C" HRESULT DAPI ConsoleInitialize()
77 }
78 else
79 {
65 - ExitOnWin32Error(er, hr, "failed to get output console screen buffer info");
80 + ConExitOnWin32Error(er, hr, "failed to get output console screen buffer info");
81 }
82 }
83
@@ -89,6 +104,8 @@ LExit:
104
105 extern "C" void DAPI ConsoleUninitialize()
106 {
107 + BOOL fOutEqualsIn = vhStdOut == vhStdIn;
108 +
109 memset(&vcsbiInfo, 0, sizeof(vcsbiInfo));
110
111 if (INVALID_HANDLE_VALUE != vhStdOut)
@@ -96,7 +113,7 @@ extern "C" void DAPI ConsoleUninitialize()
113 ::CloseHandle(vhStdOut);
114 }
115
99 - if (INVALID_HANDLE_VALUE != vhStdIn && vhStdOut != vhStdIn)
116 + if (INVALID_HANDLE_VALUE != vhStdIn && !fOutEqualsIn)
117 {
118 ::CloseHandle(vhStdIn);
119 }
@@ -178,14 +195,14 @@ extern "C" HRESULT DAPI ConsoleWrite(
195 va_start(args, szFormat);
196 hr = StrAnsiAllocFormattedArgs(&pszOutput, szFormat, args);
197 va_end(args);
181 - ExitOnFailure(hr, "failed to format message: \"%s\"", szFormat);
198 + ConExitOnFailure(hr, "failed to format message: \"%s\"", szFormat);
199
200 cchOutput = lstrlenA(pszOutput);
201 while (cbTotal < (sizeof(*pszOutput) * cchOutput))
202 {
203 if (!::WriteFile(vhStdOut, reinterpret_cast<BYTE*>(pszOutput) + cbTotal, cchOutput * sizeof(*pszOutput) - cbTotal, &cbWrote, NULL))
204 {
188 - ExitOnLastError(hr, "failed to write output to console: %s", pszOutput);
205 + ConExitOnLastError(hr, "failed to write output to console: %s", pszOutput);
206 }
207
208 cbTotal += cbWrote;
@@ -236,7 +253,7 @@ extern "C" HRESULT DAPI ConsoleWriteLine(
253 va_start(args, szFormat);
254 hr = StrAnsiAllocFormattedArgs(&pszOutput, szFormat, args);
255 va_end(args);
239 - ExitOnFailure(hr, "failed to format message: \"%s\"", szFormat);
256 + ConExitOnFailure(hr, "failed to format message: \"%s\"", szFormat);
257
258 //
259 // write the string
@@ -245,7 +262,7 @@ extern "C" HRESULT DAPI ConsoleWriteLine(
262 while (cbTotal < (sizeof(*pszOutput) * cchOutput))
263 {
264 if (!::WriteFile(vhStdOut, reinterpret_cast<BYTE*>(pszOutput) + cbTotal, cchOutput * sizeof(*pszOutput) - cbTotal, &cbWrote, NULL))
248 - ExitOnLastError(hr, "failed to write output to console: %s", pszOutput);
265 + ConExitOnLastError(hr, "failed to write output to console: %s", pszOutput);
266
267 cbTotal += cbWrote;
268 }
@@ -255,7 +272,7 @@ extern "C" HRESULT DAPI ConsoleWriteLine(
272 //
273 if (!::WriteFile(vhStdOut, reinterpret_cast<const BYTE*>(szNewLine), 2, &cbWrote, NULL))
274 {
258 - ExitOnLastError(hr, "failed to write newline to console");
275 + ConExitOnLastError(hr, "failed to write newline to console");
276 }
277
278 // reset the color to normal
@@ -289,7 +306,7 @@ HRESULT ConsoleWriteError(
306 va_start(args, szFormat);
307 hr = StrAnsiAllocFormattedArgs(&pszMessage, szFormat, args);
308 va_end(args);
292 - ExitOnFailure(hr, "failed to format error message: \"%s\"", szFormat);
309 + ConExitOnFailure(hr, "failed to format error message: \"%s\"", szFormat);
310
311 if (FAILED(hrError))
312 {
@@ -326,14 +343,14 @@ extern "C" HRESULT DAPI ConsoleReadW(
343
344 cch = 64;
345 hr = StrAnsiAlloc(&psz, cch);
329 - ExitOnFailure(hr, "failed to allocate memory to read from console");
346 + ConExitOnFailure(hr, "failed to allocate memory to read from console");
347
348 // loop until we read the \r\n from the console
349 for (;;)
350 {
351 // read one character at a time, since that seems to be the only way to make this work
352 if (!::ReadFile(vhStdIn, psz + cchTotalRead, 1, &cchRead, NULL))
336 - ExitOnLastError(hr, "failed to read string from console");
353 + ConExitOnLastError(hr, "failed to read string from console");
354
355 cchTotalRead += cchRead;
356 if (1 < cchTotalRead && '\r' == psz[cchTotalRead - 2] || '\n' == psz[cchTotalRead - 1])
@@ -351,7 +368,7 @@ extern "C" HRESULT DAPI ConsoleReadW(
368 {
369 cch *= 2; // double everytime we run out of space
370 hr = StrAnsiAlloc(&psz, cch);
354 - ExitOnFailure(hr, "failed to allocate memory to read from console");
371 + ConExitOnFailure(hr, "failed to allocate memory to read from console");
372 }
373 }
374
@@ -381,7 +398,7 @@ extern "C" HRESULT DAPI ConsoleReadNonBlockingW(
398
399 LPSTR psz = NULL;
400
384 - ExitOnNull(ppwzBuffer, hr, E_INVALIDARG, "Failed to read from console because buffer was not provided");
401 + ConExitOnNull(ppwzBuffer, hr, E_INVALIDARG, "Failed to read from console because buffer was not provided");
402
403 DWORD dwRead;
404 DWORD dwNumInput;
@@ -412,7 +429,7 @@ extern "C" HRESULT DAPI ConsoleReadNonBlockingW(
429
430 if (!GetNumberOfConsoleInputEvents(vhStdIn, &dwRead))
431 {
415 - ExitOnLastError(hr, "failed to peek at console input");
432 + ConExitOnLastError(hr, "failed to peek at console input");
433 }
434
435 if (0 == dwRead)
@@ -424,7 +441,7 @@ extern "C" HRESULT DAPI ConsoleReadNonBlockingW(
441 {
442 if (!ReadConsoleInputW(vhStdIn, &ir, 1, &dwNumInput))
443 {
427 - ExitOnLastError(hr, "Failed to read input from console");
444 + ConExitOnLastError(hr, "Failed to read input from console");
445 }
446
447 // If what we have is a KEY_EVENT, and that event signifies keyUp, we're interested
@@ -463,14 +480,14 @@ extern "C" HRESULT DAPI ConsoleReadNonBlockingW(
480
481 cch = 8;
482 hr = StrAnsiAlloc(&psz, cch);
466 - ExitOnFailure(hr, "failed to allocate memory to read from console");
483 + ConExitOnFailure(hr, "failed to allocate memory to read from console");
484
485 for (/*dwRead from PeekNamedPipe*/; dwRead > 0; dwRead--)
486 {
487 // read one character at a time, since that seems to be the only way to make this work
488 if (!::ReadFile(vhStdIn, psz + cchTotalRead, 1, &cchRead, NULL))
489 {
473 - ExitOnLastError(hr, "failed to read string from console");
490 + ConExitOnLastError(hr, "failed to read string from console");
491 }
492
493 cchTotalRead += cchRead;
@@ -490,7 +507,7 @@ extern "C" HRESULT DAPI ConsoleReadNonBlockingW(
507 {
508 cch *= 2; // double everytime we run out of space
509 hr = StrAnsiAlloc(&psz, cch);
493 - ExitOnFailure(hr, "failed to allocate memory to read from console");
510 + ConExitOnFailure(hr, "failed to allocate memory to read from console");
511 }
512 }
513
@@ -510,7 +527,7 @@ LExit:
527
528 *********************************************************************/
529 extern "C" HRESULT DAPI ConsoleReadStringA(
513 - __deref_out_ecount_part(cchCharBuffer,*pcchNumCharReturn) LPSTR* ppszCharBuffer,
530 + __deref_inout_ecount_part(cchCharBuffer,*pcchNumCharReturn) LPSTR* ppszCharBuffer,
531 CONST DWORD cchCharBuffer,
532 __out DWORD* pcchNumCharReturn
533 )
@@ -526,11 +543,11 @@ extern "C" HRESULT DAPI ConsoleReadStringA(
543 do
544 {
545 hr = StrAnsiAlloc(ppszCharBuffer, cchCharBuffer * iRead);
529 - ExitOnFailure(hr, "failed to allocate memory for ConsoleReadStringW");
546 + ConExitOnFailure(hr, "failed to allocate memory for ConsoleReadStringW");
547 // ReadConsoleW will not return until <Return>, the last two chars are 13 and 10.
548 if (!::ReadConsoleA(vhStdIn, *ppszCharBuffer + iReadCharTotal, cchCharBuffer, pcchNumCharReturn, NULL) || *pcchNumCharReturn == 0)
549 {
533 - ExitOnLastError(hr, "failed to read string from console");
550 + ConExitOnLastError(hr, "failed to read string from console");
551 }
552 iReadCharTotal += *pcchNumCharReturn;
553 iRead += 1;
@@ -543,7 +560,7 @@ extern "C" HRESULT DAPI ConsoleReadStringA(
560 if (!::ReadConsoleA(vhStdIn, *ppszCharBuffer, cchCharBuffer, pcchNumCharReturn, NULL) ||
561 *pcchNumCharReturn > cchCharBuffer || *pcchNumCharReturn == 0)
562 {
546 - ExitOnLastError(hr, "failed to read string from console");
563 + ConExitOnLastError(hr, "failed to read string from console");
564 }
565 if ((*ppszCharBuffer)[*pcchNumCharReturn - 1] != 10 ||
566 (*ppszCharBuffer)[*pcchNumCharReturn - 2] != 13)
@@ -567,7 +584,7 @@ LExit:
584
585 *********************************************************************/
586 extern "C" HRESULT DAPI ConsoleReadStringW(
570 - __deref_out_ecount_part(cchCharBuffer,*pcchNumCharReturn) LPWSTR* ppwzCharBuffer,
587 + __deref_inout_ecount_part(cchCharBuffer,*pcchNumCharReturn) LPWSTR* ppwzCharBuffer,
588 const DWORD cchCharBuffer,
589 __out DWORD* pcchNumCharReturn
590 )
@@ -583,11 +600,11 @@ extern "C" HRESULT DAPI ConsoleReadStringW(
600 do
601 {
602 hr = StrAlloc(ppwzCharBuffer, cchCharBuffer * iRead);
586 - ExitOnFailure(hr, "failed to allocate memory for ConsoleReadStringW");
603 + ConExitOnFailure(hr, "failed to allocate memory for ConsoleReadStringW");
604 // ReadConsoleW will not return until <Return>, the last two chars are 13 and 10.
605 if (!::ReadConsoleW(vhStdIn, *ppwzCharBuffer + iReadCharTotal, cchCharBuffer, pcchNumCharReturn, NULL) || *pcchNumCharReturn == 0)
606 {
590 - ExitOnLastError(hr, "failed to read string from console");
607 + ConExitOnLastError(hr, "failed to read string from console");
608 }
609 iReadCharTotal += *pcchNumCharReturn;
610 iRead += 1;
@@ -600,7 +617,7 @@ extern "C" HRESULT DAPI ConsoleReadStringW(
617 if (!::ReadConsoleW(vhStdIn, *ppwzCharBuffer, cchCharBuffer, pcchNumCharReturn, NULL) ||
618 *pcchNumCharReturn > cchCharBuffer || *pcchNumCharReturn == 0)
619 {
603 - ExitOnLastError(hr, "failed to read string from console");
620 + ConExitOnLastError(hr, "failed to read string from console");
621 }
622 if ((*ppwzCharBuffer)[*pcchNumCharReturn - 1] != 10 ||
623 (*ppwzCharBuffer)[*pcchNumCharReturn - 2] != 13)
@@ -630,7 +647,7 @@ extern "C" HRESULT DAPI ConsoleSetReadHidden(void)
647 ::FlushConsoleInputBuffer(vhStdIn);
648 if (!::SetConsoleMode(vhStdIn, ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT))
649 {
633 - ExitOnLastError(hr, "failed to set console input mode to be hidden");
650 + ConExitOnLastError(hr, "failed to set console input mode to be hidden");
651 }
652
653 LExit:
@@ -647,7 +664,7 @@ extern "C" HRESULT DAPI ConsoleSetReadNormal(void)
664 HRESULT hr = S_OK;
665 if (!::SetConsoleMode(vhStdIn, ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT))
666 {
650 - ExitOnLastError(hr, "failed to set console input mode to be normal");
667 + ConExitOnLastError(hr, "failed to set console input mode to be normal");
668 }
669
670 LExit:
src/dutil/cryputil.cpp
+39 -24
@@ -2,6 +2,21 @@
2
3 #include "precomp.h"
4
5 +
6 +// Exit macros
7 +#define CrypExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_CRYPUTIL, x, s, __VA_ARGS__)
8 +#define CrypExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_CRYPUTIL, x, s, __VA_ARGS__)
9 +#define CrypExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_CRYPUTIL, x, s, __VA_ARGS__)
10 +#define CrypExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_CRYPUTIL, x, s, __VA_ARGS__)
11 +#define CrypExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_CRYPUTIL, x, s, __VA_ARGS__)
12 +#define CrypExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_CRYPUTIL, x, s, __VA_ARGS__)
13 +#define CrypExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_CRYPUTIL, p, x, e, s, __VA_ARGS__)
14 +#define CrypExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_CRYPUTIL, p, x, s, __VA_ARGS__)
15 +#define CrypExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_CRYPUTIL, p, x, e, s, __VA_ARGS__)
16 +#define CrypExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_CRYPUTIL, p, x, s, __VA_ARGS__)
17 +#define CrypExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_CRYPUTIL, e, x, s, __VA_ARGS__)
18 +#define CrypExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_CRYPUTIL, g, x, s, __VA_ARGS__)
19 +
20 static PFN_RTLENCRYPTMEMORY vpfnRtlEncryptMemory = NULL;
21 static PFN_RTLDECRYPTMEMORY vpfnRtlDecryptMemory = NULL;
22 static PFN_CRYPTPROTECTMEMORY vpfnCryptProtectMemory = NULL;
@@ -32,17 +47,17 @@ extern "C" HRESULT DAPI CrypInitialize(
47 if (!vpfnRtlEncryptMemory || !vpfnRtlDecryptMemory)
48 {
49 hr = LoadSystemLibrary(L"Crypt32.dll", &vhCrypt32Dll);
35 - ExitOnFailure(hr, "Failed to load Crypt32.dll");
50 + CrypExitOnFailure(hr, "Failed to load Crypt32.dll");
51
52 vpfnCryptProtectMemory = reinterpret_cast<PFN_CRYPTPROTECTMEMORY>(::GetProcAddress(vhCrypt32Dll, "CryptProtectMemory"));
53 if (!vpfnRtlEncryptMemory && !vpfnCryptProtectMemory)
54 {
40 - ExitWithLastError(hr, "Failed to load an encryption method");
55 + CrypExitWithLastError(hr, "Failed to load an encryption method");
56 }
57 vpfnCryptUnprotectMemory = reinterpret_cast<PFN_CRYPTUNPROTECTMEMORY>(::GetProcAddress(vhCrypt32Dll, "CryptUnprotectMemory"));
58 if (!vpfnRtlDecryptMemory && !vpfnCryptUnprotectMemory)
59 {
45 - ExitWithLastError(hr, "Failed to load a decryption method");
60 + CrypExitWithLastError(hr, "Failed to load a decryption method");
61 }
62 }
63
@@ -94,15 +109,15 @@ extern "C" HRESULT DAPI CrypDecodeObject(
109
110 if (!::CryptDecodeObject(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, szStructType, pbData, cbData, dwFlags, NULL, &cbObject))
111 {
97 - ExitWithLastError(hr, "Failed to decode object to determine size.");
112 + CrypExitWithLastError(hr, "Failed to decode object to determine size.");
113 }
114
115 pvObject = MemAlloc(cbObject, TRUE);
101 - ExitOnNull(pvObject, hr, E_OUTOFMEMORY, "Failed to allocate memory for decoded object.");
116 + CrypExitOnNull(pvObject, hr, E_OUTOFMEMORY, "Failed to allocate memory for decoded object.");
117
118 if (!::CryptDecodeObject(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, szStructType, pbData, cbData, dwFlags, pvObject, &cbObject))
119 {
105 - ExitWithLastError(hr, "Failed to decode object.");
120 + CrypExitWithLastError(hr, "Failed to decode object.");
121 }
122
123 *ppvObject = pvObject;
@@ -134,15 +149,15 @@ extern "C" HRESULT DAPI CrypMsgGetParam(
149
150 if (!::CryptMsgGetParam(hCryptMsg, dwType, dwIndex, NULL, &cb))
151 {
137 - ExitWithLastError(hr, "Failed to get crypt message parameter data size.");
152 + CrypExitWithLastError(hr, "Failed to get crypt message parameter data size.");
153 }
154
155 pv = MemAlloc(cb, TRUE);
141 - ExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to allocate memory for crypt message parameter.");
156 + CrypExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to allocate memory for crypt message parameter.");
157
158 if (!::CryptMsgGetParam(hCryptMsg, dwType, dwIndex, pv, &cb))
159 {
145 - ExitWithLastError(hr, "Failed to get crypt message parameter.");
160 + CrypExitWithLastError(hr, "Failed to get crypt message parameter.");
161 }
162
163 *ppvData = pv;
@@ -161,7 +176,7 @@ LExit:
176
177
178 extern "C" HRESULT DAPI CrypHashFile(
164 - __in LPCWSTR wzFilePath,
179 + __in_z LPCWSTR wzFilePath,
180 __in DWORD dwProvType,
181 __in ALG_ID algid,
182 __out_bcount(cbHash) BYTE* pbHash,
@@ -176,11 +191,11 @@ extern "C" HRESULT DAPI CrypHashFile(
191 hFile = ::CreateFileW(wzFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
192 if (INVALID_HANDLE_VALUE == hFile)
193 {
179 - ExitWithLastError(hr, "Failed to open input file.");
194 + CrypExitWithLastError(hr, "Failed to open input file.");
195 }
196
197 hr = CrypHashFileHandle(hFile, dwProvType, algid, pbHash, cbHash, pqwBytesHashed);
183 - ExitOnFailure(hr, "Failed to hash file: %ls", wzFilePath);
198 + CrypExitOnFailure(hr, "Failed to hash file: %ls", wzFilePath);
199
200 LExit:
201 ReleaseFileHandle(hFile);
@@ -208,13 +223,13 @@ extern "C" HRESULT DAPI CrypHashFileHandle(
223 // get handle to the crypto provider
224 if (!::CryptAcquireContextW(&hProv, NULL, NULL, dwProvType, CRYPT_VERIFYCONTEXT | CRYPT_SILENT))
225 {
211 - ExitWithLastError(hr, "Failed to acquire crypto context.");
226 + CrypExitWithLastError(hr, "Failed to acquire crypto context.");
227 }
228
229 // initiate hash
230 if (!::CryptCreateHash(hProv, algid, 0, 0, &hHash))
231 {
217 - ExitWithLastError(hr, "Failed to initiate hash.");
232 + CrypExitWithLastError(hr, "Failed to initiate hash.");
233 }
234
235 for (;;)
@@ -222,7 +237,7 @@ extern "C" HRESULT DAPI CrypHashFileHandle(
237 // read data block
238 if (!::ReadFile(hFile, rgbBuffer, sizeof(rgbBuffer), &cbRead, NULL))
239 {
225 - ExitWithLastError(hr, "Failed to read data block.");
240 + CrypExitWithLastError(hr, "Failed to read data block.");
241 }
242
243 if (!cbRead)
@@ -233,21 +248,21 @@ extern "C" HRESULT DAPI CrypHashFileHandle(
248 // hash data block
249 if (!::CryptHashData(hHash, rgbBuffer, cbRead, 0))
250 {
236 - ExitWithLastError(hr, "Failed to hash data block.");
251 + CrypExitWithLastError(hr, "Failed to hash data block.");
252 }
253 }
254
255 // get hash value
256 if (!::CryptGetHashParam(hHash, HP_HASHVAL, pbHash, &cbHash, 0))
257 {
243 - ExitWithLastError(hr, "Failed to get hash value.");
258 + CrypExitWithLastError(hr, "Failed to get hash value.");
259 }
260
261 if (pqwBytesHashed)
262 {
263 if (!::SetFilePointerEx(hFile, liZero, (LARGE_INTEGER*)pqwBytesHashed, FILE_CURRENT))
264 {
250 - ExitWithLastError(hr, "Failed to get file pointer.");
265 + CrypExitWithLastError(hr, "Failed to get file pointer.");
266 }
267 }
268
@@ -280,24 +295,24 @@ HRESULT DAPI CrypHashBuffer(
295 // get handle to the crypto provider
296 if (!::CryptAcquireContextW(&hProv, NULL, NULL, dwProvType, CRYPT_VERIFYCONTEXT | CRYPT_SILENT))
297 {
283 - ExitWithLastError(hr, "Failed to acquire crypto context.");
298 + CrypExitWithLastError(hr, "Failed to acquire crypto context.");
299 }
300
301 // initiate hash
302 if (!::CryptCreateHash(hProv, algid, 0, 0, &hHash))
303 {
289 - ExitWithLastError(hr, "Failed to initiate hash.");
304 + CrypExitWithLastError(hr, "Failed to initiate hash.");
305 }
306
307 if (!::CryptHashData(hHash, pbBuffer, static_cast<DWORD>(cbBuffer), 0))
308 {
294 - ExitWithLastError(hr, "Failed to hash data.");
309 + CrypExitWithLastError(hr, "Failed to hash data.");
310 }
311
312 // get hash value
313 if (!::CryptGetHashParam(hHash, HP_HASHVAL, pbHash, &cbHash, 0))
314 {
300 - ExitWithLastError(hr, "Failed to get hash value.");
315 + CrypExitWithLastError(hr, "Failed to get hash value.");
316 }
317
318 LExit:
@@ -340,7 +355,7 @@ HRESULT DAPI CrypEncryptMemory(
355 hr = HRESULT_FROM_WIN32(::GetLastError());
356 }
357 }
343 - ExitOnFailure(hr, "Failed to encrypt memory");
358 + CrypExitOnFailure(hr, "Failed to encrypt memory");
359 LExit:
360 return hr;
361 }
@@ -372,7 +387,7 @@ HRESULT DAPI CrypDecryptMemory(
387 hr = HRESULT_FROM_WIN32(::GetLastError());
388 }
389 }
375 - ExitOnFailure(hr, "Failed to decrypt memory");
390 + CrypExitOnFailure(hr, "Failed to decrypt memory");
391 LExit:
392 return hr;
393 }
src/dutil/deputil.cpp
+80 -65
@@ -2,6 +2,21 @@
2
3 #include "precomp.h"
4
5 +
6 +// Exit macros
7 +#define DepExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_DEPUTIL, x, s, __VA_ARGS__)
8 +#define DepExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_DEPUTIL, x, s, __VA_ARGS__)
9 +#define DepExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_DEPUTIL, x, s, __VA_ARGS__)
10 +#define DepExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_DEPUTIL, x, s, __VA_ARGS__)
11 +#define DepExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_DEPUTIL, x, s, __VA_ARGS__)
12 +#define DepExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_DEPUTIL, x, s, __VA_ARGS__)
13 +#define DepExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_DEPUTIL, p, x, e, s, __VA_ARGS__)
14 +#define DepExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_DEPUTIL, p, x, s, __VA_ARGS__)
15 +#define DepExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_DEPUTIL, p, x, e, s, __VA_ARGS__)
16 +#define DepExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_DEPUTIL, p, x, s, __VA_ARGS__)
17 +#define DepExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_DEPUTIL, e, x, s, __VA_ARGS__)
18 +#define DepExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_DEPUTIL, g, x, s, __VA_ARGS__)
19 +
20 #define ARRAY_GROWTH_SIZE 5
21
22 static LPCWSTR vcszVersionValue = L"Version";
@@ -42,7 +57,7 @@ DAPI_(HRESULT) DepGetProviderInformation(
57
58 // Format the provider dependency registry key.
59 hr = AllocDependencyKeyName(wzProviderKey, &sczKey);
45 - ExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzProviderKey);
60 + DepExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzProviderKey);
61
62 // Try to open the dependency key.
63 hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey);
@@ -50,7 +65,7 @@ DAPI_(HRESULT) DepGetProviderInformation(
65 {
66 ExitFunction1(hr = E_NOTFOUND);
67 }
53 - ExitOnFailure(hr, "Failed to open the registry key for the dependency \"%ls\".", wzProviderKey);
68 + DepExitOnFailure(hr, "Failed to open the registry key for the dependency \"%ls\".", wzProviderKey);
69
70 // Get the Id if requested and available.
71 if (psczId)
@@ -60,7 +75,7 @@ DAPI_(HRESULT) DepGetProviderInformation(
75 {
76 hr = S_OK;
77 }
63 - ExitOnFailure(hr, "Failed to get the id for the dependency \"%ls\".", wzProviderKey);
78 + DepExitOnFailure(hr, "Failed to get the id for the dependency \"%ls\".", wzProviderKey);
79 }
80
81 // Get the DisplayName if requested and available.
@@ -71,7 +86,7 @@ DAPI_(HRESULT) DepGetProviderInformation(
86 {
87 hr = S_OK;
88 }
74 - ExitOnFailure(hr, "Failed to get the name for the dependency \"%ls\".", wzProviderKey);
89 + DepExitOnFailure(hr, "Failed to get the name for the dependency \"%ls\".", wzProviderKey);
90 }
91
92 // Get the Version if requested and available.
@@ -82,7 +97,7 @@ DAPI_(HRESULT) DepGetProviderInformation(
97 {
98 hr = S_OK;
99 }
85 - ExitOnFailure(hr, "Failed to get the version for the dependency \"%ls\".", wzProviderKey);
100 + DepExitOnFailure(hr, "Failed to get the version for the dependency \"%ls\".", wzProviderKey);
101 }
102
103 LExit:
@@ -116,19 +131,19 @@ DAPI_(HRESULT) DepCheckDependency(
131
132 // Format the provider dependency registry key.
133 hr = AllocDependencyKeyName(wzProviderKey, &sczKey);
119 - ExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzProviderKey);
134 + DepExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzProviderKey);
135
136 // Try to open the key. If that fails, add the missing dependency key to the dependency array if it doesn't already exist.
137 hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey);
138 if (E_FILENOTFOUND != hr)
139 {
125 - ExitOnFailure(hr, "Failed to open the registry key for dependency \"%ls\".", wzProviderKey);
140 + DepExitOnFailure(hr, "Failed to open the registry key for dependency \"%ls\".", wzProviderKey);
141
142 // If there are no registry values, consider the key orphaned and treat it as missing.
143 hr = RegReadVersion(hkKey, vcszVersionValue, &dw64Version);
144 if (E_FILENOTFOUND != hr)
145 {
131 - ExitOnFailure(hr, "Failed to read the %ls registry value for dependency \"%ls\".", vcszVersionValue, wzProviderKey);
146 + DepExitOnFailure(hr, "Failed to read the %ls registry value for dependency \"%ls\".", vcszVersionValue, wzProviderKey);
147 }
148 }
149
@@ -138,15 +153,15 @@ DAPI_(HRESULT) DepCheckDependency(
153 hr = DictKeyExists(sdDependencies, wzProviderKey);
154 if (E_NOTFOUND != hr)
155 {
141 - ExitOnFailure(hr, "Failed to check the dictionary for missing dependency \"%ls\".", wzProviderKey);
156 + DepExitOnFailure(hr, "Failed to check the dictionary for missing dependency \"%ls\".", wzProviderKey);
157 }
158 else
159 {
160 hr = DepDependencyArrayAlloc(prgDependencies, pcDependencies, wzProviderKey, NULL);
146 - ExitOnFailure(hr, "Failed to add the missing dependency \"%ls\" to the array.", wzProviderKey);
161 + DepExitOnFailure(hr, "Failed to add the missing dependency \"%ls\" to the array.", wzProviderKey);
162
163 hr = DictAddKey(sdDependencies, wzProviderKey);
149 - ExitOnFailure(hr, "Failed to add the missing dependency \"%ls\" to the dictionary.", wzProviderKey);
164 + DepExitOnFailure(hr, "Failed to add the missing dependency \"%ls\" to the dictionary.", wzProviderKey);
165 }
166
167 // Exit since the check already failed.
@@ -160,7 +175,7 @@ DAPI_(HRESULT) DepCheckDependency(
175 if (0 < cchMinVersion)
176 {
177 hr = FileVersionFromStringEx(wzMinVersion, cchMinVersion, &dw64MinVersion);
163 - ExitOnFailure(hr, "Failed to get the 64-bit version number from \"%ls\".", wzMinVersion);
178 + DepExitOnFailure(hr, "Failed to get the 64-bit version number from \"%ls\".", wzMinVersion);
179
180 fAllowEqual = iAttributes & RequiresAttributesMinVersionInclusive;
181 if (!(fAllowEqual && dw64MinVersion <= dw64Version || dw64MinVersion < dw64Version))
@@ -168,18 +183,18 @@ DAPI_(HRESULT) DepCheckDependency(
183 hr = DictKeyExists(sdDependencies, wzProviderKey);
184 if (E_NOTFOUND != hr)
185 {
171 - ExitOnFailure(hr, "Failed to check the dictionary for the older dependency \"%ls\".", wzProviderKey);
186 + DepExitOnFailure(hr, "Failed to check the dictionary for the older dependency \"%ls\".", wzProviderKey);
187 }
188 else
189 {
190 hr = RegReadString(hkKey, vcszDisplayNameValue, &sczName);
176 - ExitOnFailure(hr, "Failed to get the display name of the older dependency \"%ls\".", wzProviderKey);
191 + DepExitOnFailure(hr, "Failed to get the display name of the older dependency \"%ls\".", wzProviderKey);
192
193 hr = DepDependencyArrayAlloc(prgDependencies, pcDependencies, wzProviderKey, sczName);
179 - ExitOnFailure(hr, "Failed to add the older dependency \"%ls\" to the dependencies array.", wzProviderKey);
194 + DepExitOnFailure(hr, "Failed to add the older dependency \"%ls\" to the dependencies array.", wzProviderKey);
195
196 hr = DictAddKey(sdDependencies, wzProviderKey);
182 - ExitOnFailure(hr, "Failed to add the older dependency \"%ls\" to the unique dependency string list.", wzProviderKey);
197 + DepExitOnFailure(hr, "Failed to add the older dependency \"%ls\" to the unique dependency string list.", wzProviderKey);
198 }
199
200 // Exit since the check already failed.
@@ -195,7 +210,7 @@ DAPI_(HRESULT) DepCheckDependency(
210 if (0 < cchMaxVersion)
211 {
212 hr = FileVersionFromStringEx(wzMaxVersion, cchMaxVersion, &dw64MaxVersion);
198 - ExitOnFailure(hr, "Failed to get the 64-bit version number from \"%ls\".", wzMaxVersion);
213 + DepExitOnFailure(hr, "Failed to get the 64-bit version number from \"%ls\".", wzMaxVersion);
214
215 fAllowEqual = iAttributes & RequiresAttributesMaxVersionInclusive;
216 if (!(fAllowEqual && dw64Version <= dw64MaxVersion || dw64Version < dw64MaxVersion))
@@ -203,18 +218,18 @@ DAPI_(HRESULT) DepCheckDependency(
218 hr = DictKeyExists(sdDependencies, wzProviderKey);
219 if (E_NOTFOUND != hr)
220 {
206 - ExitOnFailure(hr, "Failed to check the dictionary for the newer dependency \"%ls\".", wzProviderKey);
221 + DepExitOnFailure(hr, "Failed to check the dictionary for the newer dependency \"%ls\".", wzProviderKey);
222 }
223 else
224 {
225 hr = RegReadString(hkKey, vcszDisplayNameValue, &sczName);
211 - ExitOnFailure(hr, "Failed to get the display name of the newer dependency \"%ls\".", wzProviderKey);
226 + DepExitOnFailure(hr, "Failed to get the display name of the newer dependency \"%ls\".", wzProviderKey);
227
228 hr = DepDependencyArrayAlloc(prgDependencies, pcDependencies, wzProviderKey, sczName);
214 - ExitOnFailure(hr, "Failed to add the newer dependency \"%ls\" to the dependencies array.", wzProviderKey);
229 + DepExitOnFailure(hr, "Failed to add the newer dependency \"%ls\" to the dependencies array.", wzProviderKey);
230
231 hr = DictAddKey(sdDependencies, wzProviderKey);
217 - ExitOnFailure(hr, "Failed to add the newer dependency \"%ls\" to the unique dependency string list.", wzProviderKey);
232 + DepExitOnFailure(hr, "Failed to add the newer dependency \"%ls\" to the unique dependency string list.", wzProviderKey);
233 }
234
235 // Exit since the check already failed.
@@ -249,17 +264,17 @@ DAPI_(HRESULT) DepCheckDependents(
264
265 // Format the provider dependency registry key.
266 hr = AllocDependencyKeyName(wzProviderKey, &sczKey);
252 - ExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzProviderKey);
267 + DepExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzProviderKey);
268
269 // Try to open the key. If that fails, the dependency information is corrupt.
270 hr = RegOpen(hkHive, sczKey, KEY_READ, &hkProviderKey);
256 - ExitOnFailure(hr, "Failed to open the registry key \"%ls\". The dependency store is corrupt.", sczKey);
271 + DepExitOnFailure(hr, "Failed to open the registry key \"%ls\". The dependency store is corrupt.", sczKey);
272
273 // Try to open the dependencies key. If that does not exist, there are no dependents.
274 hr = RegOpen(hkProviderKey, vsczRegistryDependents, KEY_READ, &hkDependentsKey);
275 if (E_FILENOTFOUND != hr)
276 {
262 - ExitOnFailure(hr, "Failed to open the registry key for dependents of \"%ls\".", wzProviderKey);
277 + DepExitOnFailure(hr, "Failed to open the registry key for dependents of \"%ls\".", wzProviderKey);
278 }
279 else
280 {
@@ -272,7 +287,7 @@ DAPI_(HRESULT) DepCheckDependents(
287 hr = RegKeyEnum(hkDependentsKey, dwIndex, &sczDependentKey);
288 if (E_NOMOREITEMS != hr)
289 {
275 - ExitOnFailure(hr, "Failed to enumerate the dependents key of \"%ls\".", wzProviderKey);
290 + DepExitOnFailure(hr, "Failed to enumerate the dependents key of \"%ls\".", wzProviderKey);
291 }
292 else
293 {
@@ -284,16 +299,16 @@ DAPI_(HRESULT) DepCheckDependents(
299 hr = DictKeyExists(sdIgnoredDependents, sczDependentKey);
300 if (E_NOTFOUND != hr)
301 {
287 - ExitOnFailure(hr, "Failed to check the dictionary of ignored dependents.");
302 + DepExitOnFailure(hr, "Failed to check the dictionary of ignored dependents.");
303 }
304 else
305 {
306 // Get the name of the dependent from the key.
307 hr = GetDependencyNameFromKey(hkHive, sczDependentKey, &sczDependentName);
293 - ExitOnFailure(hr, "Failed to get the name of the dependent from the key \"%ls\".", sczDependentKey);
308 + DepExitOnFailure(hr, "Failed to get the name of the dependent from the key \"%ls\".", sczDependentKey);
309
310 hr = DepDependencyArrayAlloc(prgDependents, pcDependents, sczDependentKey, sczDependentName);
296 - ExitOnFailure(hr, "Failed to add the dependent key \"%ls\" to the string array.", sczDependentKey);
311 + DepExitOnFailure(hr, "Failed to add the dependent key \"%ls\" to the string array.", sczDependentKey);
312 }
313 }
314
@@ -323,32 +338,32 @@ DAPI_(HRESULT) DepRegisterDependency(
338
339 // Format the provider dependency registry key.
340 hr = AllocDependencyKeyName(wzProviderKey, &sczKey);
326 - ExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzProviderKey);
341 + DepExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzProviderKey);
342
343 // Create the dependency key (or open it if it already exists).
344 hr = RegCreateEx(hkHive, sczKey, KEY_WRITE, FALSE, NULL, &hkKey, &fCreated);
330 - ExitOnFailure(hr, "Failed to create the dependency registry key \"%ls\".", sczKey);
345 + DepExitOnFailure(hr, "Failed to create the dependency registry key \"%ls\".", sczKey);
346
347 // Set the id if it was provided.
348 if (wzId)
349 {
350 hr = RegWriteString(hkKey, NULL, wzId);
336 - ExitOnFailure(hr, "Failed to set the %ls registry value to \"%ls\".", L"default", wzId);
351 + DepExitOnFailure(hr, "Failed to set the %ls registry value to \"%ls\".", L"default", wzId);
352 }
353
354 // Set the version.
355 hr = RegWriteString(hkKey, vcszVersionValue, wzVersion);
341 - ExitOnFailure(hr, "Failed to set the %ls registry value to \"%ls\".", vcszVersionValue, wzVersion);
356 + DepExitOnFailure(hr, "Failed to set the %ls registry value to \"%ls\".", vcszVersionValue, wzVersion);
357
358 // Set the display name.
359 hr = RegWriteString(hkKey, vcszDisplayNameValue, wzDisplayName);
345 - ExitOnFailure(hr, "Failed to set the %ls registry value to \"%ls\".", vcszDisplayNameValue, wzDisplayName);
360 + DepExitOnFailure(hr, "Failed to set the %ls registry value to \"%ls\".", vcszDisplayNameValue, wzDisplayName);
361
362 // Set the attributes if non-zero.
363 if (0 != iAttributes)
364 {
365 hr = RegWriteNumber(hkKey, vcszAttributesValue, static_cast<DWORD>(iAttributes));
351 - ExitOnFailure(hr, "Failed to set the %ls registry value to %d.", vcszAttributesValue, iAttributes);
366 + DepExitOnFailure(hr, "Failed to set the %ls registry value to %d.", vcszAttributesValue, iAttributes);
367 }
368
369 LExit:
@@ -370,12 +385,12 @@ DAPI_(HRESULT) DepDependentExists(
385
386 // Format the provider dependents registry key.
387 hr = StrAllocFormatted(&sczDependentKey, L"%ls%ls\\%ls\\%ls", vsczRegistryRoot, wzDependencyProviderKey, vsczRegistryDependents, wzProviderKey);
373 - ExitOnFailure(hr, "Failed to format registry key to dependent.");
388 + DepExitOnFailure(hr, "Failed to format registry key to dependent.");
389
390 hr = RegOpen(hkHive, sczDependentKey, KEY_READ, &hkDependentKey);
391 if (E_FILENOTFOUND != hr)
392 {
378 - ExitOnFailure(hr, "Failed to open the dependent registry key at: \"%ls\".", sczDependentKey);
393 + DepExitOnFailure(hr, "Failed to open the dependent registry key at: \"%ls\".", sczDependentKey);
394 }
395
396 LExit:
@@ -403,32 +418,32 @@ DAPI_(HRESULT) DepRegisterDependent(
418
419 // Format the provider dependency registry key.
420 hr = AllocDependencyKeyName(wzDependencyProviderKey, &sczDependencyKey);
406 - ExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzDependencyProviderKey);
421 + DepExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzDependencyProviderKey);
422
423 // Create the dependency key (or open it if it already exists).
424 hr = RegCreateEx(hkHive, sczDependencyKey, KEY_WRITE, FALSE, NULL, &hkDependencyKey, &fCreated);
410 - ExitOnFailure(hr, "Failed to create the dependency registry key \"%ls\".", sczDependencyKey);
425 + DepExitOnFailure(hr, "Failed to create the dependency registry key \"%ls\".", sczDependencyKey);
426
427 // Create the subkey to register the dependent.
428 hr = StrAllocFormatted(&sczKey, L"%ls\\%ls", vsczRegistryDependents, wzProviderKey);
414 - ExitOnFailure(hr, "Failed to allocate dependent subkey \"%ls\" under dependency \"%ls\".", wzProviderKey, wzDependencyProviderKey);
429 + DepExitOnFailure(hr, "Failed to allocate dependent subkey \"%ls\" under dependency \"%ls\".", wzProviderKey, wzDependencyProviderKey);
430
431 hr = RegCreateEx(hkDependencyKey, sczKey, KEY_WRITE, FALSE, NULL, &hkKey, &fCreated);
417 - ExitOnFailure(hr, "Failed to create the dependency subkey \"%ls\".", sczKey);
432 + DepExitOnFailure(hr, "Failed to create the dependency subkey \"%ls\".", sczKey);
433
434 // Set the minimum version if not NULL.
435 hr = RegWriteString(hkKey, vcszMinVersionValue, wzMinVersion);
421 - ExitOnFailure(hr, "Failed to set the %ls registry value to \"%ls\".", vcszMinVersionValue, wzMinVersion);
436 + DepExitOnFailure(hr, "Failed to set the %ls registry value to \"%ls\".", vcszMinVersionValue, wzMinVersion);
437
438 // Set the maximum version if not NULL.
439 hr = RegWriteString(hkKey, vcszMaxVersionValue, wzMaxVersion);
425 - ExitOnFailure(hr, "Failed to set the %ls registry value to \"%ls\".", vcszMaxVersionValue, wzMaxVersion);
440 + DepExitOnFailure(hr, "Failed to set the %ls registry value to \"%ls\".", vcszMaxVersionValue, wzMaxVersion);
441
442 // Set the attributes if non-zero.
443 if (0 != iAttributes)
444 {
445 hr = RegWriteNumber(hkKey, vcszAttributesValue, static_cast<DWORD>(iAttributes));
431 - ExitOnFailure(hr, "Failed to set the %ls registry value to %d.", vcszAttributesValue, iAttributes);
446 + DepExitOnFailure(hr, "Failed to set the %ls registry value to %d.", vcszAttributesValue, iAttributes);
447 }
448
449 LExit:
@@ -451,13 +466,13 @@ DAPI_(HRESULT) DepUnregisterDependency(
466
467 // Format the provider dependency registry key.
468 hr = AllocDependencyKeyName(wzProviderKey, &sczKey);
454 - ExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzProviderKey);
469 + DepExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzProviderKey);
470
471 // Delete the entire key including all sub-keys.
472 hr = RegDelete(hkHive, sczKey, REG_KEY_DEFAULT, TRUE);
473 if (E_FILENOTFOUND != hr)
474 {
460 - ExitOnFailure(hr, "Failed to delete the key \"%ls\".", sczKey);
475 + DepExitOnFailure(hr, "Failed to delete the key \"%ls\".", sczKey);
476 }
477
478 LExit:
@@ -484,7 +499,7 @@ DAPI_(HRESULT) DepUnregisterDependent(
499 hr = RegOpen(hkHive, vsczRegistryRoot, KEY_READ, &hkRegistryRoot);
500 if (E_FILENOTFOUND != hr)
501 {
487 - ExitOnFailure(hr, "Failed to open root registry key \"%ls\".", vsczRegistryRoot);
502 + DepExitOnFailure(hr, "Failed to open root registry key \"%ls\".", vsczRegistryRoot);
503 }
504 else
505 {
@@ -495,7 +510,7 @@ DAPI_(HRESULT) DepUnregisterDependent(
510 hr = RegOpen(hkRegistryRoot, wzDependencyProviderKey, KEY_READ, &hkDependencyProviderKey);
511 if (E_FILENOTFOUND != hr)
512 {
498 - ExitOnFailure(hr, "Failed to open the registry key for the dependency \"%ls\".", wzDependencyProviderKey);
513 + DepExitOnFailure(hr, "Failed to open the registry key for the dependency \"%ls\".", wzDependencyProviderKey);
514 }
515 else
516 {
@@ -506,7 +521,7 @@ DAPI_(HRESULT) DepUnregisterDependent(
521 hr = RegOpen(hkDependencyProviderKey, vsczRegistryDependents, KEY_READ, &hkRegistryDependents);
522 if (E_FILENOTFOUND != hr)
523 {
509 - ExitOnFailure(hr, "Failed to open the dependents subkey under the dependency \"%ls\".", wzDependencyProviderKey);
524 + DepExitOnFailure(hr, "Failed to open the dependents subkey under the dependency \"%ls\".", wzDependencyProviderKey);
525 }
526 else
527 {
@@ -515,11 +530,11 @@ DAPI_(HRESULT) DepUnregisterDependent(
530
531 // Delete the wzProviderKey dependent sub-key.
532 hr = RegDelete(hkRegistryDependents, wzProviderKey, REG_KEY_DEFAULT, TRUE);
518 - ExitOnFailure(hr, "Failed to delete the dependent \"%ls\" under the dependency \"%ls\".", wzProviderKey, wzDependencyProviderKey);
533 + DepExitOnFailure(hr, "Failed to delete the dependent \"%ls\" under the dependency \"%ls\".", wzProviderKey, wzDependencyProviderKey);
534
535 // If there are no remaining dependents, delete the Dependents subkey.
536 hr = RegQueryKey(hkRegistryDependents, &cSubKeys, NULL);
522 - ExitOnFailure(hr, "Failed to get the number of dependent subkeys under the dependency \"%ls\".", wzDependencyProviderKey);
537 + DepExitOnFailure(hr, "Failed to get the number of dependent subkeys under the dependency \"%ls\".", wzDependencyProviderKey);
538
539 if (0 < cSubKeys)
540 {
@@ -531,11 +546,11 @@ DAPI_(HRESULT) DepUnregisterDependent(
546
547 // Fail if there are any subkeys since we just checked.
548 hr = RegDelete(hkDependencyProviderKey, vsczRegistryDependents, REG_KEY_DEFAULT, FALSE);
534 - ExitOnFailure(hr, "Failed to delete the dependents subkey under the dependency \"%ls\".", wzDependencyProviderKey);
549 + DepExitOnFailure(hr, "Failed to delete the dependents subkey under the dependency \"%ls\".", wzDependencyProviderKey);
550
551 // If there are no values, delete the provider dependency key.
552 hr = RegQueryKey(hkDependencyProviderKey, NULL, &cValues);
538 - ExitOnFailure(hr, "Failed to get the number of values under the dependency \"%ls\".", wzDependencyProviderKey);
553 + DepExitOnFailure(hr, "Failed to get the number of values under the dependency \"%ls\".", wzDependencyProviderKey);
554
555 if (0 == cValues)
556 {
@@ -544,7 +559,7 @@ DAPI_(HRESULT) DepUnregisterDependent(
559
560 // Fail if there are any subkeys since we just checked.
561 hr = RegDelete(hkRegistryRoot, wzDependencyProviderKey, REG_KEY_DEFAULT, FALSE);
547 - ExitOnFailure(hr, "Failed to delete the dependency \"%ls\".", wzDependencyProviderKey);
562 + DepExitOnFailure(hr, "Failed to delete the dependency \"%ls\".", wzDependencyProviderKey);
563 }
564
565 LExit:
@@ -567,21 +582,21 @@ DAPI_(HRESULT) DepDependencyArrayAlloc(
582 DEPENDENCY* pDependency = NULL;
583
584 hr = ::UIntAdd(*pcDependencies, 1, &cRequired);
570 - ExitOnFailure(hr, "Failed to increment the number of elements required in the dependency array.");
585 + DepExitOnFailure(hr, "Failed to increment the number of elements required in the dependency array.");
586
587 hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(prgDependencies), cRequired, sizeof(DEPENDENCY), ARRAY_GROWTH_SIZE);
573 - ExitOnFailure(hr, "Failed to allocate memory for the dependency array.");
588 + DepExitOnFailure(hr, "Failed to allocate memory for the dependency array.");
589
590 pDependency = static_cast<DEPENDENCY*>(&(*prgDependencies)[*pcDependencies]);
576 - ExitOnNull(pDependency, hr, E_POINTER, "The dependency element in the array is invalid.");
591 + DepExitOnNull(pDependency, hr, E_POINTER, "The dependency element in the array is invalid.");
592
593 hr = StrAllocString(&(pDependency->sczKey), wzKey, 0);
579 - ExitOnFailure(hr, "Failed to allocate the string key in the dependency array.");
594 + DepExitOnFailure(hr, "Failed to allocate the string key in the dependency array.");
595
596 if (wzName)
597 {
598 hr = StrAllocString(&(pDependency->sczName), wzName, 0);
584 - ExitOnFailure(hr, "Failed to allocate the string name in the dependency array.");
599 + DepExitOnFailure(hr, "Failed to allocate the string name in the dependency array.");
600 }
601
602 // Update the number of current elements in the dependency array.
@@ -623,18 +638,18 @@ static HRESULT AllocDependencyKeyName(
638
639 // Get the length of the dependency, and add to the length of the root.
640 hr = ::StringCchLengthW(wzName, STRSAFE_MAX_CCH, &cchName);
626 - ExitOnFailure(hr, "Failed to get string length of dependency name.");
641 + DepExitOnFailure(hr, "Failed to get string length of dependency name.");
642
643 // Add the sizes together to allocate memory once (callee will add space for nul).
644 hr = ::SizeTAdd(cchRegistryRoot, cchName, &cchKeyName);
630 - ExitOnFailure(hr, "Failed to add the string lengths together.");
645 + DepExitOnFailure(hr, "Failed to add the string lengths together.");
646
647 // Allocate and concat the strings together.
648 hr = StrAllocString(psczKeyName, vsczRegistryRoot, cchKeyName);
634 - ExitOnFailure(hr, "Failed to allocate string for dependency registry root.");
649 + DepExitOnFailure(hr, "Failed to allocate string for dependency registry root.");
650
651 hr = StrAllocConcat(psczKeyName, wzName, cchName);
637 - ExitOnFailure(hr, "Failed to concatenate the dependency key name.");
652 + DepExitOnFailure(hr, "Failed to concatenate the dependency key name.");
653
654 LExit:
655 return hr;
@@ -656,13 +671,13 @@ static HRESULT GetDependencyNameFromKey(
671
672 // Format the provider dependency registry key.
673 hr = AllocDependencyKeyName(wzProviderKey, &sczKey);
659 - ExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzProviderKey);
674 + DepExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzProviderKey);
675
676 // Try to open the dependency key.
677 hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey);
678 if (E_FILENOTFOUND != hr)
679 {
665 - ExitOnFailure(hr, "Failed to open the registry key for the dependency \"%ls\".", wzProviderKey);
680 + DepExitOnFailure(hr, "Failed to open the registry key for the dependency \"%ls\".", wzProviderKey);
681 }
682 else
683 {
@@ -673,7 +688,7 @@ static HRESULT GetDependencyNameFromKey(
688 hr = RegReadString(hkKey, vcszDisplayNameValue, psczName);
689 if (E_FILENOTFOUND != hr)
690 {
676 - ExitOnFailure(hr, "Failed to get the dependency name for the dependency \"%ls\".", wzProviderKey);
691 + DepExitOnFailure(hr, "Failed to get the dependency name for the dependency \"%ls\".", wzProviderKey);
692 }
693 else
694 {
src/dutil/dictutil.cpp
+63 -48
@@ -2,6 +2,21 @@
2
3 #include "precomp.h"
4
5 +
6 +// Exit macros
7 +#define DictExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_DICTUTIL, x, s, __VA_ARGS__)
8 +#define DictExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_DICTUTIL, x, s, __VA_ARGS__)
9 +#define DictExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_DICTUTIL, x, s, __VA_ARGS__)
10 +#define DictExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_DICTUTIL, x, s, __VA_ARGS__)
11 +#define DictExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_DICTUTIL, x, s, __VA_ARGS__)
12 +#define DictExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_DICTUTIL, x, s, __VA_ARGS__)
13 +#define DictExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_DICTUTIL, p, x, e, s, __VA_ARGS__)
14 +#define DictExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_DICTUTIL, p, x, s, __VA_ARGS__)
15 +#define DictExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_DICTUTIL, p, x, e, s, __VA_ARGS__)
16 +#define DictExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_DICTUTIL, p, x, s, __VA_ARGS__)
17 +#define DictExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_DICTUTIL, e, x, s, __VA_ARGS__)
18 +#define DictExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_DICTUTIL, g, x, s, __VA_ARGS__)
19 +
20 // These should all be primes, and spaced reasonably apart (currently each is about 4x the last)
21 const DWORD MAX_BUCKET_SIZES[] = {
22 503,
@@ -61,7 +76,7 @@ static HRESULT StringHash(
76 __in const STRINGDICT_STRUCT *psd,
77 __in DWORD dwNumBuckets,
78 __in_z LPCWSTR pszString,
64 - __out LPDWORD pdwHash
79 + __out DWORD *pdwHash
80 );
81 static BOOL IsMatchExact(
82 __in const STRINGDICT_STRUCT *psd,
@@ -122,11 +137,11 @@ extern "C" HRESULT DAPI DictCreateWithEmbeddedKey(
137 {
138 HRESULT hr = S_OK;
139
125 - ExitOnNull(psdHandle, hr, E_INVALIDARG, "Handle not specified while creating dict");
140 + DictExitOnNull(psdHandle, hr, E_INVALIDARG, "Handle not specified while creating dict");
141
142 // Allocate the handle
143 *psdHandle = static_cast<STRINGDICT_HANDLE>(MemAlloc(sizeof(STRINGDICT_STRUCT), FALSE));
129 - ExitOnNull(*psdHandle, hr, E_OUTOFMEMORY, "Failed to allocate dictionary object");
144 + DictExitOnNull(*psdHandle, hr, E_OUTOFMEMORY, "Failed to allocate dictionary object");
145
146 STRINGDICT_STRUCT *psd = static_cast<STRINGDICT_STRUCT *>(*psdHandle);
147
@@ -151,7 +166,7 @@ extern "C" HRESULT DAPI DictCreateWithEmbeddedKey(
166
167 // Finally, allocate our initial buckets
168 psd->ppvBuckets = static_cast<void**>(MemAlloc(sizeof(void *) * MAX_BUCKET_SIZES[psd->dwBucketSizeIndex], TRUE));
154 - ExitOnNull(psd->ppvBuckets, hr, E_OUTOFMEMORY, "Failed to allocate buckets for dictionary");
169 + DictExitOnNull(psd->ppvBuckets, hr, E_OUTOFMEMORY, "Failed to allocate buckets for dictionary");
170
171 LExit:
172 return hr;
@@ -166,11 +181,11 @@ extern "C" HRESULT DAPI DictCreateStringList(
181 {
182 HRESULT hr = S_OK;
183
169 - ExitOnNull(psdHandle, hr, E_INVALIDARG, "Handle not specified while creating dict");
184 + DictExitOnNull(psdHandle, hr, E_INVALIDARG, "Handle not specified while creating dict");
185
186 // Allocate the handle
187 *psdHandle = static_cast<STRINGDICT_HANDLE>(MemAlloc(sizeof(STRINGDICT_STRUCT), FALSE));
173 - ExitOnNull(*psdHandle, hr, E_OUTOFMEMORY, "Failed to allocate dictionary object");
188 + DictExitOnNull(*psdHandle, hr, E_OUTOFMEMORY, "Failed to allocate dictionary object");
189
190 STRINGDICT_STRUCT *psd = static_cast<STRINGDICT_STRUCT *>(*psdHandle);
191
@@ -195,7 +210,7 @@ extern "C" HRESULT DAPI DictCreateStringList(
210
211 // Finally, allocate our initial buckets
212 psd->ppvBuckets = static_cast<void**>(MemAlloc(sizeof(void *) * MAX_BUCKET_SIZES[psd->dwBucketSizeIndex], TRUE));
198 - ExitOnNull(psd->ppvBuckets, hr, E_OUTOFMEMORY, "Failed to allocate buckets for dictionary");
213 + DictExitOnNull(psd->ppvBuckets, hr, E_OUTOFMEMORY, "Failed to allocate buckets for dictionary");
214
215 LExit:
216 return hr;
@@ -212,7 +227,7 @@ extern "C" HRESULT DAPI DictCreateStringListFromArray(
227 STRINGDICT_HANDLE sd = NULL;
228
229 hr = DictCreateStringList(&sd, cStringArray, dfFlags);
215 - ExitOnFailure(hr, "Failed to create the string dictionary.");
230 + DictExitOnFailure(hr, "Failed to create the string dictionary.");
231
232 for (DWORD i = 0; i < cStringArray; ++i)
233 {
@@ -221,12 +236,12 @@ extern "C" HRESULT DAPI DictCreateStringListFromArray(
236 hr = DictKeyExists(sd, wzKey);
237 if (E_NOTFOUND != hr)
238 {
224 - ExitOnFailure(hr, "Failed to check the string dictionary.");
239 + DictExitOnFailure(hr, "Failed to check the string dictionary.");
240 }
241 else
242 {
243 hr = DictAddKey(sd, wzKey);
229 - ExitOnFailure(hr, "Failed to add \"%ls\" to the string dictionary.", wzKey);
244 + DictExitOnFailure(hr, "Failed to add \"%ls\" to the string dictionary.", wzKey);
245 }
246 }
247
@@ -252,7 +267,7 @@ extern "C" HRESULT DAPI DictCompareStringListToArray(
267 hr = DictKeyExists(sdStringList, rgwzStringArray[i]);
268 if (E_NOTFOUND != hr)
269 {
255 - ExitOnFailure(hr, "Failed to check the string dictionary.");
270 + DictExitOnFailure(hr, "Failed to check the string dictionary.");
271 ExitFunction1(hr = S_OK);
272 }
273 }
@@ -273,19 +288,19 @@ extern "C" HRESULT DAPI DictAddKey(
288 DWORD dwIndex = 0;
289 STRINGDICT_STRUCT *psd = static_cast<STRINGDICT_STRUCT *>(sdHandle);
290
276 - ExitOnNull(sdHandle, hr, E_INVALIDARG, "Handle not specified while adding value to dict");
277 - ExitOnNull(pszString, hr, E_INVALIDARG, "String not specified while adding value to dict");
291 + DictExitOnNull(sdHandle, hr, E_INVALIDARG, "Handle not specified while adding value to dict");
292 + DictExitOnNull(pszString, hr, E_INVALIDARG, "String not specified while adding value to dict");
293
294 if (psd->dwBucketSizeIndex >= countof(MAX_BUCKET_SIZES))
295 {
296 hr = E_INVALIDARG;
282 - ExitOnFailure(hr, "Invalid dictionary - bucket size index is out of range");
297 + DictExitOnFailure(hr, "Invalid dictionary - bucket size index is out of range");
298 }
299
300 if (DICT_STRING_LIST != psd->dtType)
301 {
302 hr = E_INVALIDARG;
288 - ExitOnFailure(hr, "Tried to add key without value to wrong dictionary type! This dictionary type is: %d", psd->dtType);
303 + DictExitOnFailure(hr, "Tried to add key without value to wrong dictionary type! This dictionary type is: %d", psd->dtType);
304 }
305
306 if ((psd->dwNumItems + 1) >= MAX_BUCKET_SIZES[psd->dwBucketSizeIndex] / MAX_BUCKETS_TO_ITEMS_RATIO)
@@ -299,18 +314,18 @@ extern "C" HRESULT DAPI DictAddKey(
314 hr = S_OK;
315 }
316 }
302 - ExitOnFailure(hr, "Failed to grow dictionary");
317 + DictExitOnFailure(hr, "Failed to grow dictionary");
318 }
319
320 hr = GetInsertIndex(psd, MAX_BUCKET_SIZES[psd->dwBucketSizeIndex], psd->ppvBuckets, pszString, &dwIndex);
306 - ExitOnFailure(hr, "Failed to get index to insert into");
321 + DictExitOnFailure(hr, "Failed to get index to insert into");
322
323 hr = MemEnsureArraySize(reinterpret_cast<void **>(&(psd->ppvItemList)), psd->dwNumItems + 1, sizeof(void *), 1000);
309 - ExitOnFailure(hr, "Failed to resize list of items in dictionary");
324 + DictExitOnFailure(hr, "Failed to resize list of items in dictionary");
325 ++psd->dwNumItems;
326
327 hr = StrAllocString(reinterpret_cast<LPWSTR *>(&(psd->ppvBuckets[dwIndex])), pszString, 0);
313 - ExitOnFailure(hr, "Failed to allocate copy of string");
328 + DictExitOnFailure(hr, "Failed to allocate copy of string");
329
330 psd->ppvItemList[psd->dwNumItems-1] = psd->ppvBuckets[dwIndex];
331
@@ -330,23 +345,23 @@ extern "C" HRESULT DAPI DictAddValue(
345 DWORD dwIndex = 0;
346 STRINGDICT_STRUCT *psd = static_cast<STRINGDICT_STRUCT *>(sdHandle);
347
333 - ExitOnNull(sdHandle, hr, E_INVALIDARG, "Handle not specified while adding value to dict");
334 - ExitOnNull(pvValue, hr, E_INVALIDARG, "Value not specified while adding value to dict");
348 + DictExitOnNull(sdHandle, hr, E_INVALIDARG, "Handle not specified while adding value to dict");
349 + DictExitOnNull(pvValue, hr, E_INVALIDARG, "Value not specified while adding value to dict");
350
351 if (psd->dwBucketSizeIndex >= countof(MAX_BUCKET_SIZES))
352 {
353 hr = E_INVALIDARG;
339 - ExitOnFailure(hr, "Invalid dictionary - bucket size index is out of range");
354 + DictExitOnFailure(hr, "Invalid dictionary - bucket size index is out of range");
355 }
356
357 if (DICT_EMBEDDED_KEY != psd->dtType)
358 {
359 hr = E_INVALIDARG;
345 - ExitOnFailure(hr, "Tried to add key/value pair to wrong dictionary type! This dictionary type is: %d", psd->dtType);
360 + DictExitOnFailure(hr, "Tried to add key/value pair to wrong dictionary type! This dictionary type is: %d", psd->dtType);
361 }
362
363 wzKey = GetKey(psd, pvValue);
349 - ExitOnNull(wzKey, hr, E_INVALIDARG, "String not specified while adding value to dict");
364 + DictExitOnNull(wzKey, hr, E_INVALIDARG, "String not specified while adding value to dict");
365
366 if ((psd->dwNumItems + 1) >= MAX_BUCKET_SIZES[psd->dwBucketSizeIndex] / MAX_BUCKETS_TO_ITEMS_RATIO)
367 {
@@ -359,14 +374,14 @@ extern "C" HRESULT DAPI DictAddValue(
374 hr = S_OK;
375 }
376 }
362 - ExitOnFailure(hr, "Failed to grow dictionary");
377 + DictExitOnFailure(hr, "Failed to grow dictionary");
378 }
379
380 hr = GetInsertIndex(psd, MAX_BUCKET_SIZES[psd->dwBucketSizeIndex], psd->ppvBuckets, wzKey, &dwIndex);
366 - ExitOnFailure(hr, "Failed to get index to insert into");
381 + DictExitOnFailure(hr, "Failed to get index to insert into");
382
383 hr = MemEnsureArraySize(reinterpret_cast<void **>(&(psd->ppvItemList)), psd->dwNumItems + 1, sizeof(void *), 1000);
369 - ExitOnFailure(hr, "Failed to resize list of items in dictionary");
384 + DictExitOnFailure(hr, "Failed to resize list of items in dictionary");
385 ++psd->dwNumItems;
386
387 pvOffset = TranslateValueToOffset(psd, pvValue);
@@ -385,15 +400,15 @@ extern "C" HRESULT DAPI DictGetValue(
400 {
401 HRESULT hr = S_OK;
402
388 - ExitOnNull(sdHandle, hr, E_INVALIDARG, "Handle not specified while searching dict");
389 - ExitOnNull(pszString, hr, E_INVALIDARG, "String not specified while searching dict");
403 + DictExitOnNull(sdHandle, hr, E_INVALIDARG, "Handle not specified while searching dict");
404 + DictExitOnNull(pszString, hr, E_INVALIDARG, "String not specified while searching dict");
405
406 const STRINGDICT_STRUCT *psd = static_cast<const STRINGDICT_STRUCT *>(sdHandle);
407
408 if (DICT_EMBEDDED_KEY != psd->dtType)
409 {
410 hr = E_INVALIDARG;
396 - ExitOnFailure(hr, "Tried to lookup value in wrong dictionary type! This dictionary type is: %d", psd->dtType);
411 + DictExitOnFailure(hr, "Tried to lookup value in wrong dictionary type! This dictionary type is: %d", psd->dtType);
412 }
413
414 hr = GetValue(psd, pszString, ppvValue);
@@ -401,7 +416,7 @@ extern "C" HRESULT DAPI DictGetValue(
416 {
417 ExitFunction();
418 }
404 - ExitOnFailure(hr, "Failed to call internal GetValue()");
419 + DictExitOnFailure(hr, "Failed to call internal GetValue()");
420
421 LExit:
422 return hr;
@@ -414,8 +429,8 @@ extern "C" HRESULT DAPI DictKeyExists(
429 {
430 HRESULT hr = S_OK;
431
417 - ExitOnNull(sdHandle, hr, E_INVALIDARG, "Handle not specified while searching dict");
418 - ExitOnNull(pszString, hr, E_INVALIDARG, "String not specified while searching dict");
432 + DictExitOnNull(sdHandle, hr, E_INVALIDARG, "Handle not specified while searching dict");
433 + DictExitOnNull(pszString, hr, E_INVALIDARG, "String not specified while searching dict");
434
435 const STRINGDICT_STRUCT *psd = static_cast<const STRINGDICT_STRUCT *>(sdHandle);
436
@@ -425,7 +440,7 @@ extern "C" HRESULT DAPI DictKeyExists(
440 {
441 ExitFunction();
442 }
428 - ExitOnFailure(hr, "Failed to call internal GetValue()");
443 + DictExitOnFailure(hr, "Failed to call internal GetValue()");
444
445 LExit:
446 return hr;
@@ -467,7 +482,7 @@ static HRESULT StringHash(
482 if (DICT_FLAG_CASEINSENSITIVE & psd->dfFlags)
483 {
484 hr = StrAllocStringToUpperInvariant(&sczNewKey, pszString, 0);
470 - ExitOnFailure(hr, "Failed to convert the string to upper-case.");
485 + DictExitOnFailure(hr, "Failed to convert the string to upper-case.");
486
487 wzKey = sczNewKey;
488 }
@@ -522,17 +537,17 @@ static HRESULT GetValue(
537 void *pvCandidateValue = NULL;
538 DWORD dwIndex = 0;
539
525 - ExitOnNull(psd, hr, E_INVALIDARG, "Handle not specified while searching dict");
526 - ExitOnNull(pszString, hr, E_INVALIDARG, "String not specified while searching dict");
540 + DictExitOnNull(psd, hr, E_INVALIDARG, "Handle not specified while searching dict");
541 + DictExitOnNull(pszString, hr, E_INVALIDARG, "String not specified while searching dict");
542
543 if (psd->dwBucketSizeIndex >= countof(MAX_BUCKET_SIZES))
544 {
545 hr = E_INVALIDARG;
531 - ExitOnFailure(hr, "Invalid dictionary - bucket size index is out of range");
546 + DictExitOnFailure(hr, "Invalid dictionary - bucket size index is out of range");
547 }
548
549 hr = StringHash(psd, MAX_BUCKET_SIZES[psd->dwBucketSizeIndex], pszString, &dwOriginalIndexCandidate);
535 - ExitOnFailure(hr, "Failed to hash the string.");
550 + DictExitOnFailure(hr, "Failed to hash the string.");
551
552 DWORD dwIndexCandidate = dwOriginalIndexCandidate;
553
@@ -553,7 +568,7 @@ static HRESULT GetValue(
568 {
569 ExitFunction();
570 }
556 - ExitOnFailure(hr, "Failed to find index to get");
571 + DictExitOnFailure(hr, "Failed to find index to get");
572
573 if (NULL != ppvValue)
574 {
@@ -581,7 +596,7 @@ static HRESULT GetInsertIndex(
596 DWORD dwOriginalIndexCandidate = 0;
597
598 hr = StringHash(psd, dwBucketCount, pszString, &dwOriginalIndexCandidate);
584 - ExitOnFailure(hr, "Failed to hash the string.");
599 + DictExitOnFailure(hr, "Failed to hash the string.");
600
601 DWORD dwIndexCandidate = dwOriginalIndexCandidate;
602
@@ -604,7 +619,7 @@ static HRESULT GetInsertIndex(
619 {
620 // The dict table is full - this error seems to be a reasonably close match
621 hr = HRESULT_FROM_WIN32(ERROR_DATABASE_FULL);
607 - ExitOnRootFailure(hr, "Failed to add item '%ls' to dict table because dict table is full of items", pszString);
622 + DictExitOnRootFailure(hr, "Failed to add item '%ls' to dict table because dict table is full of items", pszString);
623 }
624 }
625
@@ -626,11 +641,11 @@ static HRESULT GetIndex(
641 if (psd->dwBucketSizeIndex >= countof(MAX_BUCKET_SIZES))
642 {
643 hr = E_INVALIDARG;
629 - ExitOnFailure(hr, "Invalid dictionary - bucket size index is out of range");
644 + DictExitOnFailure(hr, "Invalid dictionary - bucket size index is out of range");
645 }
646
647 hr = StringHash(psd, MAX_BUCKET_SIZES[psd->dwBucketSizeIndex], pszString, &dwOriginalIndexCandidate);
633 - ExitOnFailure(hr, "Failed to hash the string.");
648 + DictExitOnFailure(hr, "Failed to hash the string.");
649
650 DWORD dwIndexCandidate = dwOriginalIndexCandidate;
651
@@ -704,18 +719,18 @@ static HRESULT GrowDictionary(
719 }
720
721 hr = ::SizeTMult(sizeof(void *), MAX_BUCKET_SIZES[dwNewBucketSizeIndex], &cbAllocSize);
707 - ExitOnFailure(hr, "Overflow while calculating allocation size to grow dictionary");
722 + DictExitOnFailure(hr, "Overflow while calculating allocation size to grow dictionary");
723
724 ppvNewBuckets = static_cast<void**>(MemAlloc(cbAllocSize, TRUE));
710 - ExitOnNull(ppvNewBuckets, hr, E_OUTOFMEMORY, "Failed to allocate %u buckets while growing dictionary", MAX_BUCKET_SIZES[dwNewBucketSizeIndex]);
725 + DictExitOnNull(ppvNewBuckets, hr, E_OUTOFMEMORY, "Failed to allocate %u buckets while growing dictionary", MAX_BUCKET_SIZES[dwNewBucketSizeIndex]);
726
727 for (DWORD i = 0; i < psd->dwNumItems; ++i)
728 {
729 wzKey = GetKey(psd, TranslateOffsetToValue(psd, psd->ppvItemList[i]));
715 - ExitOnNull(wzKey, hr, E_INVALIDARG, "String not specified in existing dict value");
730 + DictExitOnNull(wzKey, hr, E_INVALIDARG, "String not specified in existing dict value");
731
732 hr = GetInsertIndex(psd, MAX_BUCKET_SIZES[dwNewBucketSizeIndex], ppvNewBuckets, wzKey, &dwInsertIndex);
718 - ExitOnFailure(hr, "Failed to get index to insert into");
733 + DictExitOnFailure(hr, "Failed to get index to insert into");
734
735 ppvNewBuckets[dwInsertIndex] = psd->ppvItemList[i];
736 }
src/dutil/dirutil.cpp
+38 -23
@@ -3,6 +3,21 @@
3 #include "precomp.h"
4
5
6 +// Exit macros
7 +#define DirExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_DIRUTIL, x, s, __VA_ARGS__)
8 +#define DirExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_DIRUTIL, x, s, __VA_ARGS__)
9 +#define DirExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_DIRUTIL, x, s, __VA_ARGS__)
10 +#define DirExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_DIRUTIL, x, s, __VA_ARGS__)
11 +#define DirExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_DIRUTIL, x, s, __VA_ARGS__)
12 +#define DirExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_DIRUTIL, x, s, __VA_ARGS__)
13 +#define DirExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_DIRUTIL, p, x, e, s, __VA_ARGS__)
14 +#define DirExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_DIRUTIL, p, x, s, __VA_ARGS__)
15 +#define DirExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_DIRUTIL, p, x, e, s, __VA_ARGS__)
16 +#define DirExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_DIRUTIL, p, x, s, __VA_ARGS__)
17 +#define DirExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_DIRUTIL, e, x, s, __VA_ARGS__)
18 +#define DirExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_DIRUTIL, g, x, s, __VA_ARGS__)
19 +
20 +
21 /*******************************************************************
22 DirExists
23
@@ -59,12 +74,12 @@ extern "C" HRESULT DAPI DirCreateTempPath(
74 cch = ::GetTempPathW(countof(wzDir), wzDir);
75 if (!cch || cch >= countof(wzDir))
76 {
62 - ExitWithLastError(hr, "Failed to GetTempPath.");
77 + DirExitWithLastError(hr, "Failed to GetTempPath.");
78 }
79
80 if (!::GetTempFileNameW(wzDir, wzPrefix, 0, wzFile))
81 {
67 - ExitWithLastError(hr, "Failed to GetTempFileName.");
82 + DirExitWithLastError(hr, "Failed to GetTempFileName.");
83 }
84
85 hr = ::StringCchCopyW(wzPath, cchPath, wzFile);
@@ -111,12 +126,12 @@ extern "C" HRESULT DAPI DirEnsureExists(
126 }
127
128 // if there is no parent directory fail
114 - ExitOnNullDebugTrace(pwzLastSlash, hr, HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "cannot find parent path");
129 + DirExitOnNullDebugTrace(pwzLastSlash, hr, HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "cannot find parent path");
130
131 *pwzLastSlash = L'\0'; // null terminate the parent path
132 hr = DirEnsureExists(wzPath, psa); // recurse!
133 *pwzLastSlash = L'\\'; // put the slash back
119 - ExitOnFailureDebugTrace(hr, "failed to create path: %ls", wzPath);
134 + DirExitOnFailureDebugTrace(hr, "failed to create path: %ls", wzPath);
135
136 // try to create the directory now that all parents are created
137 if (!::CreateDirectoryW(wzPath, psa))
@@ -197,7 +212,7 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx(
212 er = ERROR_PATH_NOT_FOUND;
213 }
214 hr = HRESULT_FROM_WIN32(er);
200 - ExitOnRootFailure(hr, "Failed to get attributes for path: %ls", wzPath);
215 + DirExitOnRootFailure(hr, "Failed to get attributes for path: %ls", wzPath);
216 }
217
218 if (dwAttrib & FILE_ATTRIBUTE_DIRECTORY)
@@ -206,7 +221,7 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx(
221 {
222 if (!::SetFileAttributesW(wzPath, FILE_ATTRIBUTE_NORMAL))
223 {
209 - ExitWithLastError(hr, "Failed to remove read-only attribute from path: %ls", wzPath);
224 + DirExitWithLastError(hr, "Failed to remove read-only attribute from path: %ls", wzPath);
225 }
226 }
227
@@ -217,18 +232,18 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx(
232 {
233 if (!::GetTempPathW(countof(wzTempDirectory), wzTempDirectory))
234 {
220 - ExitWithLastError(hr, "Failed to get temp directory.");
235 + DirExitWithLastError(hr, "Failed to get temp directory.");
236 }
237 }
238
239 // Delete everything in this directory.
240 hr = PathConcat(wzPath, L"*.*", &sczDelete);
226 - ExitOnFailure(hr, "Failed to concat wild cards to string: %ls", wzPath);
241 + DirExitOnFailure(hr, "Failed to concat wild cards to string: %ls", wzPath);
242
243 hFind = ::FindFirstFileW(sczDelete, &wfd);
244 if (INVALID_HANDLE_VALUE == hFind)
245 {
231 - ExitWithLastError(hr, "failed to get first file in directory: %ls", wzPath);
246 + DirExitWithLastError(hr, "failed to get first file in directory: %ls", wzPath);
247 }
248
249 do
@@ -243,18 +258,18 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx(
258 wfd.cFileName[MAX_PATH - 1] = L'\0';
259
260 hr = PathConcat(wzPath, wfd.cFileName, &sczDelete);
246 - ExitOnFailure(hr, "Failed to concat filename '%ls' to directory: %ls", wfd.cFileName, wzPath);
261 + DirExitOnFailure(hr, "Failed to concat filename '%ls' to directory: %ls", wfd.cFileName, wzPath);
262
263 if (fRecurse && wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
264 {
265 hr = PathBackslashTerminate(&sczDelete);
251 - ExitOnFailure(hr, "Failed to ensure path is backslash terminated: %ls", sczDelete);
266 + DirExitOnFailure(hr, "Failed to ensure path is backslash terminated: %ls", sczDelete);
267
268 hr = DirEnsureDeleteEx(sczDelete, dwFlags); // recursive call
269 if (FAILED(hr))
270 {
271 // if we failed to delete a subdirectory, keep trying to finish any remaining files
257 - ExitTraceSource(DUTIL_SOURCE_DEFAULT, hr, "Failed to delete subdirectory; continuing: %ls", sczDelete);
272 + ExitTraceSource(DUTIL_SOURCE_DIRUTIL, hr, "Failed to delete subdirectory; continuing: %ls", sczDelete);
273 hr = S_OK;
274 }
275 }
@@ -264,7 +279,7 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx(
279 {
280 if (!::SetFileAttributesW(sczDelete, FILE_ATTRIBUTE_NORMAL))
281 {
267 - ExitWithLastError(hr, "Failed to remove attributes from file: %ls", sczDelete);
282 + DirExitWithLastError(hr, "Failed to remove attributes from file: %ls", sczDelete);
283 }
284 }
285
@@ -274,7 +289,7 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx(
289 {
290 if (!::GetTempFileNameW(wzTempDirectory, L"DEL", 0, wzTempPath))
291 {
277 - ExitWithLastError(hr, "Failed to get temp file to move to.");
292 + DirExitWithLastError(hr, "Failed to get temp file to move to.");
293 }
294
295 // Try to move the file to the temp directory then schedule for delete,
@@ -290,7 +305,7 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx(
305 }
306 else
307 {
293 - ExitWithLastError(hr, "Failed to delete file: %ls", sczDelete);
308 + DirExitWithLastError(hr, "Failed to delete file: %ls", sczDelete);
309 }
310 }
311 }
@@ -303,7 +318,7 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx(
318 }
319 else
320 {
306 - ExitWithLastError(hr, "Failed while looping through files in directory: %ls", wzPath);
321 + DirExitWithLastError(hr, "Failed while looping through files in directory: %ls", wzPath);
322 }
323 }
324
@@ -318,13 +333,13 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx(
333 }
334 }
335
321 - ExitOnRootFailure(hr, "Failed to remove directory: %ls", wzPath);
336 + DirExitOnRootFailure(hr, "Failed to remove directory: %ls", wzPath);
337 }
338 }
339 else
340 {
341 hr = E_UNEXPECTED;
327 - ExitOnFailure(hr, "Directory delete cannot delete file: %ls", wzPath);
342 + DirExitOnFailure(hr, "Directory delete cannot delete file: %ls", wzPath);
343 }
344
345 Assert(S_OK == hr);
@@ -351,22 +366,22 @@ extern "C" HRESULT DAPI DirGetCurrent(
366 if (psczCurrentDirectory && *psczCurrentDirectory)
367 {
368 hr = StrMaxLength(*psczCurrentDirectory, &cch);
354 - ExitOnFailure(hr, "Failed to determine size of current directory.");
369 + DirExitOnFailure(hr, "Failed to determine size of current directory.");
370 }
371
372 DWORD cchRequired = ::GetCurrentDirectoryW(static_cast<DWORD>(cch), 0 == cch ? NULL : *psczCurrentDirectory);
373 if (0 == cchRequired)
374 {
360 - ExitWithLastError(hr, "Failed to get current directory.");
375 + DirExitWithLastError(hr, "Failed to get current directory.");
376 }
377 else if (cch < cchRequired)
378 {
379 hr = StrAlloc(psczCurrentDirectory, cchRequired);
365 - ExitOnFailure(hr, "Failed to allocate string for current directory.");
380 + DirExitOnFailure(hr, "Failed to allocate string for current directory.");
381
382 if (!::GetCurrentDirectoryW(cchRequired, *psczCurrentDirectory))
383 {
369 - ExitWithLastError(hr, "Failed to get current directory using allocated string.");
384 + DirExitWithLastError(hr, "Failed to get current directory using allocated string.");
385 }
386 }
387
@@ -387,7 +402,7 @@ extern "C" HRESULT DAPI DirSetCurrent(
402
403 if (!::SetCurrentDirectoryW(wzDirectory))
404 {
390 - ExitWithLastError(hr, "Failed to set current directory to: %ls", wzDirectory);
405 + DirExitWithLastError(hr, "Failed to set current directory to: %ls", wzDirectory);
406 }
407
408 LExit:
src/dutil/dlutil.cpp
+52 -37
@@ -5,6 +5,21 @@
5 #include <inetutil.h>
6 #include <uriutil.h>
7
8 +
9 +// Exit macros
10 +#define DlExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_DLUTIL, x, s, __VA_ARGS__)
11 +#define DlExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_DLUTIL, x, s, __VA_ARGS__)
12 +#define DlExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_DLUTIL, x, s, __VA_ARGS__)
13 +#define DlExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_DLUTIL, x, s, __VA_ARGS__)
14 +#define DlExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_DLUTIL, x, s, __VA_ARGS__)
15 +#define DlExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_DLUTIL, x, s, __VA_ARGS__)
16 +#define DlExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_DLUTIL, p, x, e, s, __VA_ARGS__)
17 +#define DlExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_DLUTIL, p, x, s, __VA_ARGS__)
18 +#define DlExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_DLUTIL, p, x, e, s, __VA_ARGS__)
19 +#define DlExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_DLUTIL, p, x, s, __VA_ARGS__)
20 +#define DlExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_DLUTIL, e, x, s, __VA_ARGS__)
21 +#define DlExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_DLUTIL, g, x, s, __VA_ARGS__)
22 +
23 static const DWORD64 DOWNLOAD_ENGINE_TWO_GIGABYTES = DWORD64(2) * 1024 * 1024 * 1024;
24 static LPCWSTR DOWNLOAD_ENGINE_ACCEPT_TYPES[] = { L"*/*", NULL };
25
@@ -41,7 +56,7 @@ static HRESULT DownloadResource(
56 static HRESULT AllocateRangeRequestHeader(
57 __in DWORD64 dw64ResumeOffset,
58 __in DWORD64 dw64ResourceLength,
44 - __deref_out_z LPWSTR* psczHeader
59 + __deref_inout_z LPWSTR* psczHeader
60 );
61 static HRESULT WriteToFile(
62 __in HINTERNET hUrl,
@@ -126,10 +141,10 @@ extern "C" HRESULT DAPI DownloadUrl(
141 // Copy the download source into a working variable to handle redirects then
142 // open the internet session.
143 hr = StrAllocString(&sczUrl, pDownloadSource->sczUrl, 0);
129 - ExitOnFailure(hr, "Failed to copy download source URL.");
144 + DlExitOnFailure(hr, "Failed to copy download source URL.");
145
146 hSession = ::InternetOpenW(L"Burn", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
132 - ExitOnNullWithLastError(hSession, hr, "Failed to open internet session");
147 + DlExitOnNullWithLastError(hSession, hr, "Failed to open internet session");
148
149 // Make a best effort to set the download timeouts to 2 minutes or whatever policy says.
150 PolcReadNumber(POLICY_BURN_REGISTRY_PATH, L"DownloadTimeout", 2 * 60, &dwTimeout);
@@ -143,14 +158,14 @@ extern "C" HRESULT DAPI DownloadUrl(
158
159 // Get the resource size and creation time from the internet.
160 hr = GetResourceMetadata(hSession, &sczUrl, pDownloadSource->sczUser, pDownloadSource->sczPassword, pAuthenticate, &dw64Size, &ftCreated);
146 - ExitOnFailure(hr, "Failed to get size and time for URL: %ls", sczUrl);
161 + DlExitOnFailure(hr, "Failed to get size and time for URL: %ls", sczUrl);
162
163 // Ignore failure to initialize resume because we will fall back to full download then
164 // download.
165 InitializeResume(wzDestinationPath, &sczResumePath, &hResumeFile, &dw64ResumeOffset);
166
167 hr = DownloadResource(hSession, &sczUrl, pDownloadSource->sczUser, pDownloadSource->sczPassword, wzDestinationPath, dw64AuthoredDownloadSize, dw64Size, dw64ResumeOffset, hResumeFile, pCache, pAuthenticate);
153 - ExitOnFailure(hr, "Failed to download URL: %ls", sczUrl);
168 + DlExitOnFailure(hr, "Failed to download URL: %ls", sczUrl);
169
170 // Cleanup the resume file because we successfully downloaded the whole file.
171 if (sczResumePath && *sczResumePath)
@@ -185,19 +200,19 @@ static HRESULT InitializeResume(
200 *pdw64ResumeOffset = 0;
201
202 hr = DownloadGetResumePath(wzDestinationPath, psczResumePath);
188 - ExitOnFailure(hr, "Failed to calculate resume path from working path: %ls", wzDestinationPath);
203 + DlExitOnFailure(hr, "Failed to calculate resume path from working path: %ls", wzDestinationPath);
204
205 hResumeFile = ::CreateFileW(*psczResumePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_DELETE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
206 if (INVALID_HANDLE_VALUE == hResumeFile)
207 {
193 - ExitWithLastError(hr, "Failed to create resume file: %ls", *psczResumePath);
208 + DlExitWithLastError(hr, "Failed to create resume file: %ls", *psczResumePath);
209 }
210
211 do
212 {
213 if (!::ReadFile(hResumeFile, reinterpret_cast<BYTE*>(pdw64ResumeOffset) + cbTotalReadResumeData, sizeof(DWORD64) - cbTotalReadResumeData, &cbReadData, NULL))
214 {
200 - ExitWithLastError(hr, "Failed to read resume file: %ls", *psczResumePath);
215 + DlExitWithLastError(hr, "Failed to read resume file: %ls", *psczResumePath);
216 }
217 cbTotalReadResumeData += cbReadData;
218 } while (cbReadData && sizeof(DWORD64) > cbTotalReadResumeData);
@@ -233,7 +248,7 @@ static HRESULT GetResourceMetadata(
248 LONGLONG llLength = 0;
249
250 hr = MakeRequest(hSession, psczUrl, L"HEAD", NULL, wzUser, wzPassword, pAuthenticate, &hConnect, &hUrl, &fRangeRequestsAccepted);
236 - ExitOnFailure(hr, "Failed to connect to URL: %ls", *psczUrl);
251 + DlExitOnFailure(hr, "Failed to connect to URL: %ls", *psczUrl);
252
253 hr = InternetGetSizeByHandle(hUrl, &llLength);
254 if (FAILED(hr))
@@ -286,12 +301,12 @@ static HRESULT DownloadResource(
301 hPayloadFile = ::CreateFileW(wzDestinationPath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_DELETE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
302 if (INVALID_HANDLE_VALUE == hPayloadFile)
303 {
289 - ExitWithLastError(hr, "Failed to create download destination file: %ls", wzDestinationPath);
304 + DlExitWithLastError(hr, "Failed to create download destination file: %ls", wzDestinationPath);
305 }
306
307 // Allocate a memory block on a page boundary in case we want to do optimal writing.
308 pbData = static_cast<BYTE*>(::VirtualAlloc(NULL, cbMaxData, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE));
294 - ExitOnNullWithLastError(pbData, hr, "Failed to allocate buffer to download files into.");
309 + DlExitOnNullWithLastError(pbData, hr, "Failed to allocate buffer to download files into.");
310
311 // Let's try downloading the file assuming that range requests are accepted. If range requests
312 // are not supported we'll have to start over and accept the fact that we only get one shot
@@ -300,13 +315,13 @@ static HRESULT DownloadResource(
315 while (fRangeRequestsAccepted && (0 == dw64ResourceLength || dw64ResumeOffset < dw64ResourceLength))
316 {
317 hr = AllocateRangeRequestHeader(dw64ResumeOffset, 0 == dw64ResourceLength ? dw64AuthoredResourceLength : dw64ResourceLength, &sczRangeRequestHeader);
303 - ExitOnFailure(hr, "Failed to allocate range request header.");
318 + DlExitOnFailure(hr, "Failed to allocate range request header.");
319
320 ReleaseNullInternet(hConnect);
321 ReleaseNullInternet(hUrl);
322
323 hr = MakeRequest(hSession, psczUrl, L"GET", sczRangeRequestHeader, wzUser, wzPassword, pAuthenticate, &hConnect, &hUrl, &fRangeRequestsAccepted);
309 - ExitOnFailure(hr, "Failed to request URL for download: %ls", *psczUrl);
324 + DlExitOnFailure(hr, "Failed to request URL for download: %ls", *psczUrl);
325
326 // If we didn't get the size of the resource from the initial "HEAD" request
327 // then let's try to get the size from this "GET" request.
@@ -335,7 +350,7 @@ static HRESULT DownloadResource(
350 }
351
352 hr = WriteToFile(hUrl, hPayloadFile, &dw64ResumeOffset, hResumeFile, dw64ResourceLength, pbData, cbMaxData, pCache);
338 - ExitOnFailure(hr, "Failed while reading from internet and writing to: %ls", wzDestinationPath);
353 + DlExitOnFailure(hr, "Failed while reading from internet and writing to: %ls", wzDestinationPath);
354 }
355
356 LExit:
@@ -354,7 +369,7 @@ LExit:
369 static HRESULT AllocateRangeRequestHeader(
370 __in DWORD64 dw64ResumeOffset,
371 __in DWORD64 dw64ResourceLength,
357 - __deref_out_z LPWSTR* psczHeader
372 + __deref_inout_z LPWSTR* psczHeader
373 )
374 {
375 HRESULT hr = S_OK;
@@ -368,7 +383,7 @@ static HRESULT AllocateRangeRequestHeader(
383 if (0 < dw64ResumeOffset)
384 {
385 hr = StrAllocFormatted(psczHeader, L"Range: bytes=%I64u-", dw64ResumeOffset);
371 - ExitOnFailure(hr, "Failed to add range read header.");
386 + DlExitOnFailure(hr, "Failed to add range read header.");
387 }
388 else
389 {
@@ -378,7 +393,7 @@ static HRESULT AllocateRangeRequestHeader(
393 else // we'll have to download in chunks.
394 {
395 hr = StrAllocFormatted(psczHeader, L"Range: bytes=%I64u-%I64u", dw64ResumeOffset, dw64ResumeOffset + dw64RemainingLength - 1);
381 - ExitOnFailure(hr, "Failed to add range read header.");
396 + DlExitOnFailure(hr, "Failed to add range read header.");
397 }
398
399 LExit:
@@ -400,14 +415,14 @@ static HRESULT WriteToFile(
415 DWORD cbReadData = 0;
416
417 hr = FileSetPointer(hPayloadFile, *pdw64ResumeOffset, NULL, FILE_BEGIN);
403 - ExitOnFailure(hr, "Failed to seek to start point in file.");
418 + DlExitOnFailure(hr, "Failed to seek to start point in file.");
419
420 do
421 {
422 // Read bits from the internet.
423 if (!::InternetReadFile(hUrl, static_cast<void*>(pbData), cbData, &cbReadData))
424 {
410 - ExitWithLastError(hr, "Failed while reading from internet.");
425 + DlExitWithLastError(hr, "Failed while reading from internet.");
426 }
427
428 // Write bits to disk (if there are any).
@@ -419,7 +434,7 @@ static HRESULT WriteToFile(
434 {
435 if (!::WriteFile(hPayloadFile, pbData + cbTotalWritten, cbReadData - cbTotalWritten, &cbWritten, NULL))
436 {
422 - ExitWithLastError(hr, "Failed to write data from internet.");
437 + DlExitWithLastError(hr, "Failed to write data from internet.");
438 }
439
440 cbTotalWritten += cbWritten;
@@ -431,7 +446,7 @@ static HRESULT WriteToFile(
446 if (pCallback && pCallback->pfnProgress)
447 {
448 hr = DownloadSendProgressCallback(pCallback, *pdw64ResumeOffset, dw64ResourceLength, hPayloadFile);
434 - ExitOnFailure(hr, "UX aborted on cache progress.");
449 + DlExitOnFailure(hr, "UX aborted on cache progress.");
450 }
451 }
452 } while (cbReadData);
@@ -456,14 +471,14 @@ static HRESULT UpdateResumeOffset(
471 DWORD cbWrittenResumeData = 0;
472
473 hr = FileSetPointer(hResumeFile, 0, NULL, FILE_BEGIN);
459 - ExitOnFailure(hr, "Failed to seek to start point in file.");
474 + DlExitOnFailure(hr, "Failed to seek to start point in file.");
475
476 do
477 {
478 // Ignore failure to write to the resume file as that should not prevent the download from happening.
479 if (!::WriteFile(hResumeFile, pdw64ResumeOffset + cbTotalWrittenResumeData, sizeof(DWORD64) - cbTotalWrittenResumeData, &cbWrittenResumeData, NULL))
480 {
466 - ExitOnFailure(hr, "Failed to seek to write to file.");
481 + DlExitOnFailure(hr, "Failed to seek to write to file.");
482 }
483
484 cbTotalWrittenResumeData += cbWrittenResumeData;
@@ -504,10 +519,10 @@ static HRESULT MakeRequest(
519
520 // Open the url.
521 hr = UriCrackEx(*psczSourceUrl, &uri);
507 - ExitOnFailure(hr, "Failed to break URL into server and resource parts.");
522 + DlExitOnFailure(hr, "Failed to break URL into server and resource parts.");
523
524 hConnect = ::InternetConnectW(hSession, uri.sczHostName, uri.port, (wzUser && *wzUser) ? wzUser : uri.sczUser, (wzPassword && *wzPassword) ? wzPassword : uri.sczPassword, INTERNET_SCHEME_FTP == uri.scheme ? INTERNET_SERVICE_FTP : INTERNET_SERVICE_HTTP, 0, 0);
510 - ExitOnNullWithLastError(hConnect, hr, "Failed to connect to URL: %ls", *psczSourceUrl);
525 + DlExitOnNullWithLastError(hConnect, hr, "Failed to connect to URL: %ls", *psczSourceUrl);
526
527 // Best effort set the proxy username and password, if they were provided.
528 if ((wzUser && *wzUser) && (wzPassword && *wzPassword))
@@ -519,10 +534,10 @@ static HRESULT MakeRequest(
534 }
535
536 hr = OpenRequest(hConnect, wzMethod, uri.scheme, uri.sczPath, uri.sczQueryString, wzHeaders, &hUrl);
522 - ExitOnFailure(hr, "Failed to open internet URL: %ls", *psczSourceUrl);
537 + DlExitOnFailure(hr, "Failed to open internet URL: %ls", *psczSourceUrl);
538
539 hr = SendRequest(hUrl, psczSourceUrl, pAuthenticate, &fRetry, pfRangeRequestsAccepted);
525 - ExitOnFailure(hr, "Failed to send request to URL: %ls", *psczSourceUrl);
540 + DlExitOnFailure(hr, "Failed to send request to URL: %ls", *psczSourceUrl);
541 } while (fRetry);
542
543 // Okay, we're all ready to start downloading. Update the connection information.
@@ -565,23 +580,23 @@ static HRESULT OpenRequest(
580
581 // Allocate the resource name.
582 hr = StrAllocString(&sczResource, wzResource, 0);
568 - ExitOnFailure(hr, "Failed to allocate string for resource URI.");
583 + DlExitOnFailure(hr, "Failed to allocate string for resource URI.");
584
585 if (wzQueryString && *wzQueryString)
586 {
587 hr = StrAllocConcat(&sczResource, wzQueryString, 0);
573 - ExitOnFailure(hr, "Failed to append query strong to resource from URI.");
588 + DlExitOnFailure(hr, "Failed to append query strong to resource from URI.");
589 }
590
591 // Open the request and add the header if provided.
592 hUrl = ::HttpOpenRequestW(hConnect, wzMethod, sczResource, NULL, NULL, DOWNLOAD_ENGINE_ACCEPT_TYPES, dwRequestFlags, NULL);
578 - ExitOnNullWithLastError(hUrl, hr, "Failed to open internet request.");
593 + DlExitOnNullWithLastError(hUrl, hr, "Failed to open internet request.");
594
595 if (wzHeader && *wzHeader)
596 {
597 if (!::HttpAddRequestHeadersW(hUrl, wzHeader, static_cast<DWORD>(-1), HTTP_ADDREQ_FLAG_COALESCE))
598 {
584 - ExitWithLastError(hr, "Failed to add header to HTTP request.");
599 + DlExitWithLastError(hr, "Failed to add header to HTTP request.");
600 }
601 }
602
@@ -618,12 +633,12 @@ static HRESULT SendRequest(
633 // Try to get the HTTP status code and, if good, handle via the switch statement below but if it
634 // fails return the error code from the send request above as the result of the function.
635 HRESULT hrQueryStatusCode = InternetQueryInfoNumber(hUrl, HTTP_QUERY_STATUS_CODE, &lCode);
621 - ExitOnFailure(hrQueryStatusCode, "Failed to get HTTP status code for failed request to URL: %ls", *psczUrl);
636 + DlExitOnFailure(hrQueryStatusCode, "Failed to get HTTP status code for failed request to URL: %ls", *psczUrl);
637 }
638 else // get the http status code.
639 {
640 hr = InternetQueryInfoNumber(hUrl, HTTP_QUERY_STATUS_CODE, &lCode);
626 - ExitOnFailure(hr, "Failed to get HTTP status code for request to URL: %ls", *psczUrl);
641 + DlExitOnFailure(hr, "Failed to get HTTP status code for request to URL: %ls", *psczUrl);
642 }
643
644 switch (lCode)
@@ -643,7 +658,7 @@ static HRESULT SendRequest(
658 case 302: __fallthrough; // temporary
659 case 303: // redirect method
660 hr = InternetQueryInfoString(hUrl, HTTP_QUERY_CONTENT_LOCATION, psczUrl);
646 - ExitOnFailure(hr, "Failed to get redirect url: %ls", *psczUrl);
661 + DlExitOnFailure(hr, "Failed to get redirect url: %ls", *psczUrl);
662
663 *pfRetry = TRUE;
664 break;
@@ -734,7 +749,7 @@ static HRESULT DownloadGetResumePath(
749 HRESULT hr = S_OK;
750
751 hr = StrAllocFormatted(psczResumePath, L"%ls.R", wzPayloadWorkingPath);
737 - ExitOnFailure(hr, "Failed to create resume path.");
752 + DlExitOnFailure(hr, "Failed to create resume path.");
753
754 LExit:
755 return hr;
@@ -769,7 +784,7 @@ static HRESULT DownloadSendProgressCallback(
784 case PROGRESS_CANCEL: __fallthrough; // TODO: should cancel and stop be treated differently?
785 case PROGRESS_STOP:
786 hr = HRESULT_FROM_WIN32(ERROR_INSTALL_USEREXIT);
772 - ExitOnRootFailure(hr, "UX aborted on download progress.");
787 + DlExitOnRootFailure(hr, "UX aborted on download progress.");
788
789 case PROGRESS_QUIET: // Not actually an error, just an indication to the caller to stop requesting progress.
790 pCallback->pfnProgress = NULL;
@@ -778,7 +793,7 @@ static HRESULT DownloadSendProgressCallback(
793
794 default:
795 hr = E_UNEXPECTED;
781 - ExitOnRootFailure(hr, "Invalid return code from progress routine.");
796 + DlExitOnRootFailure(hr, "Invalid return code from progress routine.");
797 }
798 }
799
src/dutil/dutil.cpp
+22 -7
@@ -2,6 +2,21 @@
2
3 #include "precomp.h"
4
5 +
6 +// Exit macros
7 +#define DExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_DUTIL, x, s, __VA_ARGS__)
8 +#define DExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_DUTIL, x, s, __VA_ARGS__)
9 +#define DExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_DUTIL, x, s, __VA_ARGS__)
10 +#define DExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_DUTIL, x, s, __VA_ARGS__)
11 +#define DExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_DUTIL, x, s, __VA_ARGS__)
12 +#define DExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_DUTIL, x, s, __VA_ARGS__)
13 +#define DExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_DUTIL, p, x, e, s, __VA_ARGS__)
14 +#define DExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_DUTIL, p, x, s, __VA_ARGS__)
15 +#define DExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_DUTIL, p, x, e, s, __VA_ARGS__)
16 +#define DExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_DUTIL, p, x, s, __VA_ARGS__)
17 +#define DExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_DUTIL, e, x, s, __VA_ARGS__)
18 +#define DExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_DUTIL, g, x, s, __VA_ARGS__)
19 +
20 // No need for OACR to warn us about using non-unicode APIs in this file.
21 #pragma prefast(disable:25068)
22
@@ -84,7 +99,7 @@ extern "C" void DAPI Dutil_AssertMsg(
99
100 char szMsg[DUTIL_STRING_BUFFER];
101 hr = ::StringCchCopyA(szMsg, countof(szMsg), szMessage);
87 - ExitOnFailure(hr, "failed to copy message while building assert message");
102 + DExitOnFailure(hr, "failed to copy message while building assert message");
103
104 if (Dutil_pfnDisplayAssert)
105 {
@@ -123,7 +138,7 @@ extern "C" void DAPI Dutil_AssertMsg(
138 if (ERROR_SUCCESS != er)
139 {
140 hr = ::StringCchCatA(szMsg, countof(szMsg), "\nAbort=Debug, Retry=Skip, Ignore=Skip all");
126 - ExitOnFailure(hr, "failed to concat string while building assert message");
141 + DExitOnFailure(hr, "failed to concat string while building assert message");
142
143 id = ::MessageBoxA(0, szMsg, "Debug Assert Message",
144 MB_SERVICE_NOTIFICATION | MB_TOPMOST |
@@ -480,24 +495,24 @@ extern "C" HRESULT DAPI LoadSystemLibraryWithPath(
495 WCHAR wzPath[MAX_PATH] = { };
496
497 cch = ::GetSystemDirectoryW(wzPath, MAX_PATH);
483 - ExitOnNullWithLastError(cch, hr, "Failed to get the Windows system directory.");
498 + DExitOnNullWithLastError(cch, hr, "Failed to get the Windows system directory.");
499
500 if (L'\\' != wzPath[cch - 1])
501 {
502 hr = ::StringCchCatNW(wzPath, MAX_PATH, L"\\", 1);
488 - ExitOnRootFailure(hr, "Failed to terminate the string with a backslash.");
503 + DExitOnRootFailure(hr, "Failed to terminate the string with a backslash.");
504 }
505
506 hr = ::StringCchCatW(wzPath, MAX_PATH, wzModuleName);
492 - ExitOnRootFailure(hr, "Failed to create the fully-qualified path to %ls.", wzModuleName);
507 + DExitOnRootFailure(hr, "Failed to create the fully-qualified path to %ls.", wzModuleName);
508
509 *phModule = ::LoadLibraryW(wzPath);
495 - ExitOnNullWithLastError(*phModule, hr, "Failed to load the library %ls.", wzModuleName);
510 + DExitOnNullWithLastError(*phModule, hr, "Failed to load the library %ls.", wzModuleName);
511
512 if (psczPath)
513 {
514 hr = StrAllocString(psczPath, wzPath, MAX_PATH);
500 - ExitOnFailure(hr, "Failed to copy the path to library.");
515 + DExitOnFailure(hr, "Failed to copy the path to library.");
516 }
517
518 LExit:
src/dutil/eseutil.cpp
+58 -43
@@ -2,6 +2,21 @@
2
3 #include "precomp.h"
4
5 +
6 +// Exit macros
7 +#define EseExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_ESEUTIL, x, s, __VA_ARGS__)
8 +#define EseExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_ESEUTIL, x, s, __VA_ARGS__)
9 +#define EseExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_ESEUTIL, x, s, __VA_ARGS__)
10 +#define EseExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_ESEUTIL, x, s, __VA_ARGS__)
11 +#define EseExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_ESEUTIL, x, s, __VA_ARGS__)
12 +#define EseExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_ESEUTIL, x, s, __VA_ARGS__)
13 +#define EseExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_ESEUTIL, p, x, e, s, __VA_ARGS__)
14 +#define EseExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_ESEUTIL, p, x, s, __VA_ARGS__)
15 +#define EseExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_ESEUTIL, p, x, e, s, __VA_ARGS__)
16 +#define EseExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_ESEUTIL, p, x, s, __VA_ARGS__)
17 +#define EseExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_ESEUTIL, e, x, s, __VA_ARGS__)
18 +#define EseExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_ESEUTIL, g, x, s, __VA_ARGS__)
19 +
20 struct ESE_QUERY
21 {
22 ESE_QUERY_TYPE qtQueryType;
@@ -85,13 +100,13 @@ HRESULT HresultFromJetError(JET_ERR jEr)
100 }
101
102 // Log the actual Jet error code so we have record of it before it's morphed into an HRESULT to be compatible with the rest of our code
88 - ExitTraceSource(DUTIL_SOURCE_DEFAULT, hr, "Encountered Jet Error: 0x%08x", jEr);
103 + ExitTraceSource(DUTIL_SOURCE_ESEUTIL, hr, "Encountered Jet Error: 0x%08x", jEr);
104
105 return hr;
106 }
107
93 -#define ExitOnJetFailure(e, x, s, ...) { x = HresultFromJetError(e); if (S_OK != x) { ExitTraceSource(DUTIL_SOURCE_DEFAULT, x, s, __VA_ARGS__); goto LExit; }}
94 -#define ExitOnRootJetFailure(e, x, s, ...) { x = HresultFromJetError(e); if (S_OK != x) { Dutil_RootFailure(__FILE__, __LINE__, x); ExitTraceSource(DUTIL_SOURCE_DEFAULT, x, s, __VA_ARGS__); goto LExit; }}
108 +#define ExitOnJetFailure(e, x, s, ...) { x = HresultFromJetError(e); if (S_OK != x) { ExitTraceSource(DUTIL_SOURCE_ESEUTIL, x, s, __VA_ARGS__); goto LExit; }}
109 +#define ExitOnRootJetFailure(e, x, s, ...) { x = HresultFromJetError(e); if (S_OK != x) { Dutil_RootFailure(__FILE__, __LINE__, x); ExitTraceSource(DUTIL_SOURCE_ESEUTIL, x, s, __VA_ARGS__); goto LExit; }}
110
111 HRESULT DAPI EseBeginSession(
112 __out JET_INSTANCE *pjiInstance,
@@ -106,15 +121,15 @@ HRESULT DAPI EseBeginSession(
121 LPSTR pszAnsiPath = NULL;
122
123 hr = DirEnsureExists(pszPath, NULL);
109 - ExitOnFailure(hr, "Failed to ensure database directory exists");
124 + EseExitOnFailure(hr, "Failed to ensure database directory exists");
125
126 // Sigh. JETblue requires Vista and up for the wide character version of this function, so we'll convert to ANSI before calling,
127 // likely breaking everyone with unicode characters in their path.
128 hr = StrAnsiAllocString(&pszAnsiInstance, pszInstance, 0, CP_ACP);
114 - ExitOnFailure(hr, "Failed converting instance name to ansi");
129 + EseExitOnFailure(hr, "Failed converting instance name to ansi");
130
131 hr = StrAnsiAllocString(&pszAnsiPath, pszPath, 0, CP_ACP);
117 - ExitOnFailure(hr, "Failed converting session path name to ansi");
132 + EseExitOnFailure(hr, "Failed converting session path name to ansi");
133
134 jEr = JetCreateInstanceA(pjiInstance, pszAnsiInstance);
135 ExitOnJetFailure(jEr, hr, "Failed to create instance");
@@ -173,17 +188,17 @@ HRESULT AllocColumnCreateStruct(
188 size_t cbAllocSize = 0;
189
190 hr = ::SizeTMult(ptsSchema->dwColumns, sizeof(JET_COLUMNCREATE), &(cbAllocSize));
176 - ExitOnFailure(hr, "Maximum allocation exceeded.");
191 + EseExitOnFailure(hr, "Maximum allocation exceeded.");
192
193 *ppjccColumnCreate = static_cast<JET_COLUMNCREATE*>(MemAlloc(cbAllocSize, TRUE));
179 - ExitOnNull(*ppjccColumnCreate, hr, E_OUTOFMEMORY, "Failed to allocate column create structure for database");
194 + EseExitOnNull(*ppjccColumnCreate, hr, E_OUTOFMEMORY, "Failed to allocate column create structure for database");
195
196 for (i = 0; i < ptsSchema->dwColumns; ++i)
197 {
198 (*ppjccColumnCreate)[i].cbStruct = sizeof(JET_COLUMNCREATE);
199
200 hr = StrAnsiAllocString(&(*ppjccColumnCreate)[i].szColumnName, ptsSchema->pcsColumns[i].pszName, 0, CP_ACP);
186 - ExitOnFailure(hr, "Failed to allocate ansi column name: %ls", ptsSchema->pcsColumns[i].pszName);
201 + EseExitOnFailure(hr, "Failed to allocate ansi column name: %ls", ptsSchema->pcsColumns[i].pszName);
202
203 (*ppjccColumnCreate)[i].coltyp = ptsSchema->pcsColumns[i].jcColumnType;
204
@@ -237,7 +252,7 @@ HRESULT FreeColumnCreateStruct(
252 }
253
254 hr = MemFree(pjccColumnCreate);
240 - ExitOnFailure(hr, "Failed to release core column create struct");
255 + EseExitOnFailure(hr, "Failed to release core column create struct");
256
257 LExit:
258 return hr;
@@ -261,20 +276,20 @@ HRESULT AllocIndexCreateStruct(
276 if (ptsSchema->pcsColumns[i].fKey)
277 {
278 hr = StrAnsiAllocString(&pszTempString, ptsSchema->pcsColumns[i].pszName, 0, CP_ACP);
264 - ExitOnFailure(hr, "Failed to convert string to ansi: %ls", ptsSchema->pcsColumns[i].pszName);
279 + EseExitOnFailure(hr, "Failed to convert string to ansi: %ls", ptsSchema->pcsColumns[i].pszName);
280
281 hr = StrAnsiAllocConcat(&pszMultiSzKeys, "+", 0);
267 - ExitOnFailure(hr, "Failed to append plus sign to multisz string: %s", pszTempString);
282 + EseExitOnFailure(hr, "Failed to append plus sign to multisz string: %s", pszTempString);
283
284 hr = StrAnsiAllocConcat(&pszMultiSzKeys, pszTempString, 0);
270 - ExitOnFailure(hr, "Failed to append column name to multisz string: %s", pszTempString);
285 + EseExitOnFailure(hr, "Failed to append column name to multisz string: %s", pszTempString);
286
287 ReleaseNullStr(pszTempString);
288
289 // All question marks will be converted to null characters later; this is just to trick dutil
290 // into letting us create an ansi, double-null-terminated list of single-null-terminated strings
291 hr = StrAnsiAllocConcat(&pszMultiSzKeys, "?", 0);
277 - ExitOnFailure(hr, "Failed to append placeholder character to multisz string: %ls", pszMultiSzKeys);
292 + EseExitOnFailure(hr, "Failed to append placeholder character to multisz string: %hs", pszMultiSzKeys);
293
294 // Record that at least one key column was found
295 fKeyColumns = TRUE;
@@ -288,18 +303,18 @@ HRESULT AllocIndexCreateStruct(
303 }
304
305 hr = StrAnsiAllocString(&pszIndexName, ptsSchema->pszName, 0, CP_ACP);
291 - ExitOnFailure(hr, "Failed to allocate ansi string version of %ls", ptsSchema->pszName);
306 + EseExitOnFailure(hr, "Failed to allocate ansi string version of %ls", ptsSchema->pszName);
307
308 hr = StrAnsiAllocConcat(&pszIndexName, "_Index", 0);
294 - ExitOnFailure(hr, "Failed to append table name string version of %ls", ptsSchema->pszName);
309 + EseExitOnFailure(hr, "Failed to append table name string version of %ls", ptsSchema->pszName);
310
311 *ppjicIndexCreate = static_cast<JET_INDEXCREATE*>(MemAlloc(sizeof(JET_INDEXCREATE), TRUE));
297 - ExitOnNull(*ppjicIndexCreate, hr, E_OUTOFMEMORY, "Failed to allocate index create structure for database");
312 + EseExitOnNull(*ppjicIndexCreate, hr, E_OUTOFMEMORY, "Failed to allocate index create structure for database");
313
314 // Record the size including both null terminators - the struct requires this
315 DWORD dwSize = 0;
316 dwSize = lstrlen(pszMultiSzKeys) + 1; // add 1 to include null character at the end
302 - ExitOnFailure(hr, "Failed to get size of keys string");
317 + EseExitOnFailure(hr, "Failed to get size of keys string");
318
319 // At this point convert all question marks to null characters
320 for (i = 0; i < dwSize; ++i)
@@ -349,7 +364,7 @@ HRESULT EnsureSchema(
364 jtTableCreate.cIndexes = 1;
365
366 hr = EseBeginTransaction(jsSession);
352 - ExitOnFailure(hr, "Failed to begin transaction to create tables");
367 + EseExitOnFailure(hr, "Failed to begin transaction to create tables");
368 fTransaction = TRUE;
369
370 for (dwTable = 0;dwTable < pdsSchema->dwTables; ++dwTable)
@@ -363,13 +378,13 @@ HRESULT EnsureSchema(
378 {
379 // Fill out the JET_TABLECREATE struct
380 hr = StrAnsiAllocString(&jtTableCreate.szTableName, pdsSchema->ptsTables[dwTable].pszName, 0, CP_ACP);
366 - ExitOnFailure(hr, "Failed converting table name to ansi");
381 + EseExitOnFailure(hr, "Failed converting table name to ansi");
382
383 hr = AllocColumnCreateStruct(&(pdsSchema->ptsTables[dwTable]), &jtTableCreate.rgcolumncreate);
369 - ExitOnFailure(hr, "Failed to allocate column create struct");
384 + EseExitOnFailure(hr, "Failed to allocate column create struct");
385
386 hr = AllocIndexCreateStruct(&(pdsSchema->ptsTables[dwTable]), &jtTableCreate.rgindexcreate);
372 - ExitOnFailure(hr, "Failed to allocate index create struct");
387 + EseExitOnFailure(hr, "Failed to allocate index create struct");
388
389 jtTableCreate.cColumns = pdsSchema->ptsTables[dwTable].dwColumns;
390 jtTableCreate.tableid = NULL;
@@ -392,7 +407,7 @@ HRESULT EnsureSchema(
407 ReleaseNullStr(jtTableCreate.szTableName);
408
409 hr = FreeColumnCreateStruct(jtTableCreate.rgcolumncreate, jtTableCreate.cColumns);
395 - ExitOnFailure(hr, "Failed to free column create struct");
410 + EseExitOnFailure(hr, "Failed to free column create struct");
411 jtTableCreate.rgcolumncreate = NULL;
412 }
413 else
@@ -422,7 +437,7 @@ HRESULT EnsureSchema(
437 }
438
439 hr = EseEnsureColumn(jsSession, pdsSchema->ptsTables[dwTable].jtTable, pcsColumn->pszName, pcsColumn->jcColumnType, ulColumnSize, pcsColumn->fFixed, fNullable, &pcsColumn->jcColumn);
425 - ExitOnFailure(hr, "Failed to create column %u of %ls table", dwColumn, pwzTableName);
440 + EseExitOnFailure(hr, "Failed to create column %u of %ls table", dwColumn, pwzTableName);
441 }
442 }
443 }
@@ -464,13 +479,13 @@ HRESULT DAPI EseEnsureDatabase(
479 // Sigh. JETblue requires Vista and up for the wide character version of this function, so we'll convert to ANSI before calling,
480 // likely breaking all those with unicode characters in their path.
481 hr = StrAnsiAllocString(&pszAnsiFile, pszFile, 0, CP_ACP);
467 - ExitOnFailure(hr, "Failed converting database name to ansi");
482 + EseExitOnFailure(hr, "Failed converting database name to ansi");
483
484 hr = PathGetDirectory(pszFile, &pszDir);
470 - ExitOnFailure(hr, "Failed to get directory that will contain database file");
485 + EseExitOnFailure(hr, "Failed to get directory that will contain database file");
486
487 hr = DirEnsureExists(pszDir, NULL);
473 - ExitOnFailure(hr, "Failed to ensure directory exists for database: %ls", pszDir);
488 + EseExitOnFailure(hr, "Failed to ensure directory exists for database: %ls", pszDir);
489
490 if (FileExistsEx(pszFile, NULL))
491 {
@@ -498,7 +513,7 @@ HRESULT DAPI EseEnsureDatabase(
513 }
514
515 hr = EnsureSchema(*pjdbDb, jsSession, pdsSchema);
501 - ExitOnFailure(hr, "Failed to ensure database schema matches expectations");
516 + EseExitOnFailure(hr, "Failed to ensure database schema matches expectations");
517
518 LExit:
519 ReleaseStr(pszDir);
@@ -535,7 +550,7 @@ HRESULT DAPI EseCreateTable(
550 LPSTR pszAnsiTable = NULL;
551
552 hr = StrAnsiAllocString(&pszAnsiTable, pszTable, 0, CP_ACP);
538 - ExitOnFailure(hr, "Failed converting table name to ansi");
553 + EseExitOnFailure(hr, "Failed converting table name to ansi");
554
555 jEr = JetCreateTableA(jsSession, jdbDb, pszAnsiTable, 100, 0, pjtTable);
556 ExitOnJetFailure(jEr, hr, "Failed to create table %s", pszAnsiTable);
@@ -558,7 +573,7 @@ HRESULT DAPI EseOpenTable(
573 LPSTR pszAnsiTable = NULL;
574
575 hr = StrAnsiAllocString(&pszAnsiTable, pszTable, 0, CP_ACP);
561 - ExitOnFailure(hr, "Failed converting table name to ansi");
576 + EseExitOnFailure(hr, "Failed converting table name to ansi");
577
578 jEr = JetOpenTableA(jsSession, jdbDb, pszAnsiTable, NULL, 0, 0, pjtTable);
579 ExitOnJetFailure(jEr, hr, "Failed to open table %s", pszAnsiTable);
@@ -602,7 +617,7 @@ HRESULT DAPI EseEnsureColumn(
617 JET_COLUMNBASE jcdTempBase = { sizeof(JET_COLUMNBASE) };
618
619 hr = StrAnsiAllocString(&pszAnsiColumnName, pszColumnName, 0, CP_ACP);
605 - ExitOnFailure(hr, "Failed converting column name to ansi");
620 + EseExitOnFailure(hr, "Failed converting column name to ansi");
621
622 jEr = JetGetTableColumnInfoA(jsSession, jtTable, pszAnsiColumnName, &jcdTempBase, sizeof(JET_COLUMNBASE), JET_ColInfoBase);
623 if (JET_errSuccess == jEr)
@@ -661,7 +676,7 @@ HRESULT DAPI EseGetColumn(
676 JET_COLUMNBASE jcdTempBase = { sizeof(JET_COLUMNBASE) };
677
678 hr = StrAnsiAllocString(&pszAnsiColumnName, pszColumnName, 0, CP_ACP);
664 - ExitOnFailure(hr, "Failed converting column name to ansi");
679 + EseExitOnFailure(hr, "Failed converting column name to ansi");
680
681 jEr = JetGetTableColumnInfoA(jsSession, jtTable, pszAnsiColumnName, &jcdTempBase, sizeof(JET_COLUMNBASE), JET_ColInfoBase);
682 if (JET_errSuccess == jEr)
@@ -898,7 +913,7 @@ HRESULT DAPI EseGetColumnBinary(
913 __in JET_SESID jsSession,
914 __in ESE_TABLE_SCHEMA tsTable,
915 __in DWORD dwColumn,
901 - __deref_out_bcount(*piBuffer) BYTE** ppbBuffer,
916 + __deref_inout_bcount(*piBuffer) BYTE** ppbBuffer,
917 __inout SIZE_T* piBuffer
918 )
919 {
@@ -916,12 +931,12 @@ HRESULT DAPI EseGetColumnBinary(
931 if (NULL == *ppbBuffer)
932 {
933 *ppbBuffer = reinterpret_cast<BYTE *>(MemAlloc(ulActualSize, FALSE));
919 - ExitOnNull(*ppbBuffer, hr, E_OUTOFMEMORY, "Failed to allocate memory for reading binary value column");
934 + EseExitOnNull(*ppbBuffer, hr, E_OUTOFMEMORY, "Failed to allocate memory for reading binary value column");
935 }
936 else
937 {
938 *ppbBuffer = reinterpret_cast<BYTE *>(MemReAlloc(*ppbBuffer, ulActualSize, FALSE));
924 - ExitOnNull(*ppbBuffer, hr, E_OUTOFMEMORY, "Failed to reallocate memory for reading binary value column");
939 + EseExitOnNull(*ppbBuffer, hr, E_OUTOFMEMORY, "Failed to reallocate memory for reading binary value column");
940 }
941
942 jEr = JetRetrieveColumn(jsSession, tsTable.jtTable, tsTable.pcsColumns[dwColumn].jcColumn, *ppbBuffer, ulActualSize, NULL, 0, NULL);
@@ -1001,7 +1016,7 @@ HRESULT DAPI EseGetColumnString(
1016 ExitOnJetFailure(jEr, hr, "Failed to check size of string value from record");
1017
1018 hr = StrAlloc(ppszValue, ulActualSize);
1004 - ExitOnFailure(hr, "Failed to allocate string while retrieving column value");
1019 + EseExitOnFailure(hr, "Failed to allocate string while retrieving column value");
1020
1021 jEr = JetRetrieveColumn(jsSession, tsTable.jtTable, tsTable.pcsColumns[dwColumn].jcColumn, *ppszValue, ulActualSize, NULL, 0, NULL);
1022 ExitOnJetFailure(jEr, hr, "Failed to retrieve string value from record");
@@ -1023,7 +1038,7 @@ HRESULT DAPI EseBeginQuery(
1038 HRESULT hr = S_OK;
1039
1040 *peqhHandle = static_cast<ESE_QUERY*>(MemAlloc(sizeof(ESE_QUERY), TRUE));
1026 - ExitOnNull(*peqhHandle, hr, E_OUTOFMEMORY, "Failed to allocate new query");
1041 + EseExitOnNull(*peqhHandle, hr, E_OUTOFMEMORY, "Failed to allocate new query");
1042
1043 ESE_QUERY *peqHandle = static_cast<ESE_QUERY *>(*peqhHandle);
1044 peqHandle->qtQueryType = qtQueryType;
@@ -1050,7 +1065,7 @@ HRESULT DAPI SetQueryColumn(
1065 if (peqHandle->dwColumns == countof(peqHandle->pvData))
1066 {
1067 hr = E_NOTIMPL;
1053 - ExitOnFailure(hr, "Dutil hasn't implemented support for queries of more than %d columns", countof(peqHandle->pvData));
1068 + EseExitOnFailure(hr, "Dutil hasn't implemented support for queries of more than %d columns", countof(peqHandle->pvData));
1069 }
1070
1071 if (0 == peqHandle->dwColumns) // If it's the first column, start a new key
@@ -1065,7 +1080,7 @@ HRESULT DAPI SetQueryColumn(
1080 if (ESE_QUERY_EXACT != peqHandle->qtQueryType)
1081 {
1082 peqHandle->pvData[peqHandle->dwColumns] = MemAlloc(cbData, FALSE);
1068 - ExitOnNull(peqHandle->pvData[peqHandle->dwColumns], hr, E_OUTOFMEMORY, "Failed to allocate memory");
1083 + EseExitOnNull(peqHandle->pvData[peqHandle->dwColumns], hr, E_OUTOFMEMORY, "Failed to allocate memory");
1084
1085 memcpy(peqHandle->pvData[peqHandle->dwColumns], pvData, cbData);
1086
@@ -1108,7 +1123,7 @@ HRESULT DAPI EseSetQueryColumnBinary(
1123 }
1124
1125 hr = SetQueryColumn(eqhHandle, reinterpret_cast<const void *>(pbBuffer), static_cast<DWORD>(cbBuffer), jGrb);
1111 - ExitOnFailure(hr, "Failed to set value of query colum (as binary) to:");
1126 + EseExitOnFailure(hr, "Failed to set value of query colum (as binary) to:");
1127
1128 LExit:
1129 return hr;
@@ -1137,7 +1152,7 @@ HRESULT DAPI EseSetQueryColumnDword(
1152 }
1153
1154 hr = SetQueryColumn(eqhHandle, (const void *)&dwData, sizeof(DWORD), jGrb);
1140 - ExitOnFailure(hr, "Failed to set value of query colum (as dword) to: %u", dwData);
1155 + EseExitOnFailure(hr, "Failed to set value of query colum (as dword) to: %u", dwData);
1156
1157 LExit:
1158 return hr;
@@ -1167,7 +1182,7 @@ HRESULT DAPI EseSetQueryColumnBool(
1182 }
1183
1184 hr = SetQueryColumn(eqhHandle, (const void *)&bByte, 1, jGrb);
1170 - ExitOnFailure(hr, "Failed to set value of query colum (as bool) to: %s", fValue ? "TRUE" : "FALSE");
1185 + EseExitOnFailure(hr, "Failed to set value of query colum (as bool) to: %s", fValue ? "TRUE" : "FALSE");
1186
1187 LExit:
1188 return hr;
@@ -1200,7 +1215,7 @@ HRESULT DAPI EseSetQueryColumnString(
1215 }
1216
1217 hr = SetQueryColumn(eqhHandle, (const void *)pszString, dwStringSize, jGrb);
1203 - ExitOnFailure(hr, "Failed to set value of query colum (as string) to: %ls", pszString);
1218 + EseExitOnFailure(hr, "Failed to set value of query colum (as string) to: %ls", pszString);
1219
1220 LExit:
1221 return hr;
src/dutil/fileutil.cpp
+140 -125
@@ -2,6 +2,21 @@
2
3 #include "precomp.h"
4
5 +
6 +// Exit macros
7 +#define FileExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_FILEUTIL, x, s, __VA_ARGS__)
8 +#define FileExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_FILEUTIL, x, s, __VA_ARGS__)
9 +#define FileExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_FILEUTIL, x, s, __VA_ARGS__)
10 +#define FileExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_FILEUTIL, x, s, __VA_ARGS__)
11 +#define FileExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_FILEUTIL, x, s, __VA_ARGS__)
12 +#define FileExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_FILEUTIL, x, s, __VA_ARGS__)
13 +#define FileExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_FILEUTIL, p, x, e, s, __VA_ARGS__)
14 +#define FileExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_FILEUTIL, p, x, s, __VA_ARGS__)
15 +#define FileExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_FILEUTIL, p, x, e, s, __VA_ARGS__)
16 +#define FileExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_FILEUTIL, p, x, s, __VA_ARGS__)
17 +#define FileExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_FILEUTIL, e, x, s, __VA_ARGS__)
18 +#define FileExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_FILEUTIL, g, x, s, __VA_ARGS__)
19 +
20 // constants
21
22 const BYTE UTF8BOM[] = {0xEF, 0xBB, 0xBF};
@@ -15,7 +30,7 @@ const LPCWSTR REGISTRY_PENDING_FILE_RENAME_VALUE = L"PendingFileRenameOperations
30
31 ********************************************************************/
32 extern "C" LPWSTR DAPI FileFromPath(
18 - __in LPCWSTR wzPath
33 + __in_z LPCWSTR wzPath
34 )
35 {
36 if (!wzPath)
@@ -42,7 +57,7 @@ extern "C" LPWSTR DAPI FileFromPath(
57
58 ********************************************************************/
59 extern "C" HRESULT DAPI FileResolvePath(
45 - __in LPCWSTR wzRelativePath,
60 + __in_z LPCWSTR wzRelativePath,
61 __out LPWSTR *ppwzFullPath
62 )
63 {
@@ -63,28 +78,28 @@ extern "C" HRESULT DAPI FileResolvePath(
78 //
79 cchExpandedPath = MAX_PATH;
80 hr = StrAlloc(&pwzExpandedPath, cchExpandedPath);
66 - ExitOnFailure(hr, "Failed to allocate space for expanded path.");
81 + FileExitOnFailure(hr, "Failed to allocate space for expanded path.");
82
83 cch = ::ExpandEnvironmentStringsW(wzRelativePath, pwzExpandedPath, cchExpandedPath);
84 if (0 == cch)
85 {
71 - ExitWithLastError(hr, "Failed to expand environment variables in string: %ls", wzRelativePath);
86 + FileExitWithLastError(hr, "Failed to expand environment variables in string: %ls", wzRelativePath);
87 }
88 else if (cchExpandedPath < cch)
89 {
90 cchExpandedPath = cch;
91 hr = StrAlloc(&pwzExpandedPath, cchExpandedPath);
77 - ExitOnFailure(hr, "Failed to re-allocate more space for expanded path.");
92 + FileExitOnFailure(hr, "Failed to re-allocate more space for expanded path.");
93
94 cch = ::ExpandEnvironmentStringsW(wzRelativePath, pwzExpandedPath, cchExpandedPath);
95 if (0 == cch)
96 {
82 - ExitWithLastError(hr, "Failed to expand environment variables in string: %ls", wzRelativePath);
97 + FileExitWithLastError(hr, "Failed to expand environment variables in string: %ls", wzRelativePath);
98 }
99 else if (cchExpandedPath < cch)
100 {
101 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
87 - ExitOnRootFailure(hr, "Failed to allocate buffer for expanded path.");
102 + FileExitOnRootFailure(hr, "Failed to allocate buffer for expanded path.");
103 }
104 }
105
@@ -93,28 +108,28 @@ extern "C" HRESULT DAPI FileResolvePath(
108 //
109 cchFullPath = MAX_PATH;
110 hr = StrAlloc(&pwzFullPath, cchFullPath);
96 - ExitOnFailure(hr, "Failed to allocate space for full path.");
111 + FileExitOnFailure(hr, "Failed to allocate space for full path.");
112
113 cch = ::GetFullPathNameW(pwzExpandedPath, cchFullPath, pwzFullPath, &wzFileName);
114 if (0 == cch)
115 {
101 - ExitWithLastError(hr, "Failed to get full path for string: %ls", pwzExpandedPath);
116 + FileExitWithLastError(hr, "Failed to get full path for string: %ls", pwzExpandedPath);
117 }
118 else if (cchFullPath < cch)
119 {
120 cchFullPath = cch;
121 hr = StrAlloc(&pwzFullPath, cchFullPath);
107 - ExitOnFailure(hr, "Failed to re-allocate more space for full path.");
122 + FileExitOnFailure(hr, "Failed to re-allocate more space for full path.");
123
124 cch = ::GetFullPathNameW(pwzExpandedPath, cchFullPath, pwzFullPath, &wzFileName);
125 if (0 == cch)
126 {
112 - ExitWithLastError(hr, "Failed to get full path for string: %ls", pwzExpandedPath);
127 + FileExitWithLastError(hr, "Failed to get full path for string: %ls", pwzExpandedPath);
128 }
129 else if (cchFullPath < cch)
130 {
131 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
117 - ExitOnRootFailure(hr, "Failed to allocate buffer for full path.");
132 + FileExitOnRootFailure(hr, "Failed to allocate buffer for full path.");
133 }
134 }
135
@@ -133,7 +148,7 @@ LExit:
148 FileStripExtension - Strip extension from filename
149 ********************************************************************/
150 extern "C" HRESULT DAPI FileStripExtension(
136 -__in LPCWSTR wzFileName,
151 +__in_z LPCWSTR wzFileName,
152 __out LPWSTR *ppwzFileNameNoExtension
153 )
154 {
@@ -158,14 +173,14 @@ __out LPWSTR *ppwzFileNameNoExtension
173 }
174
175 hr = StrAlloc(&pwzFileNameNoExtension, cchFileNameNoExtension);
161 - ExitOnFailure(hr, "failed to allocate space for File Name without extension");
176 + FileExitOnFailure(hr, "failed to allocate space for File Name without extension");
177
178 // _wsplitpath_s can handle drive/path/filename/extension
179 errno_t err = _wsplitpath_s(wzFileName, NULL, NULL, NULL, NULL, pwzFileNameNoExtension, cchFileNameNoExtension, NULL, NULL);
180 if (0 != err)
181 {
182 hr = E_INVALIDARG;
168 - ExitOnFailure(hr, "failed to parse filename: %ls", wzFileName);
183 + FileExitOnFailure(hr, "failed to parse filename: %ls", wzFileName);
184 }
185
186 *ppwzFileNameNoExtension = pwzFileNameNoExtension;
@@ -182,8 +197,8 @@ LExit:
197 FileChangeExtension - Changes the extension of a filename
198 ********************************************************************/
199 extern "C" HRESULT DAPI FileChangeExtension(
185 - __in LPCWSTR wzFileName,
186 - __in LPCWSTR wzNewExtension,
200 + __in_z LPCWSTR wzFileName,
201 + __in_z LPCWSTR wzNewExtension,
202 __out LPWSTR *ppwzFileNameNewExtension
203 )
204 {
@@ -193,10 +208,10 @@ extern "C" HRESULT DAPI FileChangeExtension(
208 LPWSTR sczFileName = NULL;
209
210 hr = FileStripExtension(wzFileName, &sczFileName);
196 - ExitOnFailure(hr, "Failed to strip extension from file name: %ls", wzFileName);
211 + FileExitOnFailure(hr, "Failed to strip extension from file name: %ls", wzFileName);
212
213 hr = StrAllocConcat(&sczFileName, wzNewExtension, 0);
199 - ExitOnFailure(hr, "Failed to add new extension.");
214 + FileExitOnFailure(hr, "Failed to add new extension.");
215
216 *ppwzFileNameNewExtension = sczFileName;
217 sczFileName = NULL;
@@ -238,11 +253,11 @@ extern "C" HRESULT DAPI FileAddSuffixToBaseName(
253 {
254 // no extension, so add the suffix at the end of the whole name
255 hr = StrAllocString(&sczNewFileName, wzFileName, 0);
241 - ExitOnFailure(hr, "Failed to allocate new file name.");
256 + FileExitOnFailure(hr, "Failed to allocate new file name.");
257
258 hr = StrAllocConcat(&sczNewFileName, wzSuffix, 0);
259 }
245 - ExitOnFailure(hr, "Failed to allocate new file name with suffix.");
260 + FileExitOnFailure(hr, "Failed to allocate new file name with suffix.");
261
262 *psczNewFileName = sczNewFileName;
263 sczNewFileName = NULL;
@@ -259,7 +274,7 @@ LExit:
274
275 ********************************************************************/
276 extern "C" HRESULT DAPI FileVersion(
262 - __in LPCWSTR wzFilename,
277 + __in_z LPCWSTR wzFilename,
278 __out DWORD *pdwVerMajor,
279 __out DWORD* pdwVerMinor
280 )
@@ -274,20 +289,20 @@ extern "C" HRESULT DAPI FileVersion(
289
290 if (0 == (cbVerBuffer = ::GetFileVersionInfoSizeW(wzFilename, &dwHandle)))
291 {
277 - ExitOnLastErrorDebugTrace(hr, "failed to get version info for file: %ls", wzFilename);
292 + FileExitOnLastErrorDebugTrace(hr, "failed to get version info for file: %ls", wzFilename);
293 }
294
295 pVerBuffer = ::GlobalAlloc(GMEM_FIXED, cbVerBuffer);
281 - ExitOnNullDebugTrace(pVerBuffer, hr, E_OUTOFMEMORY, "failed to allocate version info for file: %ls", wzFilename);
296 + FileExitOnNullDebugTrace(pVerBuffer, hr, E_OUTOFMEMORY, "failed to allocate version info for file: %ls", wzFilename);
297
298 if (!::GetFileVersionInfoW(wzFilename, dwHandle, cbVerBuffer, pVerBuffer))
299 {
285 - ExitOnLastErrorDebugTrace(hr, "failed to get version info for file: %ls", wzFilename);
300 + FileExitOnLastErrorDebugTrace(hr, "failed to get version info for file: %ls", wzFilename);
301 }
302
303 if (!::VerQueryValueW(pVerBuffer, L"\\", (void**)&pvsFileInfo, &cbFileInfo))
304 {
290 - ExitOnLastErrorDebugTrace(hr, "failed to get version value for file: %ls", wzFilename);
305 + FileExitOnLastErrorDebugTrace(hr, "failed to get version value for file: %ls", wzFilename);
306 }
307
308 *pdwVerMajor = pvsFileInfo->dwFileVersionMS;
@@ -307,7 +322,7 @@ LExit:
322
323 *******************************************************************/
324 extern "C" HRESULT DAPI FileVersionFromString(
310 - __in LPCWSTR wzVersion,
325 + __in_z LPCWSTR wzVersion,
326 __out DWORD* pdwVerMajor,
327 __out DWORD* pdwVerMinor
328 )
@@ -394,7 +409,7 @@ LExit:
409
410 *******************************************************************/
411 extern "C" HRESULT DAPI FileVersionFromStringEx(
397 - __in LPCWSTR wzVersion,
412 + __in_z LPCWSTR wzVersion,
413 __in DWORD cchVersion,
414 __out DWORD64* pqwVersion
415 )
@@ -453,11 +468,11 @@ extern "C" HRESULT DAPI FileVersionFromStringEx(
468
469 DWORD cchPart;
470 hr = ::PtrdiffTToDWord(wzPartEnd - wzPartBegin, &cchPart);
456 - ExitOnFailure(hr, "Version number part was too long.");
471 + FileExitOnFailure(hr, "Version number part was too long.");
472
473 // parse version part
474 hr = StrStringToUInt16(wzPartBegin, cchPart, &us);
460 - ExitOnFailure(hr, "Failed to parse version number part.");
475 + FileExitOnFailure(hr, "Failed to parse version number part.");
476
477 // add part to qword version
478 qwVersion |= (DWORD64)us << ((3 - iPart) * 16);
@@ -501,7 +516,7 @@ extern "C" HRESULT DAPI FileVersionToStringEx(
516
517 // Format and return the version string.
518 hr = StrAllocFormatted(psczVersion, L"%u.%u.%u.%u", wMajor, wMinor, wBuild, wRevision);
504 - ExitOnFailure(hr, "Failed to allocate and format the version number.");
519 + FileExitOnFailure(hr, "Failed to allocate and format the version number.");
520
521 LExit:
522 return hr;
@@ -527,7 +542,7 @@ extern "C" HRESULT DAPI FileSetPointer(
542 liMove.QuadPart = dw64Move;
543 if (!::SetFilePointerEx(hFile, liMove, &liNewPosition, dwMoveMethod))
544 {
530 - ExitWithLastError(hr, "Failed to set file pointer.");
545 + FileExitWithLastError(hr, "Failed to set file pointer.");
546 }
547
548 if (pdw64NewPosition)
@@ -545,23 +560,23 @@ LExit:
560
561 ********************************************************************/
562 extern "C" HRESULT DAPI FileSize(
548 - __in LPCWSTR pwzFileName,
563 + __in_z LPCWSTR pwzFileName,
564 __out LONGLONG* pllSize
565 )
566 {
567 HRESULT hr = S_OK;
568 HANDLE hFile = INVALID_HANDLE_VALUE;
569
555 - ExitOnNull(pwzFileName, hr, E_INVALIDARG, "Attempted to check filename, but no filename was provided");
570 + FileExitOnNull(pwzFileName, hr, E_INVALIDARG, "Attempted to check filename, but no filename was provided");
571
572 hFile = ::CreateFileW(pwzFileName, FILE_READ_ATTRIBUTES, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
573 if (INVALID_HANDLE_VALUE == hFile)
574 {
560 - ExitWithLastError(hr, "Failed to open file %ls while checking file size", pwzFileName);
575 + FileExitWithLastError(hr, "Failed to open file %ls while checking file size", pwzFileName);
576 }
577
578 hr = FileSizeByHandle(hFile, pllSize);
564 - ExitOnFailure(hr, "Failed to check size of file %ls by handle", pwzFileName);
579 + FileExitOnFailure(hr, "Failed to check size of file %ls by handle", pwzFileName);
580
581 LExit:
582 ReleaseFileHandle(hFile);
@@ -587,7 +602,7 @@ extern "C" HRESULT DAPI FileSizeByHandle(
602
603 if (!::GetFileSizeEx(hFile, &li))
604 {
590 - ExitWithLastError(hr, "Failed to get size of file.");
605 + FileExitWithLastError(hr, "Failed to get size of file.");
606 }
607
608 *pllSize = li.QuadPart;
@@ -602,7 +617,7 @@ LExit:
617
618 ********************************************************************/
619 extern "C" BOOL DAPI FileExistsEx(
605 - __in LPCWSTR wzPath,
620 + __in_z LPCWSTR wzPath,
621 __out_opt DWORD *pdwAttributes
622 )
623 {
@@ -655,14 +670,14 @@ extern "C" BOOL DAPI FileExistsAfterRestart(
670 {
671 ExitFunction1(hr = S_OK);
672 }
658 - ExitOnFailure(hr, "Failed to open pending file rename registry key.");
673 + FileExitOnFailure(hr, "Failed to open pending file rename registry key.");
674
675 hr = RegReadStringArray(hkPendingFileRename, REGISTRY_PENDING_FILE_RENAME_VALUE, &rgsczRenames, &cRenames);
676 if (E_FILENOTFOUND == hr)
677 {
678 ExitFunction1(hr = S_OK);
679 }
665 - ExitOnFailure(hr, "Failed to read pending file renames.");
680 + FileExitOnFailure(hr, "Failed to read pending file renames.");
681
682 // The pending file renames array is pairs of source and target paths. We only care
683 // about checking the source paths so skip the target paths (i += 2).
@@ -678,7 +693,7 @@ extern "C" BOOL DAPI FileExistsAfterRestart(
693 }
694
695 hr = PathCompare(wzPath, wzRename, &nCompare);
681 - ExitOnFailure(hr, "Failed to compare path from pending file rename to check path.");
696 + FileExitOnFailure(hr, "Failed to compare path from pending file rename to check path.");
697
698 if (CSTR_EQUAL == nCompare)
699 {
@@ -719,14 +734,14 @@ extern "C" HRESULT DAPI FileRemoveFromPendingRename(
734 {
735 ExitFunction1(hr = S_OK);
736 }
722 - ExitOnFailure(hr, "Failed to open pending file rename registry key.");
737 + FileExitOnFailure(hr, "Failed to open pending file rename registry key.");
738
739 hr = RegReadStringArray(hkPendingFileRename, REGISTRY_PENDING_FILE_RENAME_VALUE, &rgsczRenames, &cRenames);
740 if (E_FILENOTFOUND == hr)
741 {
742 ExitFunction1(hr = S_OK);
743 }
729 - ExitOnFailure(hr, "Failed to read pending file renames.");
744 + FileExitOnFailure(hr, "Failed to read pending file renames.");
745
746 // The pending file renames array is pairs of source and target paths. We only care
747 // about checking the source paths so skip the target paths (i += 2).
@@ -742,7 +757,7 @@ extern "C" HRESULT DAPI FileRemoveFromPendingRename(
757 }
758
759 hr = PathCompare(wzPath, wzRename, &nCompare);
745 - ExitOnFailure(hr, "Failed to compare path from pending file rename to check path.");
760 + FileExitOnFailure(hr, "Failed to compare path from pending file rename to check path.");
761
762 // If we find our path in the list, null out the source and target slot and
763 // we'll compact the array next.
@@ -772,7 +787,7 @@ extern "C" HRESULT DAPI FileRemoveFromPendingRename(
787
788 // Write the new array back to the pending file rename key.
789 hr = RegWriteStringArray(hkPendingFileRename, REGISTRY_PENDING_FILE_RENAME_VALUE, rgsczRenames, cRenames);
775 - ExitOnFailure(hr, "Failed to update pending file renames.");
790 + FileExitOnFailure(hr, "Failed to update pending file renames.");
791 }
792
793 LExit:
@@ -790,7 +805,7 @@ LExit:
805 extern "C" HRESULT DAPI FileRead(
806 __deref_out_bcount_full(*pcbDest) LPBYTE* ppbDest,
807 __out SIZE_T* pcbDest,
793 - __in LPCWSTR wzSrcPath
808 + __in_z LPCWSTR wzSrcPath
809 )
810 {
811 HRESULT hr = FileReadPartial(ppbDest, pcbDest, wzSrcPath, FALSE, 0, 0xFFFFFFFF, FALSE);
@@ -819,7 +834,7 @@ extern "C" HRESULT DAPI FileReadEx(
834 extern "C" HRESULT DAPI FileReadUntil(
835 __deref_out_bcount_full(*pcbDest) LPBYTE* ppbDest,
836 __out_range(<=, cbMaxRead) SIZE_T* pcbDest,
822 - __in LPCWSTR wzSrcPath,
837 + __in_z LPCWSTR wzSrcPath,
838 __in DWORD cbMaxRead
839 )
840 {
@@ -835,7 +850,7 @@ extern "C" HRESULT DAPI FileReadUntil(
850 extern "C" HRESULT DAPI FileReadPartial(
851 __deref_out_bcount_full(*pcbDest) LPBYTE* ppbDest,
852 __out_range(<=, cbMaxRead) SIZE_T* pcbDest,
838 - __in LPCWSTR wzSrcPath,
853 + __in_z LPCWSTR wzSrcPath,
854 __in BOOL fSeek,
855 __in DWORD cbStartPosition,
856 __in DWORD cbMaxRead,
@@ -850,7 +865,7 @@ extern "C" HRESULT DAPI FileReadPartial(
865 (with specified share mode)
866 ********************************************************************/
867 extern "C" HRESULT DAPI FileReadPartialEx(
853 - __deref_out_bcount_full(*pcbDest) LPBYTE* ppbDest,
868 + __deref_inout_bcount_full(*pcbDest) LPBYTE* ppbDest,
869 __out_range(<=, cbMaxRead) SIZE_T* pcbDest,
870 __in_z LPCWSTR wzSrcPath,
871 __in BOOL fSeek,
@@ -868,10 +883,10 @@ extern "C" HRESULT DAPI FileReadPartialEx(
883 DWORD cbData = 0;
884 BYTE* pbData = NULL;
885
871 - ExitOnNull(pcbDest, hr, E_INVALIDARG, "Invalid argument pcbDest");
872 - ExitOnNull(ppbDest, hr, E_INVALIDARG, "Invalid argument ppbDest");
873 - ExitOnNull(wzSrcPath, hr, E_INVALIDARG, "Invalid argument wzSrcPath");
874 - ExitOnNull(*wzSrcPath, hr, E_INVALIDARG, "*wzSrcPath is null");
886 + FileExitOnNull(pcbDest, hr, E_INVALIDARG, "Invalid argument pcbDest");
887 + FileExitOnNull(ppbDest, hr, E_INVALIDARG, "Invalid argument ppbDest");
888 + FileExitOnNull(wzSrcPath, hr, E_INVALIDARG, "Invalid argument wzSrcPath");
889 + FileExitOnNull(*wzSrcPath, hr, E_INVALIDARG, "*wzSrcPath is null");
890
891 hFile = ::CreateFileW(wzSrcPath, GENERIC_READ, dwShareMode, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
892 if (INVALID_HANDLE_VALUE == hFile)
@@ -881,12 +896,12 @@ extern "C" HRESULT DAPI FileReadPartialEx(
896 {
897 ExitFunction1(hr = E_FILENOTFOUND);
898 }
884 - ExitOnWin32Error(er, hr, "Failed to open file: %ls", wzSrcPath);
899 + FileExitOnWin32Error(er, hr, "Failed to open file: %ls", wzSrcPath);
900 }
901
902 if (!::GetFileSizeEx(hFile, &liFileSize))
903 {
889 - ExitWithLastError(hr, "Failed to get size of file: %ls", wzSrcPath);
904 + FileExitWithLastError(hr, "Failed to get size of file: %ls", wzSrcPath);
905 }
906
907 if (fSeek)
@@ -894,13 +909,13 @@ extern "C" HRESULT DAPI FileReadPartialEx(
909 if (cbStartPosition > liFileSize.QuadPart)
910 {
911 hr = E_INVALIDARG;
897 - ExitOnFailure(hr, "Start position %d bigger than file '%ls' size %d", cbStartPosition, wzSrcPath, liFileSize.QuadPart);
912 + FileExitOnFailure(hr, "Start position %d bigger than file '%ls' size %llu", cbStartPosition, wzSrcPath, liFileSize.QuadPart);
913 }
914
915 DWORD dwErr = ::SetFilePointer(hFile, cbStartPosition, NULL, FILE_CURRENT);
916 if (INVALID_SET_FILE_POINTER == dwErr)
917 {
903 - ExitOnLastError(hr, "Failed to seek position %d", cbStartPosition);
918 + FileExitOnLastError(hr, "Failed to seek position %d", cbStartPosition);
919 }
920 }
921 else
@@ -918,7 +933,7 @@ extern "C" HRESULT DAPI FileReadPartialEx(
933 if (cbMaxRead < liFileSize.QuadPart - cbStartPosition)
934 {
935 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
921 - ExitOnRootFailure(hr, "Failed to load file: %ls, too large.", wzSrcPath);
936 + FileExitOnRootFailure(hr, "Failed to load file: %ls, too large.", wzSrcPath);
937 }
938 }
939
@@ -932,7 +947,7 @@ extern "C" HRESULT DAPI FileReadPartialEx(
947 }
948
949 LPVOID pv = MemReAlloc(*ppbDest, cbData, TRUE);
935 - ExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to re-allocate memory to read in file: %ls", wzSrcPath);
950 + FileExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to re-allocate memory to read in file: %ls", wzSrcPath);
951
952 pbData = static_cast<BYTE*>(pv);
953 }
@@ -945,7 +960,7 @@ extern "C" HRESULT DAPI FileReadPartialEx(
960 }
961
962 pbData = static_cast<BYTE*>(MemAlloc(cbData, TRUE));
948 - ExitOnNull(pbData, hr, E_OUTOFMEMORY, "Failed to allocate memory to read in file: %ls", wzSrcPath);
963 + FileExitOnNull(pbData, hr, E_OUTOFMEMORY, "Failed to allocate memory to read in file: %ls", wzSrcPath);
964 }
965
966 DWORD cbTotalRead = 0;
@@ -954,11 +969,11 @@ extern "C" HRESULT DAPI FileReadPartialEx(
969 {
970 DWORD cbRemaining = 0;
971 hr = ::ULongSub(cbData, cbTotalRead, &cbRemaining);
957 - ExitOnFailure(hr, "Underflow calculating remaining buffer size.");
972 + FileExitOnFailure(hr, "Underflow calculating remaining buffer size.");
973
974 if (!::ReadFile(hFile, pbData + cbTotalRead, cbRemaining, &cbRead, NULL))
975 {
961 - ExitWithLastError(hr, "Failed to read from file: %ls", wzSrcPath);
976 + FileExitWithLastError(hr, "Failed to read from file: %ls", wzSrcPath);
977 }
978
979 cbTotalRead += cbRead;
@@ -967,7 +982,7 @@ extern "C" HRESULT DAPI FileReadPartialEx(
982 if (cbTotalRead != cbData)
983 {
984 hr = E_UNEXPECTED;
970 - ExitOnFailure(hr, "Failed to completely read file: %ls", wzSrcPath);
985 + FileExitOnFailure(hr, "Failed to completely read file: %ls", wzSrcPath);
986 }
987
988 *ppbDest = pbData;
@@ -999,10 +1014,10 @@ extern "C" HRESULT DAPI FileWrite(
1014
1015 // Open the file
1016 hFile = ::CreateFileW(pwzFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, dwFlagsAndAttributes, NULL);
1002 - ExitOnInvalidHandleWithLastError(hFile, hr, "Failed to open file: %ls", pwzFileName);
1017 + FileExitOnInvalidHandleWithLastError(hFile, hr, "Failed to open file: %ls", pwzFileName);
1018
1019 hr = FileWriteHandle(hFile, pbData, cbData);
1005 - ExitOnFailure(hr, "Failed to write to file: %ls", pwzFileName);
1020 + FileExitOnFailure(hr, "Failed to write to file: %ls", pwzFileName);
1021
1022 if (pHandle)
1023 {
@@ -1036,7 +1051,7 @@ extern "C" HRESULT DAPI FileWriteHandle(
1051 {
1052 if (!::WriteFile(hFile, pbData + cbTotal, (DWORD)(cbData - cbTotal), &cbDataWritten, NULL))
1053 {
1039 - ExitOnLastError(hr, "Failed to write data to file handle.");
1054 + FileExitOnLastError(hr, "Failed to write data to file handle.");
1055 }
1056
1057 cbTotal += cbDataWritten;
@@ -1068,13 +1083,13 @@ extern "C" HRESULT DAPI FileCopyUsingHandles(
1083 cbRead = static_cast<DWORD>((0 == cbCopy) ? countof(rgbData) : min(countof(rgbData), cbCopy - cbTotalCopied));
1084 if (!::ReadFile(hSource, rgbData, cbRead, &cbRead, NULL))
1085 {
1071 - ExitWithLastError(hr, "Failed to read from source.");
1086 + FileExitWithLastError(hr, "Failed to read from source.");
1087 }
1088
1089 if (cbRead)
1090 {
1091 hr = FileWriteHandle(hTarget, rgbData, cbRead);
1077 - ExitOnFailure(hr, "Failed to write to target.");
1092 + FileExitOnFailure(hr, "Failed to write to target.");
1093 }
1094
1095 cbTotalCopied += cbRead;
@@ -1095,8 +1110,8 @@ LExit:
1110
1111 *******************************************************************/
1112 extern "C" HRESULT DAPI FileEnsureCopy(
1098 - __in LPCWSTR wzSource,
1099 - __in LPCWSTR wzTarget,
1113 + __in_z LPCWSTR wzSource,
1114 + __in_z LPCWSTR wzTarget,
1115 __in BOOL fOverwrite
1116 )
1117 {
@@ -1132,12 +1147,12 @@ extern "C" HRESULT DAPI FileEnsureCopy(
1147 *pwzLastSlash = L'\0'; // null terminate
1148 hr = DirEnsureExists(wzTarget, NULL);
1149 *pwzLastSlash = L'\\'; // now put the slash back
1135 - ExitOnFailureDebugTrace(hr, "failed to create directory while copying file: '%ls' to: '%ls'", wzSource, wzTarget);
1150 + FileExitOnFailureDebugTrace(hr, "failed to create directory while copying file: '%ls' to: '%ls'", wzSource, wzTarget);
1151
1152 // try to copy again
1153 if (!::CopyFileW(wzSource, wzTarget, fOverwrite))
1154 {
1140 - ExitOnLastErrorDebugTrace(hr, "failed to copy file: '%ls' to: '%ls'", wzSource, wzTarget);
1155 + FileExitOnLastErrorDebugTrace(hr, "failed to copy file: '%ls' to: '%ls'", wzSource, wzTarget);
1156 }
1157 }
1158 else // no path was specified so just return the error
@@ -1186,7 +1201,7 @@ extern "C" HRESULT DAPI FileEnsureCopyWithRetry(
1201 break; // no reason to retry these errors.
1202 }
1203 }
1189 - ExitOnFailure(hr, "Failed to copy file: '%ls' to: '%ls' after %u retries.", wzSource, wzTarget, i);
1204 + FileExitOnFailure(hr, "Failed to copy file: '%ls' to: '%ls' after %u retries.", wzSource, wzTarget, i);
1205
1206 LExit:
1207 return hr;
@@ -1198,8 +1213,8 @@ LExit:
1213
1214 *******************************************************************/
1215 extern "C" HRESULT DAPI FileEnsureMove(
1201 - __in LPCWSTR wzSource,
1202 - __in LPCWSTR wzTarget,
1216 + __in_z LPCWSTR wzSource,
1217 + __in_z LPCWSTR wzTarget,
1218 __in BOOL fOverwrite,
1219 __in BOOL fAllowCopy
1220 )
@@ -1260,12 +1275,12 @@ extern "C" HRESULT DAPI FileEnsureMove(
1275 *pwzLastSlash = L'\0'; // null terminate
1276 hr = DirEnsureExists(wzTarget, NULL);
1277 *pwzLastSlash = L'\\'; // now put the slash back
1263 - ExitOnFailureDebugTrace(hr, "failed to create directory while moving file: '%ls' to: '%ls'", wzSource, wzTarget);
1278 + FileExitOnFailureDebugTrace(hr, "failed to create directory while moving file: '%ls' to: '%ls'", wzSource, wzTarget);
1279
1280 // try to move again
1281 if (!::MoveFileExW(wzSource, wzTarget, dwFlags))
1282 {
1268 - ExitOnLastErrorDebugTrace(hr, "failed to move file: '%ls' to: '%ls'", wzSource, wzTarget);
1283 + FileExitOnLastErrorDebugTrace(hr, "failed to move file: '%ls' to: '%ls'", wzSource, wzTarget);
1284 }
1285 }
1286 else // no path was specified so just return the error
@@ -1310,7 +1325,7 @@ extern "C" HRESULT DAPI FileEnsureMoveWithRetry(
1325
1326 hr = FileEnsureMove(wzSource, wzTarget, fOverwrite, fAllowCopy);
1327 }
1313 - ExitOnFailure(hr, "Failed to move file: '%ls' to: '%ls' after %u retries.", wzSource, wzTarget, i);
1328 + FileExitOnFailure(hr, "Failed to move file: '%ls' to: '%ls' after %u retries.", wzSource, wzTarget, i);
1329
1330 LExit:
1331 return hr;
@@ -1323,8 +1338,8 @@ LExit:
1338 NOTE: uses ANSI functions internally so it is Win9x safe
1339 ********************************************************************/
1340 extern "C" HRESULT DAPI FileCreateTemp(
1326 - __in LPCWSTR wzPrefix,
1327 - __in LPCWSTR wzExtension,
1341 + __in_z LPCWSTR wzPrefix,
1342 + __in_z LPCWSTR wzExtension,
1343 __deref_opt_out_z LPWSTR* ppwzTempFile,
1344 __out_opt HANDLE* phTempFile
1345 )
@@ -1340,13 +1355,13 @@ extern "C" HRESULT DAPI FileCreateTemp(
1355 int i = 0;
1356
1357 hr = StrAnsiAlloc(&pszTempPath, cchTempPath);
1343 - ExitOnFailure(hr, "failed to allocate memory for the temp path");
1358 + FileExitOnFailure(hr, "failed to allocate memory for the temp path");
1359 ::GetTempPathA(cchTempPath, pszTempPath);
1360
1361 for (i = 0; i < 1000 && INVALID_HANDLE_VALUE == hTempFile; ++i)
1362 {
1363 hr = StrAnsiAllocFormatted(&pszTempFile, "%s%ls%05d.%ls", pszTempPath, wzPrefix, i, wzExtension);
1349 - ExitOnFailure(hr, "failed to allocate memory for log file");
1364 + FileExitOnFailure(hr, "failed to allocate memory for log file");
1365
1366 hTempFile = ::CreateFileA(pszTempFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
1367 if (INVALID_HANDLE_VALUE == hTempFile)
@@ -1358,7 +1373,7 @@ extern "C" HRESULT DAPI FileCreateTemp(
1373 hr = S_OK;
1374 continue;
1375 }
1361 - ExitOnFailureDebugTrace(hr, "failed to create file: %ls", pszTempFile);
1376 + FileExitOnFailureDebugTrace(hr, "failed to create file: %hs", pszTempFile);
1377 }
1378 }
1379
@@ -1387,8 +1402,8 @@ LExit:
1402
1403 *******************************************************************/
1404 extern "C" HRESULT DAPI FileCreateTempW(
1390 - __in LPCWSTR wzPrefix,
1391 - __in LPCWSTR wzExtension,
1405 + __in_z LPCWSTR wzPrefix,
1406 + __in_z LPCWSTR wzExtension,
1407 __deref_opt_out_z LPWSTR* ppwzTempFile,
1408 __out_opt HANDLE* phTempFile
1409 )
@@ -1405,13 +1420,13 @@ extern "C" HRESULT DAPI FileCreateTempW(
1420
1421 if (!::GetTempPathW(cchTempPath, wzTempPath))
1422 {
1408 - ExitOnLastError(hr, "failed to get temp path");
1423 + FileExitOnLastError(hr, "failed to get temp path");
1424 }
1425
1426 for (i = 0; i < 1000 && INVALID_HANDLE_VALUE == hTempFile; ++i)
1427 {
1428 hr = StrAllocFormatted(&pwzTempFile, L"%s%s%05d.%s", wzTempPath, wzPrefix, i, wzExtension);
1414 - ExitOnFailure(hr, "failed to allocate memory for temp filename");
1429 + FileExitOnFailure(hr, "failed to allocate memory for temp filename");
1430
1431 hTempFile = ::CreateFileW(pwzTempFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
1432 if (INVALID_HANDLE_VALUE == hTempFile)
@@ -1423,7 +1438,7 @@ extern "C" HRESULT DAPI FileCreateTempW(
1438 hr = S_OK;
1439 continue;
1440 }
1426 - ExitOnFailureDebugTrace(hr, "failed to create file: %ls", pwzTempFile);
1441 + FileExitOnFailureDebugTrace(hr, "failed to create file: %ls", pwzTempFile);
1442 }
1443 }
1444
@@ -1452,8 +1467,8 @@ LExit:
1467
1468 ********************************************************************/
1469 extern "C" HRESULT DAPI FileIsSame(
1455 - __in LPCWSTR wzFile1,
1456 - __in LPCWSTR wzFile2,
1470 + __in_z LPCWSTR wzFile1,
1471 + __in_z LPCWSTR wzFile2,
1472 __out LPBOOL lpfSameFile
1473 )
1474 {
@@ -1464,19 +1479,19 @@ extern "C" HRESULT DAPI FileIsSame(
1479 BY_HANDLE_FILE_INFORMATION fileInfo2 = { };
1480
1481 hFile1 = ::CreateFileW(wzFile1, FILE_READ_ATTRIBUTES, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
1467 - ExitOnInvalidHandleWithLastError(hFile1, hr, "Failed to open file 1. File = '%ls'", wzFile1);
1482 + FileExitOnInvalidHandleWithLastError(hFile1, hr, "Failed to open file 1. File = '%ls'", wzFile1);
1483
1484 hFile2 = ::CreateFileW(wzFile2, FILE_READ_ATTRIBUTES, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
1470 - ExitOnInvalidHandleWithLastError(hFile2, hr, "Failed to open file 2. File = '%ls'", wzFile2);
1485 + FileExitOnInvalidHandleWithLastError(hFile2, hr, "Failed to open file 2. File = '%ls'", wzFile2);
1486
1487 if (!::GetFileInformationByHandle(hFile1, &fileInfo1))
1488 {
1474 - ExitWithLastError(hr, "Failed to get information for file 1. File = '%ls'", wzFile1);
1489 + FileExitWithLastError(hr, "Failed to get information for file 1. File = '%ls'", wzFile1);
1490 }
1491
1492 if (!::GetFileInformationByHandle(hFile2, &fileInfo2))
1493 {
1479 - ExitWithLastError(hr, "Failed to get information for file 2. File = '%ls'", wzFile2);
1494 + FileExitWithLastError(hr, "Failed to get information for file 2. File = '%ls'", wzFile2);
1495 }
1496
1497 *lpfSameFile = fileInfo1.dwVolumeSerialNumber == fileInfo2.dwVolumeSerialNumber &&
@@ -1495,7 +1510,7 @@ LExit:
1510 hidden, or system attributes if necessary.
1511 ********************************************************************/
1512 extern "C" HRESULT DAPI FileEnsureDelete(
1498 - __in LPCWSTR wzFile
1513 + __in_z LPCWSTR wzFile
1514 )
1515 {
1516 HRESULT hr = S_OK;
@@ -1507,13 +1522,13 @@ extern "C" HRESULT DAPI FileEnsureDelete(
1522 {
1523 if (!::SetFileAttributesW(wzFile, FILE_ATTRIBUTE_NORMAL))
1524 {
1510 - ExitOnLastError(hr, "Failed to remove attributes from file: %ls", wzFile);
1525 + FileExitOnLastError(hr, "Failed to remove attributes from file: %ls", wzFile);
1526 }
1527 }
1528
1529 if (!::DeleteFileW(wzFile))
1530 {
1516 - ExitOnLastError(hr, "Failed to delete file: %ls", wzFile);
1531 + FileExitOnLastError(hr, "Failed to delete file: %ls", wzFile);
1532 }
1533 }
1534
@@ -1525,7 +1540,7 @@ LExit:
1540 FileGetTime - Gets the file time of a specified file
1541 ********************************************************************/
1542 extern "C" HRESULT DAPI FileGetTime(
1528 - __in LPCWSTR wzFile,
1543 + __in_z LPCWSTR wzFile,
1544 __out_opt LPFILETIME lpCreationTime,
1545 __out_opt LPFILETIME lpLastAccessTime,
1546 __out_opt LPFILETIME lpLastWriteTime
@@ -1535,11 +1550,11 @@ extern "C" HRESULT DAPI FileGetTime(
1550 HANDLE hFile = NULL;
1551
1552 hFile = ::CreateFileW(wzFile, FILE_READ_ATTRIBUTES, FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL);
1538 - ExitOnInvalidHandleWithLastError(hFile, hr, "Failed to open file. File = '%ls'", wzFile);
1553 + FileExitOnInvalidHandleWithLastError(hFile, hr, "Failed to open file. File = '%ls'", wzFile);
1554
1555 if (!::GetFileTime(hFile, lpCreationTime, lpLastAccessTime, lpLastWriteTime))
1556 {
1542 - ExitWithLastError(hr, "Failed to get file time for file. File = '%ls'", wzFile);
1557 + FileExitWithLastError(hr, "Failed to get file time for file. File = '%ls'", wzFile);
1558 }
1559
1560 LExit:
@@ -1551,7 +1566,7 @@ LExit:
1566 FileSetTime - Sets the file time of a specified file
1567 ********************************************************************/
1568 extern "C" HRESULT DAPI FileSetTime(
1554 - __in LPCWSTR wzFile,
1569 + __in_z LPCWSTR wzFile,
1570 __in_opt const FILETIME *lpCreationTime,
1571 __in_opt const FILETIME *lpLastAccessTime,
1572 __in_opt const FILETIME *lpLastWriteTime
@@ -1561,11 +1576,11 @@ extern "C" HRESULT DAPI FileSetTime(
1576 HANDLE hFile = NULL;
1577
1578 hFile = ::CreateFileW(wzFile, FILE_WRITE_ATTRIBUTES, FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL);
1564 - ExitOnInvalidHandleWithLastError(hFile, hr, "Failed to open file. File = '%ls'", wzFile);
1579 + FileExitOnInvalidHandleWithLastError(hFile, hr, "Failed to open file. File = '%ls'", wzFile);
1580
1581 if (!::SetFileTime(hFile, lpCreationTime, lpLastAccessTime, lpLastWriteTime))
1582 {
1568 - ExitWithLastError(hr, "Failed to set file time for file. File = '%ls'", wzFile);
1583 + FileExitWithLastError(hr, "Failed to set file time for file. File = '%ls'", wzFile);
1584 }
1585
1586 LExit:
@@ -1578,7 +1593,7 @@ LExit:
1593 creation time of the file
1594 ********************************************************************/
1595 extern "C" HRESULT DAPI FileResetTime(
1581 - __in LPCWSTR wzFile
1596 + __in_z LPCWSTR wzFile
1597 )
1598 {
1599 HRESULT hr = S_OK;
@@ -1586,16 +1601,16 @@ extern "C" HRESULT DAPI FileResetTime(
1601 FILETIME ftCreateTime;
1602
1603 hFile = ::CreateFileW(wzFile, FILE_WRITE_ATTRIBUTES | FILE_READ_ATTRIBUTES, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
1589 - ExitOnInvalidHandleWithLastError(hFile, hr, "Failed to open file. File = '%ls'", wzFile);
1604 + FileExitOnInvalidHandleWithLastError(hFile, hr, "Failed to open file. File = '%ls'", wzFile);
1605
1606 if (!::GetFileTime(hFile, &ftCreateTime, NULL, NULL))
1607 {
1593 - ExitWithLastError(hr, "Failed to get file time for file. File = '%ls'", wzFile);
1608 + FileExitWithLastError(hr, "Failed to get file time for file. File = '%ls'", wzFile);
1609 }
1610
1611 if (!::SetFileTime(hFile, NULL, NULL, &ftCreateTime))
1612 {
1598 - ExitWithLastError(hr, "Failed to reset file time for file. File = '%ls'", wzFile);
1613 + FileExitWithLastError(hr, "Failed to reset file time for file. File = '%ls'", wzFile);
1614 }
1615
1616 LExit:
@@ -1609,7 +1624,7 @@ LExit:
1624
1625 *******************************************************************/
1626 extern "C" HRESULT DAPI FileExecutableArchitecture(
1612 - __in LPCWSTR wzFile,
1627 + __in_z LPCWSTR wzFile,
1628 __out FILE_ARCHITECTURE *pArchitecture
1629 )
1630 {
@@ -1623,34 +1638,34 @@ extern "C" HRESULT DAPI FileExecutableArchitecture(
1638 hFile = ::CreateFileW(wzFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
1639 if (hFile == INVALID_HANDLE_VALUE)
1640 {
1626 - ExitWithLastError(hr, "Failed to open file: %ls", wzFile);
1641 + FileExitWithLastError(hr, "Failed to open file: %ls", wzFile);
1642 }
1643
1644 if (!::ReadFile(hFile, &DosImageHeader, sizeof(DosImageHeader), &cbRead, NULL))
1645 {
1631 - ExitWithLastError(hr, "Failed to read DOS header from file: %ls", wzFile);
1646 + FileExitWithLastError(hr, "Failed to read DOS header from file: %ls", wzFile);
1647 }
1648
1649 if (DosImageHeader.e_magic != IMAGE_DOS_SIGNATURE)
1650 {
1651 hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
1637 - ExitOnRootFailure(hr, "Read invalid DOS header from file: %ls", wzFile);
1652 + FileExitOnRootFailure(hr, "Read invalid DOS header from file: %ls", wzFile);
1653 }
1654
1655 if (INVALID_SET_FILE_POINTER == ::SetFilePointer(hFile, DosImageHeader.e_lfanew, NULL, FILE_BEGIN))
1656 {
1642 - ExitWithLastError(hr, "Failed to seek the NT header in file: %ls", wzFile);
1657 + FileExitWithLastError(hr, "Failed to seek the NT header in file: %ls", wzFile);
1658 }
1659
1660 if (!::ReadFile(hFile, &NtImageHeader, sizeof(NtImageHeader), &cbRead, NULL))
1661 {
1647 - ExitWithLastError(hr, "Failed to read NT header from file: %ls", wzFile);
1662 + FileExitWithLastError(hr, "Failed to read NT header from file: %ls", wzFile);
1663 }
1664
1665 if (NtImageHeader.Signature != IMAGE_NT_SIGNATURE)
1666 {
1667 hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
1653 - ExitOnRootFailure(hr, "Read invalid NT header from file: %ls", wzFile);
1668 + FileExitOnRootFailure(hr, "Read invalid NT header from file: %ls", wzFile);
1669 }
1670
1671 if (IMAGE_SUBSYSTEM_NATIVE == NtImageHeader.OptionalHeader.Subsystem ||
@@ -1677,7 +1692,7 @@ extern "C" HRESULT DAPI FileExecutableArchitecture(
1692 {
1693 hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
1694 }
1680 - ExitOnFailure(hr, "Unexpected subsystem: %d machine type: %d specified in NT header from file: %ls", NtImageHeader.OptionalHeader.Subsystem, NtImageHeader.FileHeader.Machine, wzFile);
1695 + FileExitOnFailure(hr, "Unexpected subsystem: %d machine type: %d specified in NT header from file: %ls", NtImageHeader.OptionalHeader.Subsystem, NtImageHeader.FileHeader.Machine, wzFile);
1696
1697 LExit:
1698 if (hFile != INVALID_HANDLE_VALUE)
@@ -1706,7 +1721,7 @@ extern "C" HRESULT DAPI FileToString(
1721
1722 // Check if the file is ANSI
1723 hr = FileRead(&pbFullFileBuffer, &cbFullFileBuffer, wzFile);
1709 - ExitOnFailure(hr, "Failed to read file: %ls", wzFile);
1724 + FileExitOnFailure(hr, "Failed to read file: %ls", wzFile);
1725
1726 if (0 == cbFullFileBuffer)
1727 {
@@ -1723,7 +1738,7 @@ extern "C" HRESULT DAPI FileToString(
1738 }
1739
1740 hr = StrAllocStringAnsi(&sczFileText, reinterpret_cast<LPCSTR>(pbFullFileBuffer + 3), cbFullFileBuffer - 3, CP_UTF8);
1726 - ExitOnFailure(hr, "Failed to convert file %ls from UTF-8 as its BOM indicated", wzFile);
1741 + FileExitOnFailure(hr, "Failed to convert file %ls from UTF-8 as its BOM indicated", wzFile);
1742
1743 *psczString = sczFileText;
1744 sczFileText = NULL;
@@ -1737,7 +1752,7 @@ extern "C" HRESULT DAPI FileToString(
1752 }
1753
1754 hr = StrAllocString(psczString, reinterpret_cast<LPWSTR>(pbFullFileBuffer + 2), (cbFullFileBuffer - 2) / sizeof(WCHAR));
1740 - ExitOnFailure(hr, "Failed to allocate copy of string");
1755 + FileExitOnFailure(hr, "Failed to allocate copy of string");
1756 }
1757 // No BOM, let's try to detect
1758 else
@@ -1763,7 +1778,7 @@ extern "C" HRESULT DAPI FileToString(
1778 {
1779 if (E_OUTOFMEMORY == hr)
1780 {
1766 - ExitOnFailure(hr, "Failed to convert file %ls from UTF-8", wzFile);
1781 + FileExitOnFailure(hr, "Failed to convert file %ls from UTF-8", wzFile);
1782 }
1783 }
1784 else
@@ -1780,7 +1795,7 @@ extern "C" HRESULT DAPI FileToString(
1795 }
1796
1797 hr = StrAllocString(psczString, reinterpret_cast<LPWSTR>(pbFullFileBuffer), cbFullFileBuffer / sizeof(WCHAR));
1783 - ExitOnFailure(hr, "Failed to allocate copy of string");
1798 + FileExitOnFailure(hr, "Failed to allocate copy of string");
1799 }
1800 }
1801
@@ -1813,20 +1828,20 @@ extern "C" HRESULT DAPI FileFromString(
1828 {
1829 case FILE_ENCODING_UTF8:
1830 hr = StrAnsiAllocString(&sczUtf8String, sczString, 0, CP_UTF8);
1816 - ExitOnFailure(hr, "Failed to convert string to UTF-8 to write UTF-8 file");
1831 + FileExitOnFailure(hr, "Failed to convert string to UTF-8 to write UTF-8 file");
1832
1833 cbFullFileBuffer = lstrlenA(sczUtf8String);
1834 pcbFullFileBuffer = reinterpret_cast<BYTE *>(sczUtf8String);
1835 break;
1836 case FILE_ENCODING_UTF8_WITH_BOM:
1837 hr = StrAnsiAllocString(&sczUtf8String, sczString, 0, CP_UTF8);
1823 - ExitOnFailure(hr, "Failed to convert string to UTF-8 to write UTF-8 file");
1838 + FileExitOnFailure(hr, "Failed to convert string to UTF-8 to write UTF-8 file");
1839
1840 cbStrLen = lstrlenA(sczUtf8String);
1841 cbFullFileBuffer = sizeof(UTF8BOM) + cbStrLen;
1842
1843 pbFullFileBuffer = reinterpret_cast<BYTE *>(MemAlloc(cbFullFileBuffer, TRUE));
1829 - ExitOnNull(pbFullFileBuffer, hr, E_OUTOFMEMORY, "Failed to allocate memory for output file buffer");
1844 + FileExitOnNull(pbFullFileBuffer, hr, E_OUTOFMEMORY, "Failed to allocate memory for output file buffer");
1845
1846 memcpy_s(pbFullFileBuffer, sizeof(UTF8BOM), UTF8BOM, sizeof(UTF8BOM));
1847 memcpy_s(pbFullFileBuffer + sizeof(UTF8BOM), cbStrLen, sczUtf8String, cbStrLen);
@@ -1841,7 +1856,7 @@ extern "C" HRESULT DAPI FileFromString(
1856 cbFullFileBuffer = sizeof(UTF16BOM) + cbStrLen;
1857
1858 pbFullFileBuffer = reinterpret_cast<BYTE *>(MemAlloc(cbFullFileBuffer, TRUE));
1844 - ExitOnNull(pbFullFileBuffer, hr, E_OUTOFMEMORY, "Failed to allocate memory for output file buffer");
1859 + FileExitOnNull(pbFullFileBuffer, hr, E_OUTOFMEMORY, "Failed to allocate memory for output file buffer");
1860
1861 memcpy_s(pbFullFileBuffer, sizeof(UTF16BOM), UTF16BOM, sizeof(UTF16BOM));
1862 memcpy_s(pbFullFileBuffer + sizeof(UTF16BOM), cbStrLen, sczString, cbStrLen);
@@ -1850,7 +1865,7 @@ extern "C" HRESULT DAPI FileFromString(
1865 }
1866
1867 hr = FileWrite(wzFile, dwFlagsAndAttributes, pcbFullFileBuffer, cbFullFileBuffer, NULL);
1853 - ExitOnFailure(hr, "Failed to write file from string to: %ls", wzFile);
1868 + FileExitOnFailure(hr, "Failed to write file from string to: %ls", wzFile);
1869
1870 LExit:
1871 ReleaseStr(sczUtf8String);
src/dutil/gdiputil.cpp
+25 -10
@@ -4,6 +4,21 @@
4
5 using namespace Gdiplus;
6
7 +
8 +// Exit macros
9 +#define GdipExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_GDIPUTIL, x, s, __VA_ARGS__)
10 +#define GdipExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_GDIPUTIL, x, s, __VA_ARGS__)
11 +#define GdipExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_GDIPUTIL, x, s, __VA_ARGS__)
12 +#define GdipExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_GDIPUTIL, x, s, __VA_ARGS__)
13 +#define GdipExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_GDIPUTIL, x, s, __VA_ARGS__)
14 +#define GdipExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_GDIPUTIL, x, s, __VA_ARGS__)
15 +#define GdipExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_GDIPUTIL, p, x, e, s, __VA_ARGS__)
16 +#define GdipExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_GDIPUTIL, p, x, s, __VA_ARGS__)
17 +#define GdipExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_GDIPUTIL, p, x, e, s, __VA_ARGS__)
18 +#define GdipExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_GDIPUTIL, p, x, s, __VA_ARGS__)
19 +#define GdipExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_GDIPUTIL, e, x, s, __VA_ARGS__)
20 +#define GdipExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_GDIPUTIL, g, x, s, __VA_ARGS__)
21 +
22 /********************************************************************
23 GdipInitialize - initializes GDI+.
24
@@ -22,7 +37,7 @@ extern "C" HRESULT DAPI GdipInitialize(
37 Status status = Ok;
38
39 status = GdiplusStartup(pToken, pInput, pOutput);
25 - ExitOnGdipFailure(status, hr, "Failed to initialize GDI+.");
40 + GdipExitOnGdipFailure(status, hr, "Failed to initialize GDI+.");
41
42 LExit:
43 return hr;
@@ -59,15 +74,15 @@ extern "C" HRESULT DAPI GdipBitmapFromResource(
74 Status gs = Ok;
75
76 hr = ResReadData(hinst, szId, &pvData, &cbData);
62 - ExitOnFailure(hr, "Failed to load GDI+ bitmap from resource.");
77 + GdipExitOnFailure(hr, "Failed to load GDI+ bitmap from resource.");
78
79 // Have to copy the fixed resource data into moveable (heap) memory
80 // since that's what GDI+ expects.
81 hGlobal = ::GlobalAlloc(GMEM_MOVEABLE, cbData);
67 - ExitOnNullWithLastError(hGlobal, hr, "Failed to allocate global memory.");
82 + GdipExitOnNullWithLastError(hGlobal, hr, "Failed to allocate global memory.");
83
84 pv = ::GlobalLock(hGlobal);
70 - ExitOnNullWithLastError(pv, hr, "Failed to lock global memory.");
85 + GdipExitOnNullWithLastError(pv, hr, "Failed to lock global memory.");
86
87 memcpy(pv, pvData, cbData);
88
@@ -75,15 +90,15 @@ extern "C" HRESULT DAPI GdipBitmapFromResource(
90 pv = NULL;
91
92 hr = ::CreateStreamOnHGlobal(hGlobal, TRUE, &pStream);
78 - ExitOnFailure(hr, "Failed to allocate stream from global memory.");
93 + GdipExitOnFailure(hr, "Failed to allocate stream from global memory.");
94
95 hGlobal = NULL; // we gave the global memory to the stream object so it will close it
96
97 pBitmap = Bitmap::FromStream(pStream);
83 - ExitOnNull(pBitmap, hr, E_OUTOFMEMORY, "Failed to allocate bitmap from stream.");
98 + GdipExitOnNull(pBitmap, hr, E_OUTOFMEMORY, "Failed to allocate bitmap from stream.");
99
100 gs = pBitmap->GetLastStatus();
86 - ExitOnGdipFailure(gs, hr, "Failed to load bitmap from stream.");
101 + GdipExitOnGdipFailure(gs, hr, "Failed to load bitmap from stream.");
102
103 *ppBitmap = pBitmap;
104 pBitmap = NULL;
@@ -123,13 +138,13 @@ extern "C" HRESULT DAPI GdipBitmapFromFile(
138 Bitmap *pBitmap = NULL;
139 Status gs = Ok;
140
126 - ExitOnNull(ppBitmap, hr, E_INVALIDARG, "Invalid null wzFileName");
141 + GdipExitOnNull(ppBitmap, hr, E_INVALIDARG, "Invalid null wzFileName");
142
143 pBitmap = Bitmap::FromFile(wzFileName);
129 - ExitOnNull(pBitmap, hr, E_OUTOFMEMORY, "Failed to allocate bitmap from file.");
144 + GdipExitOnNull(pBitmap, hr, E_OUTOFMEMORY, "Failed to allocate bitmap from file.");
145
146 gs = pBitmap->GetLastStatus();
132 - ExitOnGdipFailure(gs, hr, "Failed to load bitmap from file: %ls", wzFileName);
147 + GdipExitOnGdipFailure(gs, hr, "Failed to load bitmap from file: %ls", wzFileName);
148
149 *ppBitmap = pBitmap;
150 pBitmap = NULL;
src/dutil/guidutil.cpp
+19 -4
@@ -2,6 +2,21 @@
2
3 #include "precomp.h"
4
5 +
6 +// Exit macros
7 +#define GuidExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_GUIDUTIL, x, s, __VA_ARGS__)
8 +#define GuidExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_GUIDUTIL, x, s, __VA_ARGS__)
9 +#define GuidExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_GUIDUTIL, x, s, __VA_ARGS__)
10 +#define GuidExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_GUIDUTIL, x, s, __VA_ARGS__)
11 +#define GuidExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_GUIDUTIL, x, s, __VA_ARGS__)
12 +#define GuidExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_GUIDUTIL, x, s, __VA_ARGS__)
13 +#define GuidExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_GUIDUTIL, p, x, e, s, __VA_ARGS__)
14 +#define GuidExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_GUIDUTIL, p, x, s, __VA_ARGS__)
15 +#define GuidExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_GUIDUTIL, p, x, e, s, __VA_ARGS__)
16 +#define GuidExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_GUIDUTIL, p, x, s, __VA_ARGS__)
17 +#define GuidExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_GUIDUTIL, e, x, s, __VA_ARGS__)
18 +#define GuidExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_GUIDUTIL, g, x, s, __VA_ARGS__)
19 +
20 extern "C" HRESULT DAPI GuidFixedCreate(
21 _Out_z_cap_c_(GUID_STRING_LENGTH) WCHAR* wzGuid
22 )
@@ -10,12 +25,12 @@ extern "C" HRESULT DAPI GuidFixedCreate(
25 UUID guid = { };
26
27 hr = HRESULT_FROM_RPC(::UuidCreate(&guid));
13 - ExitOnFailure(hr, "UuidCreate failed.");
28 + GuidExitOnFailure(hr, "UuidCreate failed.");
29
30 if (!::StringFromGUID2(guid, wzGuid, GUID_STRING_LENGTH))
31 {
32 hr = E_OUTOFMEMORY;
18 - ExitOnRootFailure(hr, "Failed to convert guid into string.");
33 + GuidExitOnRootFailure(hr, "Failed to convert guid into string.");
34 }
35
36 LExit:
@@ -29,10 +44,10 @@ extern "C" HRESULT DAPI GuidCreate(
44 HRESULT hr = S_OK;
45
46 hr = StrAlloc(psczGuid, GUID_STRING_LENGTH);
32 - ExitOnFailure(hr, "Failed to allocate space for guid");
47 + GuidExitOnFailure(hr, "Failed to allocate space for guid");
48
49 hr = GuidFixedCreate(*psczGuid);
35 - ExitOnFailure(hr, "Failed to create new guid.");
50 + GuidExitOnFailure(hr, "Failed to create new guid.");
51
52 LExit:
53 return hr;
src/dutil/iis7util.cpp
+37 -20
@@ -3,6 +3,21 @@
3 #include "precomp.h"
4 #include "iis7util.h"
5
6 +
7 +// Exit macros
8 +#define IisExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_IIS7UTIL, x, s, __VA_ARGS__)
9 +#define IisExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_IIS7UTIL, x, s, __VA_ARGS__)
10 +#define IisExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_IIS7UTIL, x, s, __VA_ARGS__)
11 +#define IisExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_IIS7UTIL, x, s, __VA_ARGS__)
12 +#define IisExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_IIS7UTIL, x, s, __VA_ARGS__)
13 +#define IisExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_IIS7UTIL, x, s, __VA_ARGS__)
14 +#define IisExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_IIS7UTIL, p, x, e, s, __VA_ARGS__)
15 +#define IisExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_IIS7UTIL, p, x, s, __VA_ARGS__)
16 +#define IisExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_IIS7UTIL, p, x, e, s, __VA_ARGS__)
17 +#define IisExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_IIS7UTIL, p, x, s, __VA_ARGS__)
18 +#define IisExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_IIS7UTIL, e, x, s, __VA_ARGS__)
19 +#define IisExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_IIS7UTIL, g, x, s, __VA_ARGS__)
20 +
21 #define ISSTRINGVARIANT(vt) (VT_BSTR == vt || VT_LPWSTR == vt)
22
23 extern "C" HRESULT DAPI Iis7PutPropertyVariant(
@@ -16,13 +31,13 @@ extern "C" HRESULT DAPI Iis7PutPropertyVariant(
31 BSTR bstrPropName = NULL;
32
33 bstrPropName = ::SysAllocString(wzPropName);
19 - ExitOnNull(bstrPropName, hr, E_OUTOFMEMORY, "failed SysAllocString");
34 + IisExitOnNull(bstrPropName, hr, E_OUTOFMEMORY, "failed SysAllocString");
35
36 hr = pElement->GetPropertyByName(bstrPropName, &pProperty);
22 - ExitOnFailure(hr, "Failed to get property object for %ls", wzPropName);
37 + IisExitOnFailure(hr, "Failed to get property object for %ls", wzPropName);
38
39 hr = pProperty->put_Value(vtPut);
25 - ExitOnFailure(hr, "Failed to set property value for %ls", wzPropName);
40 + IisExitOnFailure(hr, "Failed to set property value for %ls", wzPropName);
41
42 LExit:
43 ReleaseBSTR(bstrPropName);
@@ -44,7 +59,7 @@ extern "C" HRESULT DAPI Iis7PutPropertyString(
59 ::VariantInit(&vtPut);
60 vtPut.vt = VT_BSTR;
61 vtPut.bstrVal = ::SysAllocString(wzString);
47 - ExitOnNull(vtPut.bstrVal, hr, E_OUTOFMEMORY, "failed SysAllocString");
62 + IisExitOnNull(vtPut.bstrVal, hr, E_OUTOFMEMORY, "failed SysAllocString");
63
64 hr = Iis7PutPropertyVariant(pElement, wzPropName, vtPut);
65
@@ -92,13 +107,13 @@ extern "C" HRESULT DAPI Iis7GetPropertyVariant(
107 BSTR bstrPropName = NULL;
108
109 bstrPropName = ::SysAllocString(wzPropName);
95 - ExitOnNull(bstrPropName, hr, E_OUTOFMEMORY, "failed SysAllocString");
110 + IisExitOnNull(bstrPropName, hr, E_OUTOFMEMORY, "failed SysAllocString");
111
112 hr = pElement->GetPropertyByName(bstrPropName, &pProperty);
98 - ExitOnFailure(hr, "Failed to get property object for %ls", wzPropName);
113 + IisExitOnFailure(hr, "Failed to get property object for %ls", wzPropName);
114
115 hr = pProperty->get_Value(vtGet);
101 - ExitOnFailure(hr, "Failed to get property value for %ls", wzPropName);
116 + IisExitOnFailure(hr, "Failed to get property value for %ls", wzPropName);
117
118 LExit:
119 ReleaseBSTR(bstrPropName);
@@ -119,12 +134,12 @@ extern "C" HRESULT DAPI Iis7GetPropertyString(
134
135 ::VariantInit(&vtGet);
136 hr = Iis7GetPropertyVariant(pElement, wzPropName, &vtGet);
122 - ExitOnFailure(hr, "Failed to get iis7 property variant with name: %ls", wzPropName);
137 + IisExitOnFailure(hr, "Failed to get iis7 property variant with name: %ls", wzPropName);
138
139 if (!ISSTRINGVARIANT(vtGet.vt))
140 {
141 hr = E_UNEXPECTED;
127 - ExitOnFailure(hr, "Tried to get property as a string, but type was %d instead.", vtGet.vt);
142 + IisExitOnFailure(hr, "Tried to get property as a string, but type was %d instead.", vtGet.vt);
143 }
144
145 hr = StrAllocString(psczGet, vtGet.bstrVal, 0);
@@ -198,13 +213,13 @@ BOOL DAPI CompareVariantPath(
213 if (ISSTRINGVARIANT(pVariant1->vt))
214 {
215 hr = PathExpand(&wzValue1, pVariant1->bstrVal, PATH_EXPAND_ENVIRONMENT | PATH_EXPAND_FULLPATH);
201 - ExitOnFailure(hr, "Failed to expand path %ls", pVariant1->bstrVal);
216 + IisExitOnFailure(hr, "Failed to expand path %ls", pVariant1->bstrVal);
217 }
218
219 if (ISSTRINGVARIANT(pVariant2->vt))
220 {
221 hr = PathExpand(&wzValue2, pVariant2->bstrVal, PATH_EXPAND_ENVIRONMENT | PATH_EXPAND_FULLPATH);
207 - ExitOnFailure(hr, "Failed to expand path %ls", pVariant2->bstrVal);
222 + IisExitOnFailure(hr, "Failed to expand path %ls", pVariant2->bstrVal);
223 }
224
225 fEqual = CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, wzValue1, -1, wzValue2, -1);
@@ -242,14 +257,14 @@ extern "C" BOOL DAPI Iis7IsMatchingAppHostElement(
257 VARIANTCOMPARATORPROC pComparator = pComparison->pComparator ? pComparison->pComparator : CompareVariantDefault;
258
259 hr = pElement->get_Name(&bstrElementName);
245 - ExitOnFailure(hr, "Failed to get name of element");
260 + IisExitOnFailure(hr, "Failed to get name of element");
261 if (CSTR_EQUAL != ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, pComparison->sczElementName, -1, bstrElementName, -1))
262 {
263 ExitFunction();
264 }
265
266 hr = Iis7GetPropertyVariant(pElement, pComparison->sczAttributeName, &vPropValue);
252 - ExitOnFailure(hr, "Failed to get value of %ls attribute of %ls element", pComparison->sczAttributeName, pComparison->sczElementName);
267 + IisExitOnFailure(hr, "Failed to get value of %ls attribute of %ls element", pComparison->sczAttributeName, pComparison->sczElementName);
268
269 if (TRUE == pComparator(pComparison->pvAttributeValue, &vPropValue))
270 {
@@ -274,7 +289,9 @@ BOOL DAPI IsMatchingAppHostMethod(
289 BSTR bstrName = NULL;
290
291 hr = pMethod->get_Name(&bstrName);
277 - ExitOnFailure(hr, "Failed to get name of element");
292 + IisExitOnFailure(hr, "Failed to get name of element");
293 +
294 + Assert(bstrName);
295
296 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, wzMethodName, -1, bstrName, -1))
297 {
@@ -303,7 +320,7 @@ extern "C" HRESULT DAPI Iis7FindAppHostElementPath(
320
321 vtValue.vt = VT_BSTR;
322 vtValue.bstrVal = ::SysAllocString(wzAttributeValue);
306 - ExitOnNull(vtValue.bstrVal, hr, E_OUTOFMEMORY, "failed SysAllocString");
323 + IisExitOnNull(vtValue.bstrVal, hr, E_OUTOFMEMORY, "failed SysAllocString");
324
325 comparison.sczElementName = wzElementName;
326 comparison.sczAttributeName = wzAttributeName;
@@ -337,7 +354,7 @@ extern "C" HRESULT DAPI Iis7FindAppHostElementString(
354
355 vtValue.vt = VT_BSTR;
356 vtValue.bstrVal = ::SysAllocString(wzAttributeValue);
340 - ExitOnNull(vtValue.bstrVal, hr, E_OUTOFMEMORY, "failed SysAllocString");
357 + IisExitOnNull(vtValue.bstrVal, hr, E_OUTOFMEMORY, "failed SysAllocString");
358
359 hr = Iis7FindAppHostElementVariant(pCollection,
360 wzElementName,
@@ -427,14 +444,14 @@ extern "C" HRESULT DAPI Iis7EnumAppHostElements(
444 }
445
446 hr = pCollection->get_Count(&dwElements);
430 - ExitOnFailure(hr, "Failed get application IAppHostElementCollection count");
447 + IisExitOnFailure(hr, "Failed get application IAppHostElementCollection count");
448
449 vtIndex.vt = VT_UI4;
450 for (DWORD i = 0; i < dwElements; ++i)
451 {
452 vtIndex.ulVal = i;
453 hr = pCollection->get_Item(vtIndex , &pElement);
437 - ExitOnFailure(hr, "Failed get IAppHostElement element");
454 + IisExitOnFailure(hr, "Failed get IAppHostElement element");
455
456 if (pCallback(pElement, pContext))
457 {
@@ -484,14 +501,14 @@ extern "C" HRESULT DAPI Iis7FindAppHostMethod(
501 }
502
503 hr = pCollection->get_Count(&dwMethods);
487 - ExitOnFailure(hr, "Failed get application IAppHostMethodCollection count");
504 + IisExitOnFailure(hr, "Failed get application IAppHostMethodCollection count");
505
506 vtIndex.vt = VT_UI4;
507 for (DWORD i = 0; i < dwMethods; ++i)
508 {
509 vtIndex.ulVal = i;
510 hr = pCollection->get_Item(vtIndex , &pMethod);
494 - ExitOnFailure(hr, "Failed get IAppHostMethod element");
511 + IisExitOnFailure(hr, "Failed get IAppHostMethod element");
512
513 if (IsMatchingAppHostMethod(pMethod, wzMethodName))
514 {
src/dutil/inc/atomutil.h
+1 -1
@@ -138,7 +138,7 @@ HRESULT DAPI AtomParseFromDocument(
138 );
139
140 void DAPI AtomFreeFeed(
141 - __in_xcount(pFeed->cItems) ATOM_FEED *pFEED
141 + __in_xcount(pFeed->cItems) ATOM_FEED* pFeed
142 );
143
144 #ifdef __cplusplus
src/dutil/inc/buffutil.h
+7 -7
@@ -50,37 +50,37 @@ HRESULT BuffReadStream(
50 __in_bcount(cbBuffer) const BYTE* pbBuffer,
51 __in SIZE_T cbBuffer,
52 __inout SIZE_T* piBuffer,
53 - __deref_out_bcount(*pcbStream) BYTE** ppbStream,
53 + __deref_inout_bcount(*pcbStream) BYTE** ppbStream,
54 __out SIZE_T* pcbStream
55 );
56
57 HRESULT BuffWriteNumber(
58 - __deref_out_bcount(*piBuffer) BYTE** ppbBuffer,
58 + __deref_inout_bcount(*piBuffer) BYTE** ppbBuffer,
59 __inout SIZE_T* piBuffer,
60 __in DWORD_PTR dw
61 );
62 HRESULT BuffWriteNumber64(
63 - __deref_out_bcount(*piBuffer) BYTE** ppbBuffer,
63 + __deref_inout_bcount(*piBuffer) BYTE** ppbBuffer,
64 __inout SIZE_T* piBuffer,
65 __in DWORD64 dw64
66 );
67 HRESULT BuffWritePointer(
68 - __deref_out_bcount(*piBuffer) BYTE** ppbBuffer,
68 + __deref_inout_bcount(*piBuffer) BYTE** ppbBuffer,
69 __inout SIZE_T* piBuffer,
70 __in DWORD_PTR dw
71 );
72 HRESULT BuffWriteString(
73 - __deref_out_bcount(*piBuffer) BYTE** ppbBuffer,
73 + __deref_inout_bcount(*piBuffer) BYTE** ppbBuffer,
74 __inout SIZE_T* piBuffer,
75 __in_z_opt LPCWSTR scz
76 );
77 HRESULT BuffWriteStringAnsi(
78 - __deref_out_bcount(*piBuffer) BYTE** ppbBuffer,
78 + __deref_inout_bcount(*piBuffer) BYTE** ppbBuffer,
79 __inout SIZE_T* piBuffer,
80 __in_z_opt LPCSTR scz
81 );
82 HRESULT BuffWriteStream(
83 - __deref_out_bcount(*piBuffer) BYTE** ppbBuffer,
83 + __deref_inout_bcount(*piBuffer) BYTE** ppbBuffer,
84 __inout SIZE_T* piBuffer,
85 __in_bcount(cbStream) const BYTE* pbStream,
86 __in SIZE_T cbStream
src/dutil/inc/conutil.h
+2 -2
@@ -55,12 +55,12 @@ HRESULT DAPI ConsoleReadW(
55 );
56
57 HRESULT DAPI ConsoleReadStringA(
58 - __deref_out_ecount_part(cchCharBuffer,*pcchNumCharReturn) LPSTR* szCharBuffer,
58 + __deref_inout_ecount_part(cchCharBuffer,*pcchNumCharReturn) LPSTR* szCharBuffer,
59 CONST DWORD cchCharBuffer,
60 __out DWORD* pcchNumCharReturn
61 );
62 HRESULT DAPI ConsoleReadStringW(
63 - __deref_out_ecount_part(cchCharBuffer,*pcchNumCharReturn) LPWSTR* szCharBuffer,
63 + __deref_inout_ecount_part(cchCharBuffer,*pcchNumCharReturn) LPWSTR* szCharBuffer,
64 CONST DWORD cchCharBuffer,
65 __out DWORD* pcchNumCharReturn
66 );
src/dutil/inc/deputil.h
+1 -1
@@ -55,7 +55,7 @@ DAPI_(HRESULT) DepCheckDependency(
55 DAPI_(HRESULT) DepCheckDependents(
56 __in HKEY hkHive,
57 __in_z LPCWSTR wzProviderKey,
58 - __in int iAttributes,
58 + __reserved int iAttributes,
59 __in C_STRINGDICT_HANDLE sdIgnoredDependents,
60 __deref_inout_ecount_opt(*pcDependents) DEPENDENCY** prgDependents,
61 __inout LPUINT pcDependents
src/dutil/inc/dutil.h
+1 -1
@@ -44,7 +44,7 @@ void DAPI DutilUninitialize();
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 LPCSTR szMessage);
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();
src/dutil/inc/eseutil.h
+1 -1
@@ -160,7 +160,7 @@ HRESULT DAPI EseGetColumnBinary(
160 __in JET_SESID jsSession,
161 __in ESE_TABLE_SCHEMA tsTable,
162 __in DWORD dwColumn,
163 - __deref_out_bcount(*piBuffer) BYTE** ppbBuffer,
163 + __deref_inout_bcount(*piBuffer) BYTE** ppbBuffer,
164 __inout SIZE_T* piBuffer
165 );
166 HRESULT DAPI EseGetColumnDword(
src/dutil/inc/fileutil.h
+1 -1
@@ -121,7 +121,7 @@ HRESULT DAPI FileReadPartial(
121 __in BOOL fPartialOK
122 );
123 HRESULT DAPI FileReadPartialEx(
124 - __deref_out_bcount_full(*pcbDest) LPBYTE* ppbDest,
124 + __deref_inout_bcount_full(*pcbDest) LPBYTE* ppbDest,
125 __out_range(<=, cbMaxRead) SIZE_T* pcbDest,
126 __in_z LPCWSTR wzSrcPath,
127 __in BOOL fSeek,
src/dutil/inc/inetutil.h
+1 -1
@@ -30,7 +30,7 @@ HRESULT DAPI InternetQueryInfoString(
30 HRESULT DAPI InternetQueryInfoNumber(
31 __in HINTERNET h,
32 __in DWORD dwInfo,
33 - __out LONG* plInfo
33 + __inout LONG* plInfo
34 );
35
36 #ifdef __cplusplus
src/dutil/inc/iniutil.h
+1 -1
@@ -55,7 +55,7 @@ HRESULT DAPI IniParse(
55 // (their value will be NULL)
56 HRESULT DAPI IniGetValueList(
57 __in_bcount(INI_HANDLE_BYTES) INI_HANDLE piHandle,
58 - __deref_out_ecount_opt(pcValues) INI_VALUE** prgivValues,
58 + __deref_out_ecount_opt(*pcValues) INI_VALUE** prgivValues,
59 __out DWORD *pcValues
60 );
61 HRESULT DAPI IniGetValue(
src/dutil/inc/memutil.h
+3 -3
@@ -39,13 +39,13 @@ HRESULT DAPI MemReAllocArray(
39 __in DWORD dwNewItemCount
40 );
41 HRESULT DAPI MemEnsureArraySize(
42 - __deref_out_bcount(cArray * cbArrayType) LPVOID* ppvArray,
42 + __deref_inout_bcount(cArray * cbArrayType) LPVOID* ppvArray,
43 __in DWORD cArray,
44 __in SIZE_T cbArrayType,
45 __in DWORD dwGrowthCount
46 );
47 HRESULT DAPI MemInsertIntoArray(
48 - __deref_out_bcount((cExistingArray + cInsertItems) * cbArrayType) LPVOID* ppvArray,
48 + __deref_inout_bcount((cExistingArray + cInsertItems) * cbArrayType) LPVOID* ppvArray,
49 __in DWORD dwInsertIndex,
50 __in DWORD cInsertItems,
51 __in DWORD cExistingArray,
@@ -61,7 +61,7 @@ void DAPI MemRemoveFromArray(
61 __in BOOL fPreserveOrder
62 );
63 void DAPI MemArraySwapItems(
64 - __inout_bcount((cExistingArray) * cbArrayType) LPVOID pvArray,
64 + __inout_bcount(cbArrayType) LPVOID pvArray,
65 __in DWORD dwIndex1,
66 __in DWORD dwIndex2,
67 __in SIZE_T cbArrayType
src/dutil/inc/pathutil.h
+3 -3
@@ -19,7 +19,7 @@ typedef enum PATH_EXPAND
19 (i.e. quote arguments with spaces in them).
20 ********************************************************************/
21 DAPI_(HRESULT) PathCommandLineAppend(
22 - __deref_out_z LPWSTR* psczCommandLine,
22 + __deref_inout_z LPWSTR* psczCommandLine,
23 __in_z LPCWSTR wzArgument
24 );
25
@@ -43,7 +43,7 @@ DAPI_(LPCWSTR) PathExtension(
43 ********************************************************************/
44 DAPI_(HRESULT) PathGetDirectory(
45 __in_z LPCWSTR wzPath,
46 - __out LPWSTR *psczDirectory
46 + __out_z LPWSTR *psczDirectory
47 );
48
49 /*******************************************************************
@@ -206,7 +206,7 @@ DAPI_(HRESULT) PathCompress(
206 *******************************************************************/
207 DAPI_(HRESULT) PathGetHierarchyArray(
208 __in_z LPCWSTR wzPath,
209 - __deref_inout_ecount_opt(*pcStrArray) LPWSTR **prgsczPathArray,
209 + __deref_inout_ecount_opt(*pcPathArray) LPWSTR **prgsczPathArray,
210 __inout LPUINT pcPathArray
211 );
212
src/dutil/inc/regutil.h
+4 -4
@@ -50,7 +50,7 @@ typedef LSTATUS (APIENTRY *PFN_REGENUMKEYEXW)(
50 __out LPWSTR lpName,
51 __inout LPDWORD lpcName,
52 __reserved LPDWORD lpReserved,
53 - __inout LPWSTR lpClass,
53 + __inout_opt LPWSTR lpClass,
54 __inout_opt LPDWORD lpcClass,
55 __out_opt PFILETIME lpftLastWriteTime
56 );
@@ -66,7 +66,7 @@ typedef LSTATUS (APIENTRY *PFN_REGENUMVALUEW)(
66 );
67 typedef LSTATUS (APIENTRY *PFN_REGQUERYINFOKEYW)(
68 __in HKEY hKey,
69 - __out LPWSTR lpClass,
69 + __out_opt LPWSTR lpClass,
70 __inout_opt LPDWORD lpcClass,
71 __reserved LPDWORD lpReserved,
72 __out_opt LPDWORD lpcSubKeys,
@@ -170,7 +170,7 @@ HRESULT DAPI RegReadString(
170 HRESULT DAPI RegReadStringArray(
171 __in HKEY hk,
172 __in_z_opt LPCWSTR wzName,
173 - __deref_out_ecount_opt(pcStrings) LPWSTR** prgsczStrings,
173 + __deref_out_ecount_opt(*pcStrings) LPWSTR** prgsczStrings,
174 __out DWORD *pcStrings
175 );
176 HRESULT DAPI RegReadVersion(
@@ -202,7 +202,7 @@ HRESULT DAPI RegWriteString(
202 HRESULT DAPI RegWriteStringArray(
203 __in HKEY hk,
204 __in_z_opt LPCWSTR wzName,
205 - __in_ecount(cValues) LPWSTR *rgwzStrings,
205 + __in_ecount(cStrings) LPWSTR *rgwzStrings,
206 __in DWORD cStrings
207 );
208 HRESULT DAPI RegWriteStringFormatted(
src/dutil/inc/shelutil.h
+3 -3
@@ -19,9 +19,9 @@ void DAPI ShelFunctionOverride(
19 );
20 HRESULT DAPI ShelExec(
21 __in_z LPCWSTR wzTargetPath,
22 - __in_opt LPCWSTR wzParameters,
23 - __in_opt LPCWSTR wzVerb,
24 - __in_opt LPCWSTR wzWorkingDirectory,
22 + __in_z_opt LPCWSTR wzParameters,
23 + __in_z_opt LPCWSTR wzVerb,
24 + __in_z_opt LPCWSTR wzWorkingDirectory,
25 __in int nShowCmd,
26 __in_opt HWND hwndParent,
27 __out_opt HANDLE* phProcess
src/dutil/inc/strutil.h
+2 -2
@@ -198,7 +198,7 @@ HRESULT DAPI StrAllocBase85Decode(
198
199 HRESULT DAPI MultiSzLen(
200 __in_ecount(*pcch) __nullnullterminated LPCWSTR pwzMultiSz,
201 - __out SIZE_T* pcbch
201 + __out SIZE_T* pcch
202 );
203 HRESULT DAPI MultiSzPrepend(
204 __deref_inout_ecount(*pcchMultiSz) __nullnullterminated LPWSTR* ppwzMultiSz,
@@ -222,7 +222,7 @@ HRESULT DAPI MultiSzRemoveString(
222 __in DWORD_PTR dwIndex
223 );
224 HRESULT DAPI MultiSzInsertString(
225 - __deref_inout_z LPWSTR* ppwzMultiSz,
225 + __deref_inout __nullnullterminated LPWSTR* ppwzMultiSz,
226 __inout_opt SIZE_T* pcchMultiSz,
227 __in DWORD_PTR dwIndex,
228 __in_z LPCWSTR pwzInsert
src/dutil/inc/thmutil.h
+1 -1
@@ -737,7 +737,7 @@ HRESULT DAPI ThemeSetTextControlEx(
737 HRESULT DAPI ThemeGetTextControl(
738 __in const THEME* pTheme,
739 __in DWORD dwControl,
740 - __out_z LPWSTR* psczText
740 + __inout_z LPWSTR* psczText
741 );
742
743 /********************************************************************
src/dutil/inc/uriutil.h
+1 -1
@@ -91,7 +91,7 @@ HRESULT DAPI UriResolve(
91 __in_z LPCWSTR wzUri,
92 __in_opt LPCWSTR wzBaseUri,
93 __out LPWSTR* ppwzResolvedUri,
94 - __out_opt const URI_PROTOCOL* pResolvedProtocol
94 + __out_opt URI_PROTOCOL* pResolvedProtocol
95 );
96
97 #ifdef __cplusplus
src/dutil/inc/wiutil.h
+1 -1
@@ -330,7 +330,7 @@ HRESULT DAPI WiuEnumRelatedProducts(
330 );
331 HRESULT DAPI WiuEnumRelatedProductCodes(
332 __in_z LPCWSTR wzUpgradeCode,
333 - __deref_out_ecount_opt(pcRelatedProducts) LPWSTR** prgsczProductCodes,
333 + __deref_out_ecount_opt(*pcRelatedProducts) LPWSTR** prgsczProductCodes,
334 __out DWORD* pcRelatedProducts,
335 __in BOOL fReturnHighestVersionOnly
336 );
src/dutil/inetutil.cpp
+26 -11
@@ -3,6 +3,21 @@
3 #include "precomp.h"
4
5
6 +// Exit macros
7 +#define InetExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_INETUTIL, x, s, __VA_ARGS__)
8 +#define InetExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_INETUTIL, x, s, __VA_ARGS__)
9 +#define InetExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_INETUTIL, x, s, __VA_ARGS__)
10 +#define InetExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_INETUTIL, x, s, __VA_ARGS__)
11 +#define InetExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_INETUTIL, x, s, __VA_ARGS__)
12 +#define InetExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_INETUTIL, x, s, __VA_ARGS__)
13 +#define InetExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_INETUTIL, p, x, e, s, __VA_ARGS__)
14 +#define InetExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_INETUTIL, p, x, s, __VA_ARGS__)
15 +#define InetExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_INETUTIL, p, x, e, s, __VA_ARGS__)
16 +#define InetExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_INETUTIL, p, x, s, __VA_ARGS__)
17 +#define InetExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_INETUTIL, e, x, s, __VA_ARGS__)
18 +#define InetExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_INETUTIL, g, x, s, __VA_ARGS__)
19 +
20 +
21 /*******************************************************************
22 InternetGetSizeByHandle - returns size of file by url handle
23
@@ -15,13 +30,13 @@ extern "C" HRESULT DAPI InternetGetSizeByHandle(
30 Assert(pllSize);
31
32 HRESULT hr = S_OK;
18 - DWORD dwSize;
19 - DWORD cb;
33 + DWORD dwSize = 0;
34 + DWORD cb = 0;
35
36 cb = sizeof(dwSize);
37 if (!::HttpQueryInfoW(hiFile, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, reinterpret_cast<LPVOID>(&dwSize), &cb, NULL))
38 {
24 - ExitOnLastError(hr, "Failed to get size for internet file handle");
39 + InetExitOnLastError(hr, "Failed to get size for internet file handle");
40 }
41
42 *pllSize = dwSize;
@@ -47,12 +62,12 @@ extern "C" HRESULT DAPI InternetGetCreateTimeByHandle(
62
63 if (!::HttpQueryInfoW(hiFile, HTTP_QUERY_LAST_MODIFIED | HTTP_QUERY_FLAG_SYSTEMTIME, reinterpret_cast<LPVOID>(&st), &cb, NULL))
64 {
50 - ExitWithLastError(hr, "failed to get create time for internet file handle");
65 + InetExitWithLastError(hr, "failed to get create time for internet file handle");
66 }
67
68 if (!::SystemTimeToFileTime(&st, pft))
69 {
55 - ExitWithLastError(hr, "failed to convert system time to file time");
70 + InetExitWithLastError(hr, "failed to convert system time to file time");
71 }
72
73 LExit:
@@ -78,11 +93,11 @@ extern "C" HRESULT DAPI InternetQueryInfoString(
93 if (!*psczValue)
94 {
95 hr = StrAlloc(psczValue, 64);
81 - ExitOnFailure(hr, "Failed to allocate memory for value.");
96 + InetExitOnFailure(hr, "Failed to allocate memory for value.");
97 }
98
99 hr = StrSize(*psczValue, &cbValue);
85 - ExitOnFailure(hr, "Failed to get size of value.");
100 + InetExitOnFailure(hr, "Failed to get size of value.");
101
102 if (!::HttpQueryInfoW(hRequest, dwInfo, static_cast<void*>(*psczValue), reinterpret_cast<DWORD*>(&cbValue), &dwIndex))
103 {
@@ -92,7 +107,7 @@ extern "C" HRESULT DAPI InternetQueryInfoString(
107 cbValue += sizeof(WCHAR); // add one character for the null terminator.
108
109 hr = StrAlloc(psczValue, cbValue / sizeof(WCHAR));
95 - ExitOnFailure(hr, "Failed to allocate value.");
110 + InetExitOnFailure(hr, "Failed to allocate value.");
111
112 if (!::HttpQueryInfoW(hRequest, dwInfo, static_cast<void*>(*psczValue), reinterpret_cast<DWORD*>(&cbValue), &dwIndex))
113 {
@@ -105,7 +120,7 @@ extern "C" HRESULT DAPI InternetQueryInfoString(
120 }
121
122 hr = HRESULT_FROM_WIN32(er);
108 - ExitOnRootFailure(hr, "Failed to get query information.");
123 + InetExitOnRootFailure(hr, "Failed to get query information.");
124 }
125
126 LExit:
@@ -120,7 +135,7 @@ LExit:
135 extern "C" HRESULT DAPI InternetQueryInfoNumber(
136 __in HINTERNET hRequest,
137 __in DWORD dwInfo,
123 - __out LONG* plInfo
138 + __inout LONG* plInfo
139 )
140 {
141 HRESULT hr = S_OK;
@@ -129,7 +144,7 @@ extern "C" HRESULT DAPI InternetQueryInfoNumber(
144
145 if (!::HttpQueryInfoW(hRequest, dwInfo | HTTP_QUERY_FLAG_NUMBER, static_cast<void*>(plInfo), &cbCode, &dwIndex))
146 {
132 - ExitWithLastError(hr, "Failed to get query information.");
147 + InetExitWithLastError(hr, "Failed to get query information.");
148 }
149
150 LExit:
src/dutil/iniutil.cpp
+61 -46
@@ -2,6 +2,21 @@
2
3 #include "precomp.h"
4
5 +
6 +// Exit macros
7 +#define IniExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_INIUTIL, x, s, __VA_ARGS__)
8 +#define IniExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_INIUTIL, x, s, __VA_ARGS__)
9 +#define IniExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_INIUTIL, x, s, __VA_ARGS__)
10 +#define IniExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_INIUTIL, x, s, __VA_ARGS__)
11 +#define IniExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_INIUTIL, x, s, __VA_ARGS__)
12 +#define IniExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_INIUTIL, x, s, __VA_ARGS__)
13 +#define IniExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_INIUTIL, p, x, e, s, __VA_ARGS__)
14 +#define IniExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_INIUTIL, p, x, s, __VA_ARGS__)
15 +#define IniExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_INIUTIL, p, x, e, s, __VA_ARGS__)
16 +#define IniExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_INIUTIL, p, x, s, __VA_ARGS__)
17 +#define IniExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_INIUTIL, e, x, s, __VA_ARGS__)
18 +#define IniExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_INIUTIL, g, x, s, __VA_ARGS__)
19 +
20 const LPCWSTR wzSectionSeparator = L"\\";
21
22 struct INI_STRUCT
@@ -33,7 +48,7 @@ const int INI_HANDLE_BYTES = sizeof(INI_STRUCT);
48
49 static HRESULT GetSectionPrefixFromName(
50 __in_z LPCWSTR wzName,
36 - __deref_out_z LPWSTR* psczOutput
51 + __deref_inout_z LPWSTR* psczOutput
52 );
53 static void UninitializeIniValue(
54 INI_VALUE *pivValue
@@ -47,7 +62,7 @@ extern "C" HRESULT DAPI IniInitialize(
62
63 // Allocate the handle
64 *piHandle = static_cast<INI_HANDLE>(MemAlloc(sizeof(INI_STRUCT), TRUE));
50 - ExitOnNull(*piHandle, hr, E_OUTOFMEMORY, "Failed to allocate ini object");
65 + IniExitOnNull(*piHandle, hr, E_OUTOFMEMORY, "Failed to allocate ini object");
66
67 LExit:
68 return hr;
@@ -96,7 +111,7 @@ extern "C" HRESULT DAPI IniSetOpenTag(
111 if (wzOpenTagPrefix)
112 {
113 hr = StrAllocString(&pi->sczOpenTagPrefix, wzOpenTagPrefix, 0);
99 - ExitOnFailure(hr, "Failed to copy open tag prefix to ini struct: %ls", wzOpenTagPrefix);
114 + IniExitOnFailure(hr, "Failed to copy open tag prefix to ini struct: %ls", wzOpenTagPrefix);
115 }
116 else
117 {
@@ -106,7 +121,7 @@ extern "C" HRESULT DAPI IniSetOpenTag(
121 if (wzOpenTagPostfix)
122 {
123 hr = StrAllocString(&pi->sczOpenTagPostfix, wzOpenTagPostfix, 0);
109 - ExitOnFailure(hr, "Failed to copy open tag postfix to ini struct: %ls", wzOpenTagPostfix);
124 + IniExitOnFailure(hr, "Failed to copy open tag postfix to ini struct: %ls", wzOpenTagPostfix);
125 }
126 else
127 {
@@ -130,7 +145,7 @@ extern "C" HRESULT DAPI IniSetValueStyle(
145 if (wzValuePrefix)
146 {
147 hr = StrAllocString(&pi->sczValuePrefix, wzValuePrefix, 0);
133 - ExitOnFailure(hr, "Failed to copy value prefix to ini struct: %ls", wzValuePrefix);
148 + IniExitOnFailure(hr, "Failed to copy value prefix to ini struct: %ls", wzValuePrefix);
149 }
150 else
151 {
@@ -140,7 +155,7 @@ extern "C" HRESULT DAPI IniSetValueStyle(
155 if (wzValueSeparator)
156 {
157 hr = StrAllocString(&pi->sczValueSeparator, wzValueSeparator, 0);
143 - ExitOnFailure(hr, "Failed to copy value separator to ini struct: %ls", wzValueSeparator);
158 + IniExitOnFailure(hr, "Failed to copy value separator to ini struct: %ls", wzValueSeparator);
159 }
160 else
161 {
@@ -162,12 +177,12 @@ extern "C" HRESULT DAPI IniSetValueSeparatorException(
177 INI_STRUCT *pi = static_cast<INI_STRUCT *>(piHandle);
178
179 hr = MemEnsureArraySize(reinterpret_cast<void **>(&pi->rgsczValueSeparatorExceptions), pi->cValueSeparatorExceptions + 1, sizeof(LPWSTR), 5);
165 - ExitOnFailure(hr, "Failed to increase array size for value separator exceptions");
180 + IniExitOnFailure(hr, "Failed to increase array size for value separator exceptions");
181 dwInsertedIndex = pi->cValueSeparatorExceptions;
182 ++pi->cValueSeparatorExceptions;
183
184 hr = StrAllocString(&pi->rgsczValueSeparatorExceptions[dwInsertedIndex], wzValueNamePrefix, 0);
170 - ExitOnFailure(hr, "Failed to copy value separator exception");
185 + IniExitOnFailure(hr, "Failed to copy value separator exception");
186
187 LExit:
188 return hr;
@@ -185,7 +200,7 @@ extern "C" HRESULT DAPI IniSetCommentStyle(
200 if (wzLinePrefix)
201 {
202 hr = StrAllocString(&pi->sczCommentLinePrefix, wzLinePrefix, 0);
188 - ExitOnFailure(hr, "Failed to copy comment line prefix to ini struct: %ls", wzLinePrefix);
203 + IniExitOnFailure(hr, "Failed to copy comment line prefix to ini struct: %ls", wzLinePrefix);
204 }
205 else
206 {
@@ -226,10 +241,10 @@ extern "C" HRESULT DAPI IniParse(
241 BOOL fValuePrefix = (NULL != pi->sczValuePrefix);
242
243 hr = StrAllocString(&pi->sczPath, wzPath, 0);
229 - ExitOnFailure(hr, "Failed to copy path to ini struct: %ls", wzPath);
244 + IniExitOnFailure(hr, "Failed to copy path to ini struct: %ls", wzPath);
245
246 hr = FileToString(pi->sczPath, &sczContents, &pi->feEncoding);
232 - ExitOnFailure(hr, "Failed to convert file to string: %ls", pi->sczPath);
247 + IniExitOnFailure(hr, "Failed to convert file to string: %ls", pi->sczPath);
248
249 if (pfeEncodingFound)
250 {
@@ -244,7 +259,7 @@ extern "C" HRESULT DAPI IniParse(
259
260 dwValuePrefixLength = lstrlenW(pi->sczValuePrefix);
261 hr = StrSplitAllocArray(&pi->rgsczLines, reinterpret_cast<UINT *>(&pi->cLines), sczContents, L"\n");
247 - ExitOnFailure(hr, "Failed to split INI file into lines");
262 + IniExitOnFailure(hr, "Failed to split INI file into lines");
263
264 for (DWORD i = 0; i < pi->cLines; ++i)
265 {
@@ -324,7 +339,7 @@ extern "C" HRESULT DAPI IniParse(
339 {
340 // There is an section starting here, let's keep track of it and move on
341 hr = StrAllocString(&sczCurrentSection, wzOpenTagPrefix + lstrlenW(pi->sczOpenTagPrefix), wzOpenTagPostfix - (wzOpenTagPrefix + lstrlenW(pi->sczOpenTagPrefix)));
327 - ExitOnFailure(hr, "Failed to record section name for line: %ls of INI file: %ls", pi->rgsczLines[i], pi->sczPath);
342 + IniExitOnFailure(hr, "Failed to record section name for line: %ls of INI file: %ls", pi->rgsczLines[i], pi->sczPath);
343
344 // Sections will be calculated dynamically after any set operations, so don't include this in the list of lines to remember for output
345 ReleaseNullStr(pi->rgsczLines[i]);
@@ -342,28 +357,28 @@ extern "C" HRESULT DAPI IniParse(
357 }
358
359 hr = MemEnsureArraySize(reinterpret_cast<void **>(&pi->rgivValues), pi->cValues + 1, sizeof(INI_VALUE), 100);
345 - ExitOnFailure(hr, "Failed to increase array size for value array");
360 + IniExitOnFailure(hr, "Failed to increase array size for value array");
361
362 if (sczCurrentSection)
363 {
364 hr = StrAllocString(&sczName, sczCurrentSection, 0);
350 - ExitOnFailure(hr, "Failed to copy current section name");
365 + IniExitOnFailure(hr, "Failed to copy current section name");
366
367 hr = StrAllocConcat(&sczName, wzSectionSeparator, 0);
353 - ExitOnFailure(hr, "Failed to copy current section name");
368 + IniExitOnFailure(hr, "Failed to copy current section name");
369 }
370
371 hr = StrAllocConcat(&sczName, wzValueBegin, wzValueSeparator - wzValueBegin);
357 - ExitOnFailure(hr, "Failed to copy name");
372 + IniExitOnFailure(hr, "Failed to copy name");
373
374 hr = StrAllocString(&sczValue, wzValueSeparator + lstrlenW(pi->sczValueSeparator), 0);
360 - ExitOnFailure(hr, "Failed to copy value");
375 + IniExitOnFailure(hr, "Failed to copy value");
376
377 hr = StrTrimWhitespace(&sczNameTrimmed, sczName);
363 - ExitOnFailure(hr, "Failed to trim whitespace from name");
378 + IniExitOnFailure(hr, "Failed to trim whitespace from name");
379
380 hr = StrTrimWhitespace(&sczValueTrimmed, sczValue);
366 - ExitOnFailure(hr, "Failed to trim whitespace from value");
381 + IniExitOnFailure(hr, "Failed to trim whitespace from value");
382
383 pi->rgivValues[pi->cValues].wzName = const_cast<LPCWSTR>(sczNameTrimmed);
384 sczNameTrimmed = NULL;
@@ -397,7 +412,7 @@ LExit:
412
413 extern "C" HRESULT DAPI IniGetValueList(
414 __in_bcount(INI_HANDLE_BYTES) INI_HANDLE piHandle,
400 - __deref_out_ecount_opt(pcValues) INI_VALUE** prgivValues,
415 + __deref_out_ecount_opt(*pcValues) INI_VALUE** prgivValues,
416 __out DWORD *pcValues
417 )
418 {
@@ -434,7 +449,7 @@ extern "C" HRESULT DAPI IniGetValue(
449 if (NULL == pValue)
450 {
451 hr = E_NOTFOUND;
437 - ExitOnFailure(hr, "Failed to check for INI value: %ls", wzValueName);
452 + IniExitOnFailure(hr, "Failed to check for INI value: %ls", wzValueName);
453 }
454
455 if (NULL == pValue->wzValue)
@@ -443,7 +458,7 @@ extern "C" HRESULT DAPI IniGetValue(
458 }
459
460 hr = StrAllocString(psczValue, pValue->wzValue, 0);
446 - ExitOnFailure(hr, "Failed to make copy of value while looking up INI value named: %ls", wzValueName);
461 + IniExitOnFailure(hr, "Failed to make copy of value while looking up INI value named: %ls", wzValueName);
462
463 LExit:
464 return hr;
@@ -494,7 +509,7 @@ extern "C" HRESULT DAPI IniSetValue(
509 {
510 pi->fModified = TRUE;
511 hr = StrAllocString(const_cast<LPWSTR *>(&pValue->wzValue), wzValue, 0);
497 - ExitOnFailure(hr, "Failed to update value INI value named: %ls", wzValueName);
512 + IniExitOnFailure(hr, "Failed to update value INI value named: %ls", wzValueName);
513 }
514
515 ExitFunction1(hr = S_OK);
@@ -504,7 +519,7 @@ extern "C" HRESULT DAPI IniSetValue(
519 if (wzValueName)
520 {
521 hr = GetSectionPrefixFromName(wzValueName, &sczSectionPrefix);
507 - ExitOnFailure(hr, "Failed to get section prefix from value name: %ls", wzValueName);
522 + IniExitOnFailure(hr, "Failed to get section prefix from value name: %ls", wzValueName);
523 }
524
525 // If we have a section prefix, figure out the index to insert it (at the end of the section it belongs in)
@@ -545,13 +560,13 @@ extern "C" HRESULT DAPI IniSetValue(
560
561 pi->fModified = TRUE;
562 hr = MemInsertIntoArray(reinterpret_cast<void **>(&pi->rgivValues), dwInsertIndex, 1, pi->cValues + 1, sizeof(INI_VALUE), 100);
548 - ExitOnFailure(hr, "Failed to insert value into array");
563 + IniExitOnFailure(hr, "Failed to insert value into array");
564
565 hr = StrAllocString(&sczName, wzValueName, 0);
551 - ExitOnFailure(hr, "Failed to copy name");
566 + IniExitOnFailure(hr, "Failed to copy name");
567
568 hr = StrAllocString(&sczValue, wzValue, 0);
554 - ExitOnFailure(hr, "Failed to copy value");
569 + IniExitOnFailure(hr, "Failed to copy value");
570
571 pi->rgivValues[dwInsertIndex].wzName = const_cast<LPCWSTR>(sczName);
572 sczName = NULL;
@@ -611,7 +626,7 @@ extern "C" HRESULT DAPI IniWriteFile(
626 BOOL fSections = (pi->sczOpenTagPrefix) && (pi->sczOpenTagPostfix);
627
628 hr = StrAllocString(&sczContents, L"", 0);
614 - ExitOnFailure(hr, "Failed to begin contents string as empty string");
629 + IniExitOnFailure(hr, "Failed to begin contents string as empty string");
630
631 // Insert any beginning lines we didn't understand like comments
632 if (0 < pi->cLines)
@@ -619,10 +634,10 @@ extern "C" HRESULT DAPI IniWriteFile(
634 while (pi->rgsczLines[dwLineArrayIndex])
635 {
636 hr = StrAllocConcat(&sczContents, pi->rgsczLines[dwLineArrayIndex], 0);
622 - ExitOnFailure(hr, "Failed to add previous line to ini output buffer in-memory");
637 + IniExitOnFailure(hr, "Failed to add previous line to ini output buffer in-memory");
638
639 hr = StrAllocConcat(&sczContents, L"\r\n", 2);
625 - ExitOnFailure(hr, "Failed to add endline to ini output buffer in-memory");
640 + IniExitOnFailure(hr, "Failed to add endline to ini output buffer in-memory");
641
642 ++dwLineArrayIndex;
643 }
@@ -640,23 +655,23 @@ extern "C" HRESULT DAPI IniWriteFile(
655
656 // First see if we need to write a section line
657 hr = GetSectionPrefixFromName(pi->rgivValues[i].wzName, &sczNewSectionPrefix);
643 - ExitOnFailure(hr, "Failed to get section prefix from name: %ls", pi->rgivValues[i].wzName);
658 + IniExitOnFailure(hr, "Failed to get section prefix from name: %ls", pi->rgivValues[i].wzName);
659
660 // If the new section prefix is different, write a section out for it
661 if (fSections && sczNewSectionPrefix && (NULL == sczCurrentSectionPrefix || CSTR_EQUAL != ::CompareStringW(LOCALE_INVARIANT, 0, sczNewSectionPrefix, -1, sczCurrentSectionPrefix, -1)))
662 {
663 hr = StrAllocConcat(&sczContents, pi->sczOpenTagPrefix, 0);
649 - ExitOnFailure(hr, "Failed to concat open tag prefix to string");
664 + IniExitOnFailure(hr, "Failed to concat open tag prefix to string");
665
666 // Exclude section separator (i.e. backslash) from new section prefix
667 hr = StrAllocConcat(&sczContents, sczNewSectionPrefix, lstrlenW(sczNewSectionPrefix)-lstrlenW(wzSectionSeparator));
653 - ExitOnFailure(hr, "Failed to concat section name to string");
668 + IniExitOnFailure(hr, "Failed to concat section name to string");
669
670 hr = StrAllocConcat(&sczContents, pi->sczOpenTagPostfix, 0);
656 - ExitOnFailure(hr, "Failed to concat open tag postfix to string");
671 + IniExitOnFailure(hr, "Failed to concat open tag postfix to string");
672
673 hr = StrAllocConcat(&sczContents, L"\r\n", 2);
659 - ExitOnFailure(hr, "Failed to add endline to ini output buffer in-memory");
674 + IniExitOnFailure(hr, "Failed to add endline to ini output buffer in-memory");
675
676 ReleaseNullStr(sczCurrentSectionPrefix);
677 sczCurrentSectionPrefix = sczNewSectionPrefix;
@@ -674,10 +689,10 @@ extern "C" HRESULT DAPI IniWriteFile(
689 }
690
691 hr = StrAllocConcat(&sczContents, pi->rgsczLines[dwLineArrayIndex++], 0);
677 - ExitOnFailure(hr, "Failed to add previous line to ini output buffer in-memory");
692 + IniExitOnFailure(hr, "Failed to add previous line to ini output buffer in-memory");
693
694 hr = StrAllocConcat(&sczContents, L"\r\n", 2);
680 - ExitOnFailure(hr, "Failed to add endline to ini output buffer in-memory");
695 + IniExitOnFailure(hr, "Failed to add endline to ini output buffer in-memory");
696 }
697
698 wzName = pi->rgivValues[i].wzName;
@@ -690,20 +705,20 @@ extern "C" HRESULT DAPI IniWriteFile(
705 if (pi->sczValuePrefix)
706 {
707 hr = StrAllocConcat(&sczContents, pi->sczValuePrefix, 0);
693 - ExitOnFailure(hr, "Failed to concat value prefix to ini output buffer");
708 + IniExitOnFailure(hr, "Failed to concat value prefix to ini output buffer");
709 }
710
711 hr = StrAllocConcat(&sczContents, wzName, 0);
697 - ExitOnFailure(hr, "Failed to concat value name to ini output buffer");
712 + IniExitOnFailure(hr, "Failed to concat value name to ini output buffer");
713
714 hr = StrAllocConcat(&sczContents, pi->sczValueSeparator, 0);
700 - ExitOnFailure(hr, "Failed to concat value separator to ini output buffer");
715 + IniExitOnFailure(hr, "Failed to concat value separator to ini output buffer");
716
717 hr = StrAllocConcat(&sczContents, pi->rgivValues[i].wzValue, 0);
703 - ExitOnFailure(hr, "Failed to concat value to ini output buffer");
718 + IniExitOnFailure(hr, "Failed to concat value to ini output buffer");
719
720 hr = StrAllocConcat(&sczContents, L"\r\n", 2);
706 - ExitOnFailure(hr, "Failed to add endline to ini output buffer in-memory");
721 + IniExitOnFailure(hr, "Failed to add endline to ini output buffer in-memory");
722 }
723
724 // If no path was specified, use the path to the file we parsed
@@ -713,7 +728,7 @@ extern "C" HRESULT DAPI IniWriteFile(
728 }
729
730 hr = FileFromString(wzPath, 0, sczContents, feEncoding);
716 - ExitOnFailure(hr, "Failed to write INI contents out to file: %ls", wzPath);
731 + IniExitOnFailure(hr, "Failed to write INI contents out to file: %ls", wzPath);
732
733 LExit:
734 ReleaseStr(sczContents);
@@ -733,7 +748,7 @@ static void UninitializeIniValue(
748
749 static HRESULT GetSectionPrefixFromName(
750 __in_z LPCWSTR wzName,
736 - __deref_out_z LPWSTR* psczOutput
751 + __deref_inout_z LPWSTR* psczOutput
752 )
753 {
754 HRESULT hr = S_OK;
@@ -745,7 +760,7 @@ static HRESULT GetSectionPrefixFromName(
760 if (wzSectionDelimiter && wzSectionDelimiter != wzName)
761 {
762 hr = StrAllocString(psczOutput, wzName, wzSectionDelimiter - wzName + 1);
748 - ExitOnFailure(hr, "Failed to copy section prefix");
763 + IniExitOnFailure(hr, "Failed to copy section prefix");
764 }
765
766 LExit:
src/dutil/jsonutil.cpp
+47 -32
@@ -2,6 +2,21 @@
2
3 #include "precomp.h"
4
5 +
6 +// Exit macros
7 +#define JsonExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_JSONUTIL, x, s, __VA_ARGS__)
8 +#define JsonExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_JSONUTIL, x, s, __VA_ARGS__)
9 +#define JsonExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_JSONUTIL, x, s, __VA_ARGS__)
10 +#define JsonExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_JSONUTIL, x, s, __VA_ARGS__)
11 +#define JsonExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_JSONUTIL, x, s, __VA_ARGS__)
12 +#define JsonExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_JSONUTIL, x, s, __VA_ARGS__)
13 +#define JsonExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_JSONUTIL, p, x, e, s, __VA_ARGS__)
14 +#define JsonExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_JSONUTIL, p, x, s, __VA_ARGS__)
15 +#define JsonExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_JSONUTIL, p, x, e, s, __VA_ARGS__)
16 +#define JsonExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_JSONUTIL, p, x, s, __VA_ARGS__)
17 +#define JsonExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_JSONUTIL, e, x, s, __VA_ARGS__)
18 +#define JsonExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_JSONUTIL, g, x, s, __VA_ARGS__)
19 +
20 const DWORD JSON_STACK_INCREMENT = 5;
21
22 // Prototypes
@@ -44,7 +59,7 @@ DAPI_(HRESULT) JsonInitializeReader(
59 ::InitializeCriticalSection(&pReader->cs);
60
61 hr = StrAllocString(&pReader->sczJson, wzJson, 0);
47 - ExitOnFailure(hr, "Failed to allocate json string.");
62 + JsonExitOnFailure(hr, "Failed to allocate json string.");
63
64 pReader->pwz = pReader->sczJson;
65
@@ -153,7 +168,7 @@ DAPI_(HRESULT) JsonReadNext(
168 {
169 ExitFunction();
170 }
156 - ExitOnFailure(hr, "Failed to get next token.");
171 + JsonExitOnFailure(hr, "Failed to get next token.");
172
173 if (JSON_TOKEN_VALUE == *pToken)
174 {
@@ -214,10 +229,10 @@ DAPI_(HRESULT) JsonWriteBool(
229 LPWSTR sczValue = NULL;
230
231 hr = StrAllocString(&sczValue, fValue ? L"true" : L"false", 0);
217 - ExitOnFailure(hr, "Failed to convert boolean to string.");
232 + JsonExitOnFailure(hr, "Failed to convert boolean to string.");
233
234 hr = DoValue(pWriter, sczValue);
220 - ExitOnFailure(hr, "Failed to add boolean to JSON.");
235 + JsonExitOnFailure(hr, "Failed to add boolean to JSON.");
236
237 LExit:
238 ReleaseStr(sczValue);
@@ -234,10 +249,10 @@ DAPI_(HRESULT) JsonWriteNumber(
249 LPWSTR sczValue = NULL;
250
251 hr = StrAllocFormatted(&sczValue, L"%u", dwValue);
237 - ExitOnFailure(hr, "Failed to convert number to string.");
252 + JsonExitOnFailure(hr, "Failed to convert number to string.");
253
254 hr = DoValue(pWriter, sczValue);
240 - ExitOnFailure(hr, "Failed to add number to JSON.");
255 + JsonExitOnFailure(hr, "Failed to add number to JSON.");
256
257 LExit:
258 ReleaseStr(sczValue);
@@ -254,10 +269,10 @@ DAPI_(HRESULT) JsonWriteString(
269 LPWSTR sczJsonString = NULL;
270
271 hr = SerializeJsonString(&sczJsonString, wzValue);
257 - ExitOnFailure(hr, "Failed to allocate string JSON.");
272 + JsonExitOnFailure(hr, "Failed to allocate string JSON.");
273
274 hr = DoValue(pWriter, sczJsonString);
260 - ExitOnFailure(hr, "Failed to add string to JSON.");
275 + JsonExitOnFailure(hr, "Failed to add string to JSON.");
276
277 LExit:
278 ReleaseStr(sczJsonString);
@@ -272,7 +287,7 @@ DAPI_(HRESULT) JsonWriteArrayStart(
287 HRESULT hr = S_OK;
288
289 hr = DoStart(pWriter, JSON_TOKEN_ARRAY_START, L"[");
275 - ExitOnFailure(hr, "Failed to start JSON array.");
290 + JsonExitOnFailure(hr, "Failed to start JSON array.");
291
292 LExit:
293 return hr;
@@ -286,7 +301,7 @@ DAPI_(HRESULT) JsonWriteArrayEnd(
301 HRESULT hr = S_OK;
302
303 hr = DoEnd(pWriter, JSON_TOKEN_ARRAY_END, L"]");
289 - ExitOnFailure(hr, "Failed to end JSON array.");
304 + JsonExitOnFailure(hr, "Failed to end JSON array.");
305
306 LExit:
307 return hr;
@@ -300,7 +315,7 @@ DAPI_(HRESULT) JsonWriteObjectStart(
315 HRESULT hr = S_OK;
316
317 hr = DoStart(pWriter, JSON_TOKEN_OBJECT_START, L"{");
303 - ExitOnFailure(hr, "Failed to start JSON object.");
318 + JsonExitOnFailure(hr, "Failed to start JSON object.");
319
320 LExit:
321 return hr;
@@ -316,10 +331,10 @@ DAPI_(HRESULT) JsonWriteObjectKey(
331 LPWSTR sczObjectKey = NULL;
332
333 hr = StrAllocFormatted(&sczObjectKey, L"\"%ls\":", wzKey);
319 - ExitOnFailure(hr, "Failed to allocate JSON object key.");
334 + JsonExitOnFailure(hr, "Failed to allocate JSON object key.");
335
336 hr = DoKey(pWriter, sczObjectKey);
322 - ExitOnFailure(hr, "Failed to add object key to JSON.");
337 + JsonExitOnFailure(hr, "Failed to add object key to JSON.");
338
339 LExit:
340 ReleaseStr(sczObjectKey);
@@ -334,7 +349,7 @@ DAPI_(HRESULT) JsonWriteObjectEnd(
349 HRESULT hr = S_OK;
350
351 hr = DoEnd(pWriter, JSON_TOKEN_OBJECT_END, L"}");
337 - ExitOnFailure(hr, "Failed to end JSON object.");
352 + JsonExitOnFailure(hr, "Failed to end JSON object.");
353
354 LExit:
355 return hr;
@@ -357,7 +372,7 @@ static HRESULT DoStart(
372 ::EnterCriticalSection(&pWriter->cs);
373
374 hr = EnsureTokenStack(pWriter);
360 - ExitOnFailure(hr, "Failed to ensure token stack for start.");
375 + JsonExitOnFailure(hr, "Failed to ensure token stack for start.");
376
377 token = pWriter->rgTokenStack[pWriter->cTokens - 1];
378 switch (token)
@@ -381,16 +396,16 @@ static HRESULT DoStart(
396 hr = E_UNEXPECTED;
397 break;
398 }
384 - ExitOnRootFailure(hr, "Cannot start array or object to JSON serializer now.");
399 + JsonExitOnRootFailure(hr, "Cannot start array or object to JSON serializer now.");
400
401 if (fNeedComma)
402 {
403 hr = StrAllocConcat(&pWriter->sczJson, L",", 0);
389 - ExitOnFailure(hr, "Failed to add comma for start array or object to JSON.");
404 + JsonExitOnFailure(hr, "Failed to add comma for start array or object to JSON.");
405 }
406
407 hr = StrAllocConcat(&pWriter->sczJson, wzStartString, 0);
393 - ExitOnFailure(hr, "Failed to start JSON array or object.");
408 + JsonExitOnFailure(hr, "Failed to start JSON array or object.");
409
410 pWriter->rgTokenStack[pWriter->cTokens - 1] = token;
411 if (fPushToken)
@@ -418,7 +433,7 @@ static HRESULT DoEnd(
433 if (!pWriter->rgTokenStack || 0 == pWriter->cTokens)
434 {
435 hr = E_UNEXPECTED;
421 - ExitOnRootFailure(hr, "Failure to pop token because the stack is empty.");
436 + JsonExitOnRootFailure(hr, "Failure to pop token because the stack is empty.");
437 }
438 else
439 {
@@ -427,12 +442,12 @@ static HRESULT DoEnd(
442 (JSON_TOKEN_OBJECT_END == tokenEnd && JSON_TOKEN_OBJECT_START != token && JSON_TOKEN_OBJECT_VALUE != token))
443 {
444 hr = E_UNEXPECTED;
430 - ExitOnRootFailure(hr, "Failure to pop token because the stack did not match the expected token: %d", tokenEnd);
445 + JsonExitOnRootFailure(hr, "Failure to pop token because the stack did not match the expected token: %d", tokenEnd);
446 }
447 }
448
449 hr = StrAllocConcat(&pWriter->sczJson, wzEndString, 0);
435 - ExitOnFailure(hr, "Failed to end JSON array or object.");
450 + JsonExitOnFailure(hr, "Failed to end JSON array or object.");
451
452 --pWriter->cTokens;
453
@@ -454,7 +469,7 @@ static HRESULT DoKey(
469 ::EnterCriticalSection(&pWriter->cs);
470
471 hr = EnsureTokenStack(pWriter);
457 - ExitOnFailure(hr, "Failed to ensure token stack for key.");
472 + JsonExitOnFailure(hr, "Failed to ensure token stack for key.");
473
474 token = pWriter->rgTokenStack[pWriter->cTokens - 1];
475 switch (token)
@@ -472,16 +487,16 @@ static HRESULT DoKey(
487 hr = E_UNEXPECTED;
488 break;
489 }
475 - ExitOnRootFailure(hr, "Cannot add key to JSON serializer now.");
490 + JsonExitOnRootFailure(hr, "Cannot add key to JSON serializer now.");
491
492 if (fNeedComma)
493 {
494 hr = StrAllocConcat(&pWriter->sczJson, L",", 0);
480 - ExitOnFailure(hr, "Failed to add comma for key to JSON.");
495 + JsonExitOnFailure(hr, "Failed to add comma for key to JSON.");
496 }
497
498 hr = StrAllocConcat(&pWriter->sczJson, wzKey, 0);
484 - ExitOnFailure(hr, "Failed to add key to JSON.");
499 + JsonExitOnFailure(hr, "Failed to add key to JSON.");
500
501 pWriter->rgTokenStack[pWriter->cTokens - 1] = token;
502
@@ -503,7 +518,7 @@ static HRESULT DoValue(
518 ::EnterCriticalSection(&pWriter->cs);
519
520 hr = EnsureTokenStack(pWriter);
506 - ExitOnFailure(hr, "Failed to ensure token stack for value.");
521 + JsonExitOnFailure(hr, "Failed to ensure token stack for value.");
522
523 token = pWriter->rgTokenStack[pWriter->cTokens - 1];
524 switch (token)
@@ -528,23 +543,23 @@ static HRESULT DoValue(
543 hr = E_UNEXPECTED;
544 break;
545 }
531 - ExitOnRootFailure(hr, "Cannot add value to JSON serializer now.");
546 + JsonExitOnRootFailure(hr, "Cannot add value to JSON serializer now.");
547
548 if (fNeedComma)
549 {
550 hr = StrAllocConcat(&pWriter->sczJson, L",", 0);
536 - ExitOnFailure(hr, "Failed to add comma for value to JSON.");
551 + JsonExitOnFailure(hr, "Failed to add comma for value to JSON.");
552 }
553
554 if (wzValue)
555 {
556 hr = StrAllocConcat(&pWriter->sczJson, wzValue, 0);
542 - ExitOnFailure(hr, "Failed to add value to JSON.");
557 + JsonExitOnFailure(hr, "Failed to add value to JSON.");
558 }
559 else
560 {
561 hr = StrAllocConcat(&pWriter->sczJson, L"null", 0);
547 - ExitOnFailure(hr, "Failed to add null value to JSON.");
562 + JsonExitOnFailure(hr, "Failed to add null value to JSON.");
563 }
564
565 pWriter->rgTokenStack[pWriter->cTokens - 1] = token;
@@ -563,7 +578,7 @@ static HRESULT EnsureTokenStack(
578 DWORD cNumAlloc = pWriter->cTokens != 0 ? pWriter->cTokens : 0;
579
580 hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(&pWriter->rgTokenStack), cNumAlloc, sizeof(JSON_TOKEN), JSON_STACK_INCREMENT);
566 - ExitOnFailure(hr, "Failed to allocate JSON token stack.");
581 + JsonExitOnFailure(hr, "Failed to allocate JSON token stack.");
582
583 if (0 == pWriter->cTokens)
584 {
@@ -596,7 +611,7 @@ static HRESULT SerializeJsonString(
611 }
612
613 hr = StrAlloc(psczJsonString, cchRequired);
599 - ExitOnFailure(hr, "Failed to allocate space for JSON string.");
614 + JsonExitOnFailure(hr, "Failed to allocate space for JSON string.");
615
616 LPWSTR pchTarget = *psczJsonString;
617
src/dutil/locutil.cpp
+70 -55
@@ -2,6 +2,21 @@
2
3 #include "precomp.h"
4
5 +
6 +// Exit macros
7 +#define LocExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_LOCUTIL, x, s, __VA_ARGS__)
8 +#define LocExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_LOCUTIL, x, s, __VA_ARGS__)
9 +#define LocExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_LOCUTIL, x, s, __VA_ARGS__)
10 +#define LocExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_LOCUTIL, x, s, __VA_ARGS__)
11 +#define LocExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_LOCUTIL, x, s, __VA_ARGS__)
12 +#define LocExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_LOCUTIL, x, s, __VA_ARGS__)
13 +#define LocExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_LOCUTIL, p, x, e, s, __VA_ARGS__)
14 +#define LocExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_LOCUTIL, p, x, s, __VA_ARGS__)
15 +#define LocExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_LOCUTIL, p, x, e, s, __VA_ARGS__)
16 +#define LocExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_LOCUTIL, p, x, s, __VA_ARGS__)
17 +#define LocExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_LOCUTIL, e, x, s, __VA_ARGS__)
18 +#define LocExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_LOCUTIL, g, x, s, __VA_ARGS__)
19 +
20 // prototypes
21 static HRESULT ParseWxl(
22 __in IXMLDOMDocument* pixd,
@@ -63,10 +78,10 @@ extern "C" HRESULT DAPI LocProbeForFile(
78 if (wzLanguage && *wzLanguage)
79 {
80 hr = PathConcat(wzBasePath, wzLanguage, &sczProbePath);
66 - ExitOnFailure(hr, "Failed to concat base path to language.");
81 + LocExitOnFailure(hr, "Failed to concat base path to language.");
82
83 hr = PathConcat(sczProbePath, wzLocFileName, &sczProbePath);
69 - ExitOnFailure(hr, "Failed to concat loc file name to probe path.");
84 + LocExitOnFailure(hr, "Failed to concat loc file name to probe path.");
85
86 if (FileExistsEx(sczProbePath, NULL))
87 {
@@ -81,16 +96,16 @@ extern "C" HRESULT DAPI LocProbeForFile(
96 DWORD dwFlags = MUI_LANGUAGE_ID | MUI_MERGE_USER_FALLBACK | MUI_MERGE_SYSTEM_FALLBACK;
97 if (!(*pvfnGetThreadPreferredUILanguages)(dwFlags, &nLangs, NULL, &cchLangs))
98 {
84 - ExitWithLastError(hr, "GetThreadPreferredUILanguages failed to return buffer size.");
99 + LocExitWithLastError(hr, "GetThreadPreferredUILanguages failed to return buffer size.");
100 }
101
102 hr = StrAlloc(&sczLangsBuff, cchLangs);
88 - ExitOnFailure(hr, "Failed to allocate buffer for languages");
103 + LocExitOnFailure(hr, "Failed to allocate buffer for languages");
104
105 nLangs = 0;
106 if (!(*pvfnGetThreadPreferredUILanguages)(dwFlags, &nLangs, sczLangsBuff, &cchLangs))
107 {
93 - ExitWithLastError(hr, "GetThreadPreferredUILanguages failed to return language list.");
108 + LocExitWithLastError(hr, "GetThreadPreferredUILanguages failed to return language list.");
109 }
110
111 LPWSTR szLangs = sczLangsBuff;
@@ -98,14 +113,14 @@ extern "C" HRESULT DAPI LocProbeForFile(
113 {
114 // StrHexDecode assumes low byte is first. We'll need to swap the bytes once we parse out the value.
115 hr = StrHexDecode(szLangs, reinterpret_cast<BYTE*>(&langid), sizeof(langid));
101 - ExitOnFailure(hr, "Failed to parse langId.");
116 + LocExitOnFailure(hr, "Failed to parse langId.");
117
118 langid = MAKEWORD(HIBYTE(langid), LOBYTE(langid));
119 hr = StrAllocFormatted(&sczLangIdFile, L"%u\\%ls", langid, wzLocFileName);
105 - ExitOnFailure(hr, "Failed to format user preferred langid.");
120 + LocExitOnFailure(hr, "Failed to format user preferred langid.");
121
122 hr = PathConcat(wzBasePath, sczLangIdFile, &sczProbePath);
108 - ExitOnFailure(hr, "Failed to concat user preferred langid file name to base path.");
123 + LocExitOnFailure(hr, "Failed to concat user preferred langid file name to base path.");
124
125 if (FileExistsEx(sczProbePath, NULL))
126 {
@@ -117,10 +132,10 @@ extern "C" HRESULT DAPI LocProbeForFile(
132 langid = ::GetUserDefaultUILanguage();
133
134 hr = StrAllocFormatted(&sczLangIdFile, L"%u\\%ls", langid, wzLocFileName);
120 - ExitOnFailure(hr, "Failed to format user langid.");
135 + LocExitOnFailure(hr, "Failed to format user langid.");
136
137 hr = PathConcat(wzBasePath, sczLangIdFile, &sczProbePath);
123 - ExitOnFailure(hr, "Failed to concat user langid file name to base path.");
138 + LocExitOnFailure(hr, "Failed to concat user langid file name to base path.");
139
140 if (FileExistsEx(sczProbePath, NULL))
141 {
@@ -132,10 +147,10 @@ extern "C" HRESULT DAPI LocProbeForFile(
147 langid = MAKELANGID(langid & 0x3FF, SUBLANG_DEFAULT);
148
149 hr = StrAllocFormatted(&sczLangIdFile, L"%u\\%ls", langid, wzLocFileName);
135 - ExitOnFailure(hr, "Failed to format user langid (default sublang).");
150 + LocExitOnFailure(hr, "Failed to format user langid (default sublang).");
151
152 hr = PathConcat(wzBasePath, sczLangIdFile, &sczProbePath);
138 - ExitOnFailure(hr, "Failed to concat user langid file name to base path (default sublang).");
153 + LocExitOnFailure(hr, "Failed to concat user langid file name to base path (default sublang).");
154
155 if (FileExistsEx(sczProbePath, NULL))
156 {
@@ -146,10 +161,10 @@ extern "C" HRESULT DAPI LocProbeForFile(
161 langid = ::GetSystemDefaultUILanguage();
162
163 hr = StrAllocFormatted(&sczLangIdFile, L"%u\\%ls", langid, wzLocFileName);
149 - ExitOnFailure(hr, "Failed to format system langid.");
164 + LocExitOnFailure(hr, "Failed to format system langid.");
165
166 hr = PathConcat(wzBasePath, sczLangIdFile, &sczProbePath);
152 - ExitOnFailure(hr, "Failed to concat system langid file name to base path.");
167 + LocExitOnFailure(hr, "Failed to concat system langid file name to base path.");
168
169 if (FileExistsEx(sczProbePath, NULL))
170 {
@@ -161,10 +176,10 @@ extern "C" HRESULT DAPI LocProbeForFile(
176 langid = MAKELANGID(langid & 0x3FF, SUBLANG_DEFAULT);
177
178 hr = StrAllocFormatted(&sczLangIdFile, L"%u\\%ls", langid, wzLocFileName);
164 - ExitOnFailure(hr, "Failed to format user langid (default sublang).");
179 + LocExitOnFailure(hr, "Failed to format user langid (default sublang).");
180
181 hr = PathConcat(wzBasePath, sczLangIdFile, &sczProbePath);
167 - ExitOnFailure(hr, "Failed to concat user langid file name to base path (default sublang).");
182 + LocExitOnFailure(hr, "Failed to concat user langid file name to base path (default sublang).");
183
184 if (FileExistsEx(sczProbePath, NULL))
185 {
@@ -174,7 +189,7 @@ extern "C" HRESULT DAPI LocProbeForFile(
189
190 // Finally, look for the loc file in the base path.
191 hr = PathConcat(wzBasePath, wzLocFileName, &sczProbePath);
177 - ExitOnFailure(hr, "Failed to concat loc file name to base path.");
192 + LocExitOnFailure(hr, "Failed to concat loc file name to base path.");
193
194 if (!FileExistsEx(sczProbePath, NULL))
195 {
@@ -203,10 +218,10 @@ extern "C" HRESULT DAPI LocLoadFromFile(
218 IXMLDOMDocument* pixd = NULL;
219
220 hr = XmlLoadDocumentFromFile(wzWxlFile, &pixd);
206 - ExitOnFailure(hr, "Failed to load WXL file as XML document.");
221 + LocExitOnFailure(hr, "Failed to load WXL file as XML document.");
222
223 hr = ParseWxl(pixd, ppWixLoc);
209 - ExitOnFailure(hr, "Failed to parse WXL.");
224 + LocExitOnFailure(hr, "Failed to parse WXL.");
225
226 LExit:
227 ReleaseObject(pixd);
@@ -227,16 +242,16 @@ extern "C" HRESULT DAPI LocLoadFromResource(
242 IXMLDOMDocument* pixd = NULL;
243
244 hr = ResReadData(hModule, szResource, &pvResource, &cbResource);
230 - ExitOnFailure(hr, "Failed to read theme from resource.");
245 + LocExitOnFailure(hr, "Failed to read theme from resource.");
246
247 hr = StrAllocStringAnsi(&sczXml, reinterpret_cast<LPCSTR>(pvResource), cbResource, CP_UTF8);
233 - ExitOnFailure(hr, "Failed to convert XML document data from UTF-8 to unicode string.");
248 + LocExitOnFailure(hr, "Failed to convert XML document data from UTF-8 to unicode string.");
249
250 hr = XmlLoadDocument(sczXml, &pixd);
236 - ExitOnFailure(hr, "Failed to load theme resource as XML document.");
251 + LocExitOnFailure(hr, "Failed to load theme resource as XML document.");
252
253 hr = ParseWxl(pixd, ppWixLoc);
239 - ExitOnFailure(hr, "Failed to parse WXL.");
254 + LocExitOnFailure(hr, "Failed to parse WXL.");
255
256 LExit:
257 ReleaseObject(pixd);
@@ -280,7 +295,7 @@ extern "C" HRESULT DAPI LocLocalizeString(
295 for (DWORD i = 0; i < pWixLoc->cLocStrings; ++i)
296 {
297 hr = StrReplaceStringAll(ppsczInput, pWixLoc->rgLocStrings[i].wzId, pWixLoc->rgLocStrings[i].wzText);
283 - ExitOnFailure(hr, "Localizing string failed.");
298 + LocExitOnFailure(hr, "Localizing string failed.");
299 }
300
301 LExit:
@@ -348,15 +363,15 @@ extern "C" HRESULT DAPI LocAddString(
363
364 ++pWixLoc->cLocStrings;
365 pWixLoc->rgLocStrings = static_cast<LOC_STRING*>(MemReAlloc(pWixLoc->rgLocStrings, sizeof(LOC_STRING) * pWixLoc->cLocStrings, TRUE));
351 - ExitOnNull(pWixLoc->rgLocStrings, hr, E_OUTOFMEMORY, "Failed to reallocate memory for localization strings.");
366 + LocExitOnNull(pWixLoc->rgLocStrings, hr, E_OUTOFMEMORY, "Failed to reallocate memory for localization strings.");
367
368 LOC_STRING* pLocString = pWixLoc->rgLocStrings + (pWixLoc->cLocStrings - 1);
369
370 hr = StrAllocFormatted(&pLocString->wzId, L"#(loc.%s)", wzId);
356 - ExitOnFailure(hr, "Failed to set localization string Id.");
371 + LocExitOnFailure(hr, "Failed to set localization string Id.");
372
373 hr = StrAllocString(&pLocString->wzText, wzLocString, 0);
359 - ExitOnFailure(hr, "Failed to set localization string Text.");
374 + LocExitOnFailure(hr, "Failed to set localization string Text.");
375
376 pLocString->bOverridable = bOverridable;
377
@@ -376,11 +391,11 @@ static HRESULT ParseWxl(
391 WIX_LOCALIZATION* pWixLoc = NULL;
392
393 pWixLoc = static_cast<WIX_LOCALIZATION*>(MemAlloc(sizeof(WIX_LOCALIZATION), TRUE));
379 - ExitOnNull(pWixLoc, hr, E_OUTOFMEMORY, "Failed to allocate memory for Wxl file.");
394 + LocExitOnNull(pWixLoc, hr, E_OUTOFMEMORY, "Failed to allocate memory for Wxl file.");
395
396 // read the WixLocalization tag
397 hr = pixd->get_documentElement(&pWxlElement);
383 - ExitOnFailure(hr, "Failed to get localization element.");
398 + LocExitOnFailure(hr, "Failed to get localization element.");
399
400 // get the Language attribute if present
401 pWixLoc->dwLangId = WIX_LOCALIZATION_LANGUAGE_NOT_SET;
@@ -389,14 +404,14 @@ static HRESULT ParseWxl(
404 {
405 hr = S_OK;
406 }
392 - ExitOnFailure(hr, "Failed to get Language value.");
407 + LocExitOnFailure(hr, "Failed to get Language value.");
408
409 // store the strings and controls in a node list
410 hr = ParseWxlStrings(pWxlElement, pWixLoc);
396 - ExitOnFailure(hr, "Parsing localization strings failed.");
411 + LocExitOnFailure(hr, "Parsing localization strings failed.");
412
413 hr = ParseWxlControls(pWxlElement, pWixLoc);
399 - ExitOnFailure(hr, "Parsing localization controls failed.");
414 + LocExitOnFailure(hr, "Parsing localization controls failed.");
415
416 *ppWixLoc = pWixLoc;
417 pWixLoc = NULL;
@@ -420,27 +435,27 @@ static HRESULT ParseWxlStrings(
435 DWORD dwIdx = 0;
436
437 hr = XmlSelectNodes(pElement, L"String", &pixnl);
423 - ExitOnLastError(hr, "Failed to get String child nodes of Wxl File.");
438 + LocExitOnLastError(hr, "Failed to get String child nodes of Wxl File.");
439
440 hr = pixnl->get_length(reinterpret_cast<long*>(&pWixLoc->cLocStrings));
426 - ExitOnLastError(hr, "Failed to get number of String child nodes in Wxl File.");
441 + LocExitOnLastError(hr, "Failed to get number of String child nodes in Wxl File.");
442
443 if (0 < pWixLoc->cLocStrings)
444 {
445 pWixLoc->rgLocStrings = static_cast<LOC_STRING*>(MemAlloc(sizeof(LOC_STRING) * pWixLoc->cLocStrings, TRUE));
431 - ExitOnNull(pWixLoc->rgLocStrings, hr, E_OUTOFMEMORY, "Failed to allocate memory for localization strings.");
446 + LocExitOnNull(pWixLoc->rgLocStrings, hr, E_OUTOFMEMORY, "Failed to allocate memory for localization strings.");
447
448 while (S_OK == (hr = XmlNextElement(pixnl, &pixn, NULL)))
449 {
450 hr = ParseWxlString(pixn, dwIdx, pWixLoc);
436 - ExitOnFailure(hr, "Failed to parse localization string.");
451 + LocExitOnFailure(hr, "Failed to parse localization string.");
452
453 ++dwIdx;
454 ReleaseNullObject(pixn);
455 }
456
457 hr = S_OK;
443 - ExitOnFailure(hr, "Failed to enumerate all localization strings.");
458 + LocExitOnFailure(hr, "Failed to enumerate all localization strings.");
459 }
460
461 LExit:
@@ -472,27 +487,27 @@ static HRESULT ParseWxlControls(
487 DWORD dwIdx = 0;
488
489 hr = XmlSelectNodes(pElement, L"UI|Control", &pixnl);
475 - ExitOnLastError(hr, "Failed to get UI child nodes of Wxl File.");
490 + LocExitOnLastError(hr, "Failed to get UI child nodes of Wxl File.");
491
492 hr = pixnl->get_length(reinterpret_cast<long*>(&pWixLoc->cLocControls));
478 - ExitOnLastError(hr, "Failed to get number of UI child nodes in Wxl File.");
493 + LocExitOnLastError(hr, "Failed to get number of UI child nodes in Wxl File.");
494
495 if (0 < pWixLoc->cLocControls)
496 {
497 pWixLoc->rgLocControls = static_cast<LOC_CONTROL*>(MemAlloc(sizeof(LOC_CONTROL) * pWixLoc->cLocControls, TRUE));
483 - ExitOnNull(pWixLoc->rgLocControls, hr, E_OUTOFMEMORY, "Failed to allocate memory for localized controls.");
498 + LocExitOnNull(pWixLoc->rgLocControls, hr, E_OUTOFMEMORY, "Failed to allocate memory for localized controls.");
499
500 while (S_OK == (hr = XmlNextElement(pixnl, &pixn, NULL)))
501 {
502 hr = ParseWxlControl(pixn, dwIdx, pWixLoc);
488 - ExitOnFailure(hr, "Failed to parse localized control.");
503 + LocExitOnFailure(hr, "Failed to parse localized control.");
504
505 ++dwIdx;
506 ReleaseNullObject(pixn);
507 }
508
509 hr = S_OK;
495 - ExitOnFailure(hr, "Failed to enumerate all localized controls.");
510 + LocExitOnFailure(hr, "Failed to enumerate all localized controls.");
511 }
512
513 LExit:
@@ -527,16 +542,16 @@ static HRESULT ParseWxlString(
542
543 // Id
544 hr = XmlGetAttribute(pixn, L"Id", &bstrText);
530 - ExitOnFailure(hr, "Failed to get Xml attribute Id in Wxl file.");
545 + LocExitOnFailure(hr, "Failed to get Xml attribute Id in Wxl file.");
546
547 hr = StrAllocFormatted(&pLocString->wzId, L"#(loc.%s)", bstrText);
533 - ExitOnFailure(hr, "Failed to duplicate Xml attribute Id in Wxl file.");
548 + LocExitOnFailure(hr, "Failed to duplicate Xml attribute Id in Wxl file.");
549
550 ReleaseNullBSTR(bstrText);
551
552 // Overrideable
553 hr = XmlGetAttribute(pixn, L"Overridable", &bstrText);
539 - ExitOnFailure(hr, "Failed to get Xml attribute Overridable.");
554 + LocExitOnFailure(hr, "Failed to get Xml attribute Overridable.");
555
556 if (S_OK == hr)
557 {
@@ -547,10 +562,10 @@ static HRESULT ParseWxlString(
562
563 // Text
564 hr = XmlGetText(pixn, &bstrText);
550 - ExitOnFailure(hr, "Failed to get Xml text in Wxl file.");
565 + LocExitOnFailure(hr, "Failed to get Xml text in Wxl file.");
566
567 hr = StrAllocString(&pLocString->wzText, bstrText, 0);
553 - ExitOnFailure(hr, "Failed to duplicate Xml text in Wxl file.");
568 + LocExitOnFailure(hr, "Failed to duplicate Xml text in Wxl file.");
569
570 LExit:
571 ReleaseBSTR(bstrText);
@@ -572,39 +587,39 @@ static HRESULT ParseWxlControl(
587
588 // Id
589 hr = XmlGetAttribute(pixn, L"Control", &bstrText);
575 - ExitOnFailure(hr, "Failed to get Xml attribute Control in Wxl file.");
590 + LocExitOnFailure(hr, "Failed to get Xml attribute Control in Wxl file.");
591
592 hr = StrAllocString(&pLocControl->wzControl, bstrText, 0);
578 - ExitOnFailure(hr, "Failed to duplicate Xml attribute Control in Wxl file.");
593 + LocExitOnFailure(hr, "Failed to duplicate Xml attribute Control in Wxl file.");
594
595 ReleaseNullBSTR(bstrText);
596
597 // X
598 pLocControl->nX = LOC_CONTROL_NOT_SET;
599 hr = XmlGetAttributeNumber(pixn, L"X", reinterpret_cast<DWORD*>(&pLocControl->nX));
585 - ExitOnFailure(hr, "Failed to get control X attribute.");
600 + LocExitOnFailure(hr, "Failed to get control X attribute.");
601
602 // Y
603 pLocControl->nY = LOC_CONTROL_NOT_SET;
604 hr = XmlGetAttributeNumber(pixn, L"Y", reinterpret_cast<DWORD*>(&pLocControl->nY));
590 - ExitOnFailure(hr, "Failed to get control Y attribute.");
605 + LocExitOnFailure(hr, "Failed to get control Y attribute.");
606
607 // Width
608 pLocControl->nWidth = LOC_CONTROL_NOT_SET;
609 hr = XmlGetAttributeNumber(pixn, L"Width", reinterpret_cast<DWORD*>(&pLocControl->nWidth));
595 - ExitOnFailure(hr, "Failed to get control width attribute.");
610 + LocExitOnFailure(hr, "Failed to get control width attribute.");
611
612 // Height
613 pLocControl->nHeight = LOC_CONTROL_NOT_SET;
614 hr = XmlGetAttributeNumber(pixn, L"Height", reinterpret_cast<DWORD*>(&pLocControl->nHeight));
600 - ExitOnFailure(hr, "Failed to get control height attribute.");
615 + LocExitOnFailure(hr, "Failed to get control height attribute.");
616
617 // Text
618 hr = XmlGetText(pixn, &bstrText);
604 - ExitOnFailure(hr, "Failed to get control text in Wxl file.");
619 + LocExitOnFailure(hr, "Failed to get control text in Wxl file.");
620
621 hr = StrAllocString(&pLocControl->wzText, bstrText, 0);
607 - ExitOnFailure(hr, "Failed to duplicate control text in Wxl file.");
622 + LocExitOnFailure(hr, "Failed to duplicate control text in Wxl file.");
623
624 LExit:
625 ReleaseBSTR(bstrText);
src/dutil/logutil.cpp
+41 -26
@@ -2,6 +2,21 @@
2
3 #include "precomp.h"
4
5 +
6 +// Exit macros
7 +#define LoguExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_LOGUTIL, x, s, __VA_ARGS__)
8 +#define LoguExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_LOGUTIL, x, s, __VA_ARGS__)
9 +#define LoguExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_LOGUTIL, x, s, __VA_ARGS__)
10 +#define LoguExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_LOGUTIL, x, s, __VA_ARGS__)
11 +#define LoguExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_LOGUTIL, x, s, __VA_ARGS__)
12 +#define LoguExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_LOGUTIL, x, s, __VA_ARGS__)
13 +#define LoguExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_LOGUTIL, p, x, e, s, __VA_ARGS__)
14 +#define LoguExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_LOGUTIL, p, x, s, __VA_ARGS__)
15 +#define LoguExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_LOGUTIL, p, x, e, s, __VA_ARGS__)
16 +#define LoguExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_LOGUTIL, p, x, s, __VA_ARGS__)
17 +#define LoguExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_LOGUTIL, e, x, s, __VA_ARGS__)
18 +#define LoguExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_LOGUTIL, g, x, s, __VA_ARGS__)
19 +
20 // globals
21 static HMODULE LogUtil_hModule = NULL;
22 static BOOL LogUtil_fDisabled = FALSE;
@@ -110,23 +125,23 @@ extern "C" HRESULT DAPI LogOpen(
125 if (wzExt && *wzExt)
126 {
127 hr = PathCreateTimeBasedTempFile(wzDirectory, wzLog, wzPostfix, wzExt, &LogUtil_sczLogPath, &LogUtil_hLog);
113 - ExitOnFailure(hr, "Failed to create log based on current system time.");
128 + LoguExitOnFailure(hr, "Failed to create log based on current system time.");
129 }
130 else
131 {
132 hr = PathConcat(wzDirectory, wzLog, &LogUtil_sczLogPath);
118 - ExitOnFailure(hr, "Failed to combine the log path.");
133 + LoguExitOnFailure(hr, "Failed to combine the log path.");
134
135 hr = PathGetDirectory(LogUtil_sczLogPath, &sczLogDirectory);
121 - ExitOnFailure(hr, "Failed to get log directory.");
136 + LoguExitOnFailure(hr, "Failed to get log directory.");
137
138 hr = DirEnsureExists(sczLogDirectory, NULL);
124 - ExitOnFailure(hr, "Failed to ensure log file directory exists: %ls", sczLogDirectory);
139 + LoguExitOnFailure(hr, "Failed to ensure log file directory exists: %ls", sczLogDirectory);
140
141 LogUtil_hLog = ::CreateFileW(LogUtil_sczLogPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, (fAppend) ? OPEN_ALWAYS : CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
142 if (INVALID_HANDLE_VALUE == LogUtil_hLog)
143 {
129 - ExitOnLastError(hr, "failed to create log file: %ls", LogUtil_sczLogPath);
144 + LoguExitOnLastError(hr, "failed to create log file: %ls", LogUtil_sczLogPath);
145 }
146
147 if (fAppend)
@@ -152,7 +167,7 @@ extern "C" HRESULT DAPI LogOpen(
167 if (psczLogPath)
168 {
169 hr = StrAllocString(psczLogPath, LogUtil_sczLogPath, 0);
155 - ExitOnFailure(hr, "Failed to copy log path.");
170 + LoguExitOnFailure(hr, "Failed to copy log path.");
171 }
172
173 LExit:
@@ -217,15 +232,15 @@ HRESULT DAPI LogRename(
232 ReleaseFileHandle(LogUtil_hLog);
233
234 hr = FileEnsureMove(LogUtil_sczLogPath, wzNewPath, TRUE, TRUE);
220 - ExitOnFailure(hr, "Failed to move logfile to new location: %ls", wzNewPath);
235 + LoguExitOnFailure(hr, "Failed to move logfile to new location: %ls", wzNewPath);
236
237 hr = StrAllocString(&LogUtil_sczLogPath, wzNewPath, 0);
223 - ExitOnFailure(hr, "Failed to store new logfile path: %ls", wzNewPath);
238 + LoguExitOnFailure(hr, "Failed to store new logfile path: %ls", wzNewPath);
239
240 LogUtil_hLog = ::CreateFileW(LogUtil_sczLogPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
241 if (INVALID_HANDLE_VALUE == LogUtil_hLog)
242 {
228 - ExitOnLastError(hr, "failed to create log file: %ls", LogUtil_sczLogPath);
243 + LoguExitOnLastError(hr, "failed to create log file: %ls", LogUtil_sczLogPath);
244 }
245
246 // Enable "append" mode by moving file pointer to the end
@@ -307,7 +322,7 @@ HRESULT DAPI LogSetSpecialParams(
322 else
323 {
324 hr = StrAllocConcat(&LogUtil_sczSpecialBeginLine, wzSpecialBeginLine, 0);
310 - ExitOnFailure(hr, "Failed to allocate copy of special beginline string");
325 + LoguExitOnFailure(hr, "Failed to allocate copy of special beginline string");
326 }
327
328 // Handle special string to be appended to every time stamp
@@ -318,7 +333,7 @@ HRESULT DAPI LogSetSpecialParams(
333 else
334 {
335 hr = StrAllocConcat(&LogUtil_sczSpecialAfterTimeStamp, wzSpecialAfterTimeStamp, 0);
321 - ExitOnFailure(hr, "Failed to allocate copy of special post-timestamp string");
336 + LoguExitOnFailure(hr, "Failed to allocate copy of special post-timestamp string");
337 }
338
339 // Handle special string to be appended before every full line
@@ -329,7 +344,7 @@ HRESULT DAPI LogSetSpecialParams(
344 else
345 {
346 hr = StrAllocConcat(&LogUtil_sczSpecialEndLine, wzSpecialEndLine, 0);
332 - ExitOnFailure(hr, "Failed to allocate copy of special endline string");
347 + LoguExitOnFailure(hr, "Failed to allocate copy of special endline string");
348 }
349
350 LExit:
@@ -597,14 +612,14 @@ extern "C" HRESULT DAPI LogErrorStringArgs(
612 LPWSTR sczMessage = NULL;
613
614 hr = StrAllocStringAnsi(&sczFormat, szFormat, 0, CP_ACP);
600 - ExitOnFailure(hr, "Failed to convert format string to wide character string");
615 + LoguExitOnFailure(hr, "Failed to convert format string to wide character string");
616
617 // format the string as a unicode string - this is necessary to be able to include
618 // international characters in our output string. This does have the counterintuitive effect
619 // that the caller's "%s" is interpreted differently
620 // (so callers should use %hs for LPSTR and %ls for LPWSTR)
621 hr = StrAllocFormattedArgs(&sczMessage, sczFormat, args);
607 - ExitOnFailure(hr, "Failed to format error message: \"%ls\"", sczFormat);
622 + LoguExitOnFailure(hr, "Failed to format error message: \"%ls\"", sczFormat);
623
624 hr = LogStringLine(REPORT_ERROR, "Error 0x%x: %ls", hrError, sczMessage);
625
@@ -636,14 +651,14 @@ extern "C" HRESULT DAPI LogErrorIdModule(
651 WORD cStrings = 1; // guaranteed wzError is in the list
652
653 hr = ::StringCchPrintfW(wzError, countof(wzError), L"0x%08x", hrError);
639 - ExitOnFailure(hr, "failed to format error code: \"0%08x\"", hrError);
654 + LoguExitOnFailure(hr, "failed to format error code: \"0%08x\"", hrError);
655
656 cStrings += wzString1 ? 1 : 0;
657 cStrings += wzString2 ? 1 : 0;
658 cStrings += wzString3 ? 1 : 0;
659
660 hr = LogIdModule(REPORT_ERROR, dwLogId, hModule, wzError, wzString1, wzString2, wzString3);
646 - ExitOnFailure(hr, "Failed to log id module.");
661 + LoguExitOnFailure(hr, "Failed to log id module.");
662
663 LExit:
664 return hr;
@@ -771,7 +786,7 @@ extern "C" HRESULT LogStringWorkRaw(
786 if (INVALID_HANDLE_VALUE == LogUtil_hLog)
787 {
788 hr = StrAnsiAllocConcat(&LogUtil_sczPreInitBuffer, szLogData, 0);
774 - ExitOnFailure(hr, "Failed to concatenate string to pre-init buffer");
789 + LoguExitOnFailure(hr, "Failed to concatenate string to pre-init buffer");
790
791 ExitFunction1(hr = S_OK);
792 }
@@ -781,7 +796,7 @@ extern "C" HRESULT LogStringWorkRaw(
796 {
797 if (!::WriteFile(LogUtil_hLog, reinterpret_cast<const BYTE*>(szLogData) + cbTotal, cbLogData - cbTotal, &cbWrote, NULL))
798 {
784 - ExitOnLastError(hr, "Failed to write output to log: %ls - %ls", LogUtil_sczLogPath, szLogData);
799 + LoguExitOnLastError(hr, "Failed to write output to log: %ls - %hs", LogUtil_sczLogPath, szLogData);
800 }
801
802 cbTotal += cbWrote;
@@ -816,7 +831,7 @@ static HRESULT LogIdWork(
831
832 if (0 == cch)
833 {
819 - ExitOnLastError(hr, "failed to log id: %d", dwLogId);
834 + LoguExitOnLastError(hr, "failed to log id: %d", dwLogId);
835 }
836
837 if (2 <= cch && L'\r' == pwz[cch-2] && L'\n' == pwz[cch-1])
@@ -850,14 +865,14 @@ static HRESULT LogStringWorkArgs(
865 LPWSTR sczMessage = NULL;
866
867 hr = StrAllocStringAnsi(&sczFormat, szFormat, 0, CP_ACP);
853 - ExitOnFailure(hr, "Failed to convert format string to wide character string");
868 + LoguExitOnFailure(hr, "Failed to convert format string to wide character string");
869
870 // format the string as a unicode string
871 hr = StrAllocFormattedArgs(&sczMessage, sczFormat, args);
857 - ExitOnFailure(hr, "Failed to format message: \"%ls\"", sczFormat);
872 + LoguExitOnFailure(hr, "Failed to format message: \"%ls\"", sczFormat);
873
874 hr = LogStringWork(rl, 0, sczMessage, fLOGUTIL_NEWLINE);
860 - ExitOnFailure(hr, "Failed to write formatted string to log:%ls", sczMessage);
875 + LoguExitOnFailure(hr, "Failed to write formatted string to log:%ls", sczMessage);
876
877 LExit:
878 ReleaseStr(sczFormat);
@@ -909,24 +924,24 @@ static HRESULT LogStringWork(
924 hr = StrAllocFormatted(&scz, L"%ls[%04X:%04X][%04hu-%02hu-%02huT%02hu:%02hu:%02hu]%hs%03d:%ls %ls%ls", LogUtil_sczSpecialBeginLine ? LogUtil_sczSpecialBeginLine : L"",
925 dwProcessId, dwThreadId, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, szType, dwId,
926 LogUtil_sczSpecialAfterTimeStamp ? LogUtil_sczSpecialAfterTimeStamp : L"", sczString, LogUtil_sczSpecialEndLine ? LogUtil_sczSpecialEndLine : L"\r\n");
912 - ExitOnFailure(hr, "Failed to format line prefix.");
927 + LoguExitOnFailure(hr, "Failed to format line prefix.");
928 }
929
930 wzLogData = scz ? scz : sczString;
931
932 // Convert to UTF-8 before writing out to the log file
933 hr = StrAnsiAllocString(&sczMultiByte, wzLogData, 0, CP_UTF8);
919 - ExitOnFailure(hr, "Failed to convert log string to UTF-8");
934 + LoguExitOnFailure(hr, "Failed to convert log string to UTF-8");
935
936 if (s_vpfLogStringWorkRaw)
937 {
938 hr = s_vpfLogStringWorkRaw(sczMultiByte, s_vpvLogStringWorkRawContext);
924 - ExitOnFailure(hr, "Failed to write string to log using redirected function: %ls", sczString);
939 + LoguExitOnFailure(hr, "Failed to write string to log using redirected function: %ls", sczString);
940 }
941 else
942 {
943 hr = LogStringWorkRaw(sczMultiByte);
929 - ExitOnFailure(hr, "Failed to write string to log using default function: %ls", sczString);
944 + LoguExitOnFailure(hr, "Failed to write string to log using default function: %ls", sczString);
945 }
946
947 LExit:
src/dutil/memutil.cpp
+32 -19
@@ -1,10 +1,23 @@
1 -#pragma once
1 // 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.
2
4 -
3 #include "precomp.h"
4
5
6 +// Exit macros
7 +#define MemExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_MEMUTIL, x, s, __VA_ARGS__)
8 +#define MemExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_MEMUTIL, x, s, __VA_ARGS__)
9 +#define MemExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_MEMUTIL, x, s, __VA_ARGS__)
10 +#define MemExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_MEMUTIL, x, s, __VA_ARGS__)
11 +#define MemExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_MEMUTIL, x, s, __VA_ARGS__)
12 +#define MemExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_MEMUTIL, x, s, __VA_ARGS__)
13 +#define MemExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_MEMUTIL, p, x, e, s, __VA_ARGS__)
14 +#define MemExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_MEMUTIL, p, x, s, __VA_ARGS__)
15 +#define MemExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_MEMUTIL, p, x, e, s, __VA_ARGS__)
16 +#define MemExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_MEMUTIL, p, x, s, __VA_ARGS__)
17 +#define MemExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_MEMUTIL, e, x, s, __VA_ARGS__)
18 +#define MemExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_MEMUTIL, g, x, s, __VA_ARGS__)
19 +
20 +
21 #if DEBUG
22 static BOOL vfMemInitialized = FALSE;
23 #endif
@@ -51,7 +64,7 @@ extern "C" HRESULT DAPI MemReAllocSecure(
64 __in LPVOID pv,
65 __in SIZE_T cbSize,
66 __in BOOL fZero,
54 - __out LPVOID* ppvNew
67 + __deref_out LPVOID* ppvNew
68 )
69 {
70 // AssertSz(vfMemInitialized, "MemInitialize() not called, this would normally crash");
@@ -72,14 +85,14 @@ extern "C" HRESULT DAPI MemReAllocSecure(
85 const SIZE_T cbCurrent = MemSize(pv);
86 if (-1 == cbCurrent)
87 {
75 - ExitOnFailure(hr = E_INVALIDARG, "Failed to get memory size");
88 + MemExitOnRootFailure(hr = E_INVALIDARG, "Failed to get memory size");
89 }
90
91 // HeapReAlloc may allocate more memory than requested.
92 const SIZE_T cbNew = MemSize(pvNew);
93 if (-1 == cbNew)
94 {
82 - ExitOnFailure(hr = E_INVALIDARG, "Failed to get memory size");
95 + MemExitOnRootFailure(hr = E_INVALIDARG, "Failed to get memory size");
96 }
97
98 cbSize = cbNew;
@@ -94,7 +107,7 @@ extern "C" HRESULT DAPI MemReAllocSecure(
107 MemFree(pv);
108 }
109 }
97 - ExitOnNull(pvNew, hr, E_OUTOFMEMORY, "Failed to reallocate memory");
110 + MemExitOnNull(pvNew, hr, E_OUTOFMEMORY, "Failed to reallocate memory");
111
112 *ppvNew = pvNew;
113 pvNew = NULL;
@@ -129,10 +142,10 @@ extern "C" HRESULT DAPI MemReAllocArray(
142 SIZE_T cbNew = 0;
143
144 hr = ::DWordAdd(cArray, dwNewItemCount, &cNew);
132 - ExitOnFailure(hr, "Integer overflow when calculating new element count.");
145 + MemExitOnFailure(hr, "Integer overflow when calculating new element count.");
146
147 hr = ::SIZETMult(cNew, cbArrayType, &cbNew);
135 - ExitOnFailure(hr, "Integer overflow when calculating new block size.");
148 + MemExitOnFailure(hr, "Integer overflow when calculating new block size.");
149
150 if (*ppvArray)
151 {
@@ -140,7 +153,7 @@ extern "C" HRESULT DAPI MemReAllocArray(
153 if (cbCurrent < cbNew)
154 {
155 pvNew = MemReAlloc(*ppvArray, cbNew, TRUE);
143 - ExitOnNull(pvNew, hr, E_OUTOFMEMORY, "Failed to allocate larger array.");
156 + MemExitOnNull(pvNew, hr, E_OUTOFMEMORY, "Failed to allocate larger array.");
157
158 *ppvArray = pvNew;
159 }
@@ -148,7 +161,7 @@ extern "C" HRESULT DAPI MemReAllocArray(
161 else
162 {
163 pvNew = MemAlloc(cbNew, TRUE);
151 - ExitOnNull(pvNew, hr, E_OUTOFMEMORY, "Failed to allocate new array.");
164 + MemExitOnNull(pvNew, hr, E_OUTOFMEMORY, "Failed to allocate new array.");
165
166 *ppvArray = pvNew;
167 }
@@ -159,7 +172,7 @@ LExit:
172
173
174 extern "C" HRESULT DAPI MemEnsureArraySize(
162 - __deref_out_bcount(cArray * cbArrayType) LPVOID* ppvArray,
175 + __deref_inout_bcount(cArray * cbArrayType) LPVOID* ppvArray,
176 __in DWORD cArray,
177 __in SIZE_T cbArrayType,
178 __in DWORD dwGrowthCount
@@ -171,10 +184,10 @@ extern "C" HRESULT DAPI MemEnsureArraySize(
184 SIZE_T cbNew = 0;
185
186 hr = ::DWordAdd(cArray, dwGrowthCount, &cNew);
174 - ExitOnFailure(hr, "Integer overflow when calculating new element count.");
187 + MemExitOnFailure(hr, "Integer overflow when calculating new element count.");
188
189 hr = ::SIZETMult(cNew, cbArrayType, &cbNew);
177 - ExitOnFailure(hr, "Integer overflow when calculating new block size.");
190 + MemExitOnFailure(hr, "Integer overflow when calculating new block size.");
191
192 if (*ppvArray)
193 {
@@ -183,7 +196,7 @@ extern "C" HRESULT DAPI MemEnsureArraySize(
196 if (cbCurrent < cbUsed)
197 {
198 pvNew = MemReAlloc(*ppvArray, cbNew, TRUE);
186 - ExitOnNull(pvNew, hr, E_OUTOFMEMORY, "Failed to allocate array larger.");
199 + MemExitOnNull(pvNew, hr, E_OUTOFMEMORY, "Failed to allocate array larger.");
200
201 *ppvArray = pvNew;
202 }
@@ -191,7 +204,7 @@ extern "C" HRESULT DAPI MemEnsureArraySize(
204 else
205 {
206 pvNew = MemAlloc(cbNew, TRUE);
194 - ExitOnNull(pvNew, hr, E_OUTOFMEMORY, "Failed to allocate new array.");
207 + MemExitOnNull(pvNew, hr, E_OUTOFMEMORY, "Failed to allocate new array.");
208
209 *ppvArray = pvNew;
210 }
@@ -202,7 +215,7 @@ LExit:
215
216
217 extern "C" HRESULT DAPI MemInsertIntoArray(
205 - __deref_out_bcount((cExistingArray + cInsertItems) * cbArrayType) LPVOID* ppvArray,
218 + __deref_inout_bcount((cExistingArray + cInsertItems) * cbArrayType) LPVOID* ppvArray,
219 __in DWORD dwInsertIndex,
220 __in DWORD cInsertItems,
221 __in DWORD cExistingArray,
@@ -220,7 +233,7 @@ extern "C" HRESULT DAPI MemInsertIntoArray(
233 }
234
235 hr = MemEnsureArraySize(ppvArray, cExistingArray + cInsertItems, cbArrayType, dwGrowthCount);
223 - ExitOnFailure(hr, "Failed to resize array while inserting items");
236 + MemExitOnFailure(hr, "Failed to resize array while inserting items");
237
238 pbArray = reinterpret_cast<BYTE *>(*ppvArray);
239 for (i = cExistingArray + cInsertItems - 1; i > dwInsertIndex; --i)
@@ -236,7 +249,7 @@ LExit:
249 }
250
251 extern "C" void DAPI MemRemoveFromArray(
239 - __inout_bcount((cExistingArray + cInsertItems) * cbArrayType) LPVOID pvArray,
252 + __inout_bcount((cExistingArray) * cbArrayType) LPVOID pvArray,
253 __in DWORD dwRemoveIndex,
254 __in DWORD cRemoveItems,
255 __in DWORD cExistingArray,
@@ -261,7 +274,7 @@ extern "C" void DAPI MemRemoveFromArray(
274 }
275
276 extern "C" void DAPI MemArraySwapItems(
264 - __inout_bcount((cExistingArray) * cbArrayType) LPVOID pvArray,
277 + __inout_bcount(cbArrayType) LPVOID pvArray,
278 __in DWORD dwIndex1,
279 __in DWORD dwIndex2,
280 __in SIZE_T cbArrayType
src/dutil/metautil.cpp
+26 -11
@@ -9,6 +9,21 @@
9 #include "metautil.h"
10
11
12 +// Exit macros
13 +#define MetaExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_METAUTIL, x, s, __VA_ARGS__)
14 +#define MetaExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_METAUTIL, x, s, __VA_ARGS__)
15 +#define MetaExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_METAUTIL, x, s, __VA_ARGS__)
16 +#define MetaExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_METAUTIL, x, s, __VA_ARGS__)
17 +#define MetaExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_METAUTIL, x, s, __VA_ARGS__)
18 +#define MetaExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_METAUTIL, x, s, __VA_ARGS__)
19 +#define MetaExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_METAUTIL, p, x, e, s, __VA_ARGS__)
20 +#define MetaExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_METAUTIL, p, x, s, __VA_ARGS__)
21 +#define MetaExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_METAUTIL, p, x, e, s, __VA_ARGS__)
22 +#define MetaExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_METAUTIL, p, x, s, __VA_ARGS__)
23 +#define MetaExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_METAUTIL, e, x, s, __VA_ARGS__)
24 +#define MetaExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_METAUTIL, g, x, s, __VA_ARGS__)
25 +
26 +
27 // prototypes
28 static void Sort(
29 __in_ecount(cArray) DWORD dwArray[],
@@ -75,7 +90,7 @@ extern "C" HRESULT DAPI MetaFindWebBase(
90 hr = S_FALSE; // didn't find anything, try next one
91 continue;
92 }
78 - ExitOnFailure(hr, "failed to get key from metabase while searching for web servers");
93 + MetaExitOnFailure(hr, "failed to get key from metabase while searching for web servers");
94
95 // if we have an IIsWebServer store the key
96 if (0 == lstrcmpW(L"IIsWebServer", (LPCWSTR)mr.pbMDData))
@@ -83,7 +98,7 @@ extern "C" HRESULT DAPI MetaFindWebBase(
98 hr = MetaGetValue(piMetabase, METADATA_MASTER_ROOT_HANDLE, wzKey, &mrAddress);
99 if (MD_ERROR_DATA_NOT_FOUND == hr)
100 hr = S_FALSE;
86 - ExitOnFailure(hr, "failed to get address from metabase while searching for web servers");
101 + MetaExitOnFailure(hr, "failed to get address from metabase while searching for web servers");
102
103 // break down the first address into parts
104 pwzIPExists = reinterpret_cast<LPWSTR>(mrAddress.pbMDData);
@@ -111,7 +126,7 @@ extern "C" HRESULT DAPI MetaFindWebBase(
126 {
127 // if the passed in buffer wasn't big enough
128 hr = ::StringCchCopyW(wzWebBase, cchWebBase, wzKey);
114 - ExitOnFailure(hr, "failed to copy in web base: %ls", wzKey);
129 + MetaExitOnFailure(hr, "failed to copy in web base: %ls", wzKey);
130
131 fFound = TRUE;
132 break;
@@ -182,7 +197,7 @@ extern "C" HRESULT DAPI MetaFindFreeWebBase(
197 hr = S_FALSE; // didn't find anything, try next one
198 continue;
199 }
185 - ExitOnFailure(hr, "failed to get key from metabase while searching for free web root");
200 + MetaExitOnFailure(hr, "failed to get key from metabase while searching for free web root");
201
202 // if we have a IIsWebServer get the address information
203 if (0 == lstrcmpW(L"IIsWebServer", reinterpret_cast<LPCWSTR>(mr.pbMDData)))
@@ -190,7 +205,7 @@ extern "C" HRESULT DAPI MetaFindFreeWebBase(
205 if (cSubKeys >= countof(dwSubKeys))
206 {
207 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
193 - ExitOnFailure(hr, "Insufficient buffer to track all sub-WebSites");
208 + MetaExitOnFailure(hr, "Insufficient buffer to track all sub-WebSites");
209 }
210
211 dwSubKeys[cSubKeys] = wcstol(wzSubkey, NULL, 10);
@@ -201,7 +216,7 @@ extern "C" HRESULT DAPI MetaFindFreeWebBase(
216
217 if (E_NOMOREITEMS == hr)
218 hr = S_OK;
204 - ExitOnFailure(hr, "failed to find free web root");
219 + MetaExitOnFailure(hr, "failed to find free web root");
220
221 // find the lowest free web root
222 dwKey = 1;
@@ -270,18 +285,18 @@ extern "C" HRESULT DAPI MetaGetValue(
285 if (!piMetabase)
286 {
287 hr = ::CoInitialize(NULL);
273 - ExitOnFailure(hr, "failed to initialize COM");
288 + MetaExitOnFailure(hr, "failed to initialize COM");
289 fInitialized = TRUE;
290
291 hr = ::CoCreateInstance(CLSID_MSAdminBase, NULL, CLSCTX_ALL, IID_IMSAdminBase, reinterpret_cast<LPVOID*>(&piMetabase));
277 - ExitOnFailure(hr, "failed to get IID_IMSAdminBaseW object");
292 + MetaExitOnFailure(hr, "failed to get IID_IMSAdminBaseW object");
293 }
294
295 if (!pmr->pbMDData)
296 {
297 pmr->dwMDDataLen = 256;
298 pmr->pbMDData = static_cast<BYTE*>(MemAlloc(pmr->dwMDDataLen, TRUE));
284 - ExitOnNull(pmr->pbMDData, hr, E_OUTOFMEMORY, "failed to allocate memory for metabase value");
299 + MetaExitOnNull(pmr->pbMDData, hr, E_OUTOFMEMORY, "failed to allocate memory for metabase value");
300 }
301 else // set the size of the data to the actual size of the memory
302 pmr->dwMDDataLen = (DWORD)MemSize(pmr->pbMDData);
@@ -291,12 +306,12 @@ extern "C" HRESULT DAPI MetaGetValue(
306 {
307 pmr->dwMDDataLen = cbRequired;
308 BYTE* pb = static_cast<BYTE*>(MemReAlloc(pmr->pbMDData, pmr->dwMDDataLen, TRUE));
294 - ExitOnNull(pb, hr, E_OUTOFMEMORY, "failed to reallocate memory for metabase value");
309 + MetaExitOnNull(pb, hr, E_OUTOFMEMORY, "failed to reallocate memory for metabase value");
310
311 pmr->pbMDData = pb;
312 hr = piMetabase->GetData(mhKey, wzKey, pmr, &cbRequired);
313 }
299 - ExitOnFailure(hr, "failed to get metabase data");
314 + MetaExitOnFailure(hr, "failed to get metabase data");
315
316 LExit:
317 if (fInitialized)
src/dutil/monutil.cpp
+110 -95
@@ -2,6 +2,21 @@
2
3 #include "precomp.h"
4
5 +
6 +// Exit macros
7 +#define MonExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_MONUTIL, x, s, __VA_ARGS__)
8 +#define MonExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_MONUTIL, x, s, __VA_ARGS__)
9 +#define MonExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_MONUTIL, x, s, __VA_ARGS__)
10 +#define MonExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_MONUTIL, x, s, __VA_ARGS__)
11 +#define MonExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_MONUTIL, x, s, __VA_ARGS__)
12 +#define MonExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_MONUTIL, x, s, __VA_ARGS__)
13 +#define MonExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_MONUTIL, p, x, e, s, __VA_ARGS__)
14 +#define MonExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_MONUTIL, p, x, s, __VA_ARGS__)
15 +#define MonExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_MONUTIL, p, x, e, s, __VA_ARGS__)
16 +#define MonExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_MONUTIL, p, x, s, __VA_ARGS__)
17 +#define MonExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_MONUTIL, e, x, s, __VA_ARGS__)
18 +#define MonExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_MONUTIL, g, x, s, __VA_ARGS__)
19 +
20 const int MON_THREAD_GROWTH = 5;
21 const int MON_ARRAY_GROWTH = 40;
22 const int MON_MAX_MONITORS_PER_THREAD = 63;
@@ -218,10 +233,10 @@ static void MonRequestDestroy(
233 __in MON_REQUEST *pRequest
234 );
235 static void MonAddMessageDestroy(
221 - __in MON_ADD_MESSAGE *pMessage
236 + __in_opt MON_ADD_MESSAGE *pMessage
237 );
238 static void MonRemoveMessageDestroy(
224 - __in MON_REMOVE_MESSAGE *pMessage
239 + __in_opt MON_REMOVE_MESSAGE *pMessage
240 );
241 static BOOL GetRecursiveFlag(
242 __in MON_REQUEST *pRequest,
@@ -262,7 +277,7 @@ static HRESULT UpdateWaitStatus(
277 __in HRESULT hrNewStatus,
278 __inout MON_WAITER_CONTEXT *pWaiterContext,
279 __in DWORD dwRequestIndex,
265 - __out DWORD *pdwNewRequestIndex
280 + __out_opt DWORD *pdwNewRequestIndex
281 );
282
283 extern "C" HRESULT DAPI MonCreate(
@@ -277,11 +292,11 @@ extern "C" HRESULT DAPI MonCreate(
292 HRESULT hr = S_OK;
293 DWORD dwRetries = MON_THREAD_INIT_RETRIES;
294
280 - ExitOnNull(pHandle, hr, E_INVALIDARG, "Pointer to handle not specified while creating monitor");
295 + MonExitOnNull(pHandle, hr, E_INVALIDARG, "Pointer to handle not specified while creating monitor");
296
297 // Allocate the struct
298 *pHandle = static_cast<MON_HANDLE>(MemAlloc(sizeof(MON_STRUCT), TRUE));
284 - ExitOnNull(*pHandle, hr, E_OUTOFMEMORY, "Failed to allocate monitor object");
299 + MonExitOnNull(*pHandle, hr, E_OUTOFMEMORY, "Failed to allocate monitor object");
300
301 MON_STRUCT *pm = static_cast<MON_STRUCT *>(*pHandle);
302
@@ -294,7 +309,7 @@ extern "C" HRESULT DAPI MonCreate(
309 pm->hCoordinatorThread = ::CreateThread(NULL, 0, CoordinatorThread, pm, 0, &pm->dwCoordinatorThreadId);
310 if (!pm->hCoordinatorThread)
311 {
297 - ExitWithLastError(hr, "Failed to create waiter thread.");
312 + MonExitWithLastError(hr, "Failed to create waiter thread.");
313 }
314
315 // Ensure the created thread initializes its message queue. It does this first thing, so if it doesn't within 10 seconds, there must be a huge problem.
@@ -307,7 +322,7 @@ extern "C" HRESULT DAPI MonCreate(
322 if (0 == dwRetries)
323 {
324 hr = E_UNEXPECTED;
310 - ExitOnFailure(hr, "Waiter thread apparently never initialized its message queue.");
325 + MonExitOnFailure(hr, "Waiter thread apparently never initialized its message queue.");
326 }
327
328 LExit:
@@ -329,13 +344,13 @@ extern "C" HRESULT DAPI MonAddDirectory(
344 MON_ADD_MESSAGE *pMessage = NULL;
345
346 hr = StrAllocString(&sczOriginalPathRequest, wzDirectory, 0);
332 - ExitOnFailure(hr, "Failed to convert directory string to UNC path");
347 + MonExitOnFailure(hr, "Failed to convert directory string to UNC path");
348
349 hr = PathBackslashTerminate(&sczOriginalPathRequest);
335 - ExitOnFailure(hr, "Failed to ensure directory ends in backslash");
350 + MonExitOnFailure(hr, "Failed to ensure directory ends in backslash");
351
352 pMessage = reinterpret_cast<MON_ADD_MESSAGE *>(MemAlloc(sizeof(MON_ADD_MESSAGE), TRUE));
338 - ExitOnNull(pMessage, hr, E_OUTOFMEMORY, "Failed to allocate memory for message");
353 + MonExitOnNull(pMessage, hr, E_OUTOFMEMORY, "Failed to allocate memory for message");
354
355 if (sczOriginalPathRequest[0] == L'\\' && sczOriginalPathRequest[1] == L'\\')
356 {
@@ -356,7 +371,7 @@ extern "C" HRESULT DAPI MonAddDirectory(
371 hr = S_OK;
372
373 hr = StrAllocString(&sczDirectory, sczOriginalPathRequest, 0);
359 - ExitOnFailure(hr, "Failed to copy original path request: %ls", sczOriginalPathRequest);
374 + MonExitOnFailure(hr, "Failed to copy original path request: %ls", sczOriginalPathRequest);
375 }
376
377 pMessage->handle = INVALID_HANDLE_VALUE;
@@ -369,14 +384,14 @@ extern "C" HRESULT DAPI MonAddDirectory(
384 sczOriginalPathRequest = NULL;
385
386 hr = PathGetHierarchyArray(sczDirectory, &pMessage->request.rgsczPathHierarchy, reinterpret_cast<LPUINT>(&pMessage->request.cPathHierarchy));
372 - ExitOnFailure(hr, "Failed to get hierarchy array for path %ls", sczDirectory);
387 + MonExitOnFailure(hr, "Failed to get hierarchy array for path %ls", sczDirectory);
388
389 if (0 < pMessage->request.cPathHierarchy)
390 {
391 pMessage->request.hrStatus = InitiateWait(&pMessage->request, &pMessage->handle);
392 if (!::PostThreadMessageW(pm->dwCoordinatorThreadId, MON_MESSAGE_ADD, reinterpret_cast<WPARAM>(pMessage), 0))
393 {
379 - ExitWithLastError(hr, "Failed to send message to worker thread to add directory wait for path %ls", sczDirectory);
394 + MonExitWithLastError(hr, "Failed to send message to worker thread to add directory wait for path %ls", sczDirectory);
395 }
396 pMessage = NULL;
397 }
@@ -405,16 +420,16 @@ extern "C" HRESULT DAPI MonAddRegKey(
420 MON_ADD_MESSAGE *pMessage = NULL;
421
422 hr = StrAllocString(&sczSubKey, wzSubKey, 0);
408 - ExitOnFailure(hr, "Failed to copy subkey string");
423 + MonExitOnFailure(hr, "Failed to copy subkey string");
424
425 hr = PathBackslashTerminate(&sczSubKey);
411 - ExitOnFailure(hr, "Failed to ensure subkey path ends in backslash");
426 + MonExitOnFailure(hr, "Failed to ensure subkey path ends in backslash");
427
428 pMessage = reinterpret_cast<MON_ADD_MESSAGE *>(MemAlloc(sizeof(MON_ADD_MESSAGE), TRUE));
414 - ExitOnNull(pMessage, hr, E_OUTOFMEMORY, "Failed to allocate memory for message");
429 + MonExitOnNull(pMessage, hr, E_OUTOFMEMORY, "Failed to allocate memory for message");
430
431 pMessage->handle = ::CreateEventW(NULL, TRUE, FALSE, NULL);
417 - ExitOnNullWithLastError(pMessage->handle, hr, "Failed to create anonymous event for regkey monitor");
432 + MonExitOnNullWithLastError(pMessage->handle, hr, "Failed to create anonymous event for regkey monitor");
433
434 pMessage->request.type = MON_REGKEY;
435 pMessage->request.regkey.hkRoot = hkRoot;
@@ -425,16 +440,16 @@ extern "C" HRESULT DAPI MonAddRegKey(
440 pMessage->request.pvContext = pvRegKeyContext;
441
442 hr = PathGetHierarchyArray(sczSubKey, &pMessage->request.rgsczPathHierarchy, reinterpret_cast<LPUINT>(&pMessage->request.cPathHierarchy));
428 - ExitOnFailure(hr, "Failed to get hierarchy array for subkey %ls", sczSubKey);
443 + MonExitOnFailure(hr, "Failed to get hierarchy array for subkey %ls", sczSubKey);
444
445 if (0 < pMessage->request.cPathHierarchy)
446 {
447 pMessage->request.hrStatus = InitiateWait(&pMessage->request, &pMessage->handle);
433 - ExitOnFailure(hr, "Failed to initiate wait");
448 + MonExitOnFailure(hr, "Failed to initiate wait");
449
450 if (!::PostThreadMessageW(pm->dwCoordinatorThreadId, MON_MESSAGE_ADD, reinterpret_cast<WPARAM>(pMessage), 0))
451 {
437 - ExitWithLastError(hr, "Failed to send message to worker thread to add directory wait for regkey %ls", sczSubKey);
452 + MonExitWithLastError(hr, "Failed to send message to worker thread to add directory wait for regkey %ls", sczSubKey);
453 }
454 pMessage = NULL;
455 }
@@ -458,23 +473,23 @@ extern "C" HRESULT DAPI MonRemoveDirectory(
473 MON_REMOVE_MESSAGE *pMessage = NULL;
474
475 hr = StrAllocString(&sczDirectory, wzDirectory, 0);
461 - ExitOnFailure(hr, "Failed to copy directory string");
476 + MonExitOnFailure(hr, "Failed to copy directory string");
477
478 hr = PathBackslashTerminate(&sczDirectory);
464 - ExitOnFailure(hr, "Failed to ensure directory ends in backslash");
479 + MonExitOnFailure(hr, "Failed to ensure directory ends in backslash");
480
481 pMessage = reinterpret_cast<MON_REMOVE_MESSAGE *>(MemAlloc(sizeof(MON_REMOVE_MESSAGE), TRUE));
467 - ExitOnNull(pMessage, hr, E_OUTOFMEMORY, "Failed to allocate memory for message");
482 + MonExitOnNull(pMessage, hr, E_OUTOFMEMORY, "Failed to allocate memory for message");
483
484 pMessage->type = MON_DIRECTORY;
485 pMessage->fRecursive = fRecursive;
486
487 hr = StrAllocString(&pMessage->directory.sczDirectory, sczDirectory, 0);
473 - ExitOnFailure(hr, "Failed to allocate copy of directory string");
488 + MonExitOnFailure(hr, "Failed to allocate copy of directory string");
489
490 if (!::PostThreadMessageW(pm->dwCoordinatorThreadId, MON_MESSAGE_REMOVE, reinterpret_cast<WPARAM>(pMessage), 0))
491 {
477 - ExitWithLastError(hr, "Failed to send message to worker thread to add directory wait for path %ls", sczDirectory);
492 + MonExitWithLastError(hr, "Failed to send message to worker thread to add directory wait for path %ls", sczDirectory);
493 }
494 pMessage = NULL;
495
@@ -498,13 +513,13 @@ extern "C" HRESULT DAPI MonRemoveRegKey(
513 MON_REMOVE_MESSAGE *pMessage = NULL;
514
515 hr = StrAllocString(&sczSubKey, wzSubKey, 0);
501 - ExitOnFailure(hr, "Failed to copy subkey string");
516 + MonExitOnFailure(hr, "Failed to copy subkey string");
517
518 hr = PathBackslashTerminate(&sczSubKey);
504 - ExitOnFailure(hr, "Failed to ensure subkey path ends in backslash");
519 + MonExitOnFailure(hr, "Failed to ensure subkey path ends in backslash");
520
521 pMessage = reinterpret_cast<MON_REMOVE_MESSAGE *>(MemAlloc(sizeof(MON_REMOVE_MESSAGE), TRUE));
507 - ExitOnNull(pMessage, hr, E_OUTOFMEMORY, "Failed to allocate memory for message");
522 + MonExitOnNull(pMessage, hr, E_OUTOFMEMORY, "Failed to allocate memory for message");
523
524 pMessage->type = MON_REGKEY;
525 pMessage->regkey.hkRoot = hkRoot;
@@ -512,11 +527,11 @@ extern "C" HRESULT DAPI MonRemoveRegKey(
527 pMessage->fRecursive = fRecursive;
528
529 hr = StrAllocString(&pMessage->regkey.sczSubKey, sczSubKey, 0);
515 - ExitOnFailure(hr, "Failed to allocate copy of directory string");
530 + MonExitOnFailure(hr, "Failed to allocate copy of directory string");
531
532 if (!::PostThreadMessageW(pm->dwCoordinatorThreadId, MON_MESSAGE_REMOVE, reinterpret_cast<WPARAM>(pMessage), 0))
533 {
519 - ExitWithLastError(hr, "Failed to send message to worker thread to add directory wait for path %ls", sczSubKey);
534 + MonExitWithLastError(hr, "Failed to send message to worker thread to add directory wait for path %ls", sczSubKey);
535 }
536 pMessage = NULL;
537
@@ -543,7 +558,7 @@ extern "C" void DAPI MonDestroy(
558 // It already halted, or doesn't exist for some other reason, so let's just ignore it and clean up
559 er = ERROR_SUCCESS;
560 }
546 - ExitOnWin32Error(er, hr, "Failed to send message to background thread to halt");
561 + MonExitOnWin32Error(er, hr, "Failed to send message to background thread to halt");
562 }
563
564 if (pm->hCoordinatorThread)
@@ -577,10 +592,10 @@ static void MonRequestDestroy(
592 }
593
594 static void MonAddMessageDestroy(
580 - __in MON_ADD_MESSAGE *pMessage
595 + __in_opt MON_ADD_MESSAGE *pMessage
596 )
597 {
583 - if (NULL != pMessage)
598 + if (pMessage)
599 {
600 MonRequestDestroy(&pMessage->request);
601 if (MON_DIRECTORY == pMessage->request.type && INVALID_HANDLE_VALUE != pMessage->handle)
@@ -597,10 +612,10 @@ static void MonAddMessageDestroy(
612 }
613
614 static void MonRemoveMessageDestroy(
600 - __in MON_REMOVE_MESSAGE *pMessage
615 + __in_opt MON_REMOVE_MESSAGE *pMessage
616 )
617 {
603 - if (NULL != pMessage)
618 + if (pMessage)
619 {
620 switch (pMessage->type)
621 {
@@ -642,17 +657,17 @@ static DWORD WINAPI CoordinatorThread(
657 pm->fCoordinatorThreadMessageQueueInitialized = TRUE;
658
659 hr = CreateMonWindow(pm, &pm->hwnd);
645 - ExitOnFailure(hr, "Failed to create window for status update thread");
660 + MonExitOnFailure(hr, "Failed to create window for status update thread");
661
662 ::WSAStartup(MAKEWORD(2, 2), &wsaData);
663
664 hr = WaitForNetworkChanges(&hMonitor, pm);
650 - ExitOnFailure(hr, "Failed to wait for network changes");
665 + MonExitOnFailure(hr, "Failed to wait for network changes");
666
667 uTimerSuccessfulNetworkRetry = ::SetTimer(NULL, 1, MON_THREAD_NETWORK_SUCCESSFUL_RETRY_IN_MS, NULL);
668 if (0 == uTimerSuccessfulNetworkRetry)
669 {
655 - ExitWithLastError(hr, "Failed to set timer for network successful retry");
670 + MonExitWithLastError(hr, "Failed to set timer for network successful retry");
671 }
672
673 while (0 != (fRet = ::GetMessageW(&msg, NULL, 0, 0)))
@@ -660,7 +675,7 @@ static DWORD WINAPI CoordinatorThread(
675 if (-1 == fRet)
676 {
677 hr = E_UNEXPECTED;
663 - ExitOnRootFailure(hr, "Unexpected return value from message pump.");
678 + MonExitOnRootFailure(hr, "Unexpected return value from message pump.");
679 }
680 else
681 {
@@ -684,12 +699,12 @@ static DWORD WINAPI CoordinatorThread(
699 else
700 {
701 hr = MemEnsureArraySize(reinterpret_cast<void **>(&pm->rgWaiterThreads), pm->cWaiterThreads + 1, sizeof(MON_WAITER_INFO), MON_THREAD_GROWTH);
687 - ExitOnFailure(hr, "Failed to grow waiter thread array size");
702 + MonExitOnFailure(hr, "Failed to grow waiter thread array size");
703 ++pm->cWaiterThreads;
704
705 dwThreadIndex = pm->cWaiterThreads - 1;
706 pm->rgWaiterThreads[dwThreadIndex].pWaiterContext = reinterpret_cast<MON_WAITER_CONTEXT*>(MemAlloc(sizeof(MON_WAITER_CONTEXT), TRUE));
692 - ExitOnNull(pm->rgWaiterThreads[dwThreadIndex].pWaiterContext, hr, E_OUTOFMEMORY, "Failed to allocate waiter context struct");
707 + MonExitOnNull(pm->rgWaiterThreads[dwThreadIndex].pWaiterContext, hr, E_OUTOFMEMORY, "Failed to allocate waiter context struct");
708 pWaiterContext = pm->rgWaiterThreads[dwThreadIndex].pWaiterContext;
709 pWaiterContext->dwCoordinatorThreadId = ::GetCurrentThreadId();
710 pWaiterContext->vpfMonGeneral = pm->vpfMonGeneral;
@@ -698,16 +713,16 @@ static DWORD WINAPI CoordinatorThread(
713 pWaiterContext->pvContext = pm->pvContext;
714
715 hr = MemEnsureArraySize(reinterpret_cast<void **>(&pWaiterContext->rgHandles), MON_MAX_MONITORS_PER_THREAD + 1, sizeof(HANDLE), 0);
701 - ExitOnFailure(hr, "Failed to allocate first handle");
716 + MonExitOnFailure(hr, "Failed to allocate first handle");
717 pWaiterContext->cHandles = 1;
718
719 pWaiterContext->rgHandles[0] = ::CreateEventW(NULL, FALSE, FALSE, NULL);
705 - ExitOnNullWithLastError(pWaiterContext->rgHandles[0], hr, "Failed to create general event");
720 + MonExitOnNullWithLastError(pWaiterContext->rgHandles[0], hr, "Failed to create general event");
721
722 pWaiterContext->hWaiterThread = ::CreateThread(NULL, 0, WaiterThread, pWaiterContext, 0, &pWaiterContext->dwWaiterThreadId);
723 if (!pWaiterContext->hWaiterThread)
724 {
710 - ExitWithLastError(hr, "Failed to create waiter thread.");
725 + MonExitWithLastError(hr, "Failed to create waiter thread.");
726 }
727
728 dwRetries = MON_THREAD_INIT_RETRIES;
@@ -720,19 +735,19 @@ static DWORD WINAPI CoordinatorThread(
735 if (0 == dwRetries)
736 {
737 hr = E_UNEXPECTED;
723 - ExitOnFailure(hr, "Waiter thread apparently never initialized its message queue.");
738 + MonExitOnFailure(hr, "Waiter thread apparently never initialized its message queue.");
739 }
740 }
741
742 ++pm->rgWaiterThreads[dwThreadIndex].cMonitorCount;
743 if (!::PostThreadMessageW(pWaiterContext->dwWaiterThreadId, MON_MESSAGE_ADD, msg.wParam, 0))
744 {
730 - ExitWithLastError(hr, "Failed to send message to waiter thread to add monitor");
745 + MonExitWithLastError(hr, "Failed to send message to waiter thread to add monitor");
746 }
747
748 if (!::SetEvent(pWaiterContext->rgHandles[0]))
749 {
735 - ExitWithLastError(hr, "Failed to set event to notify waiter thread of incoming message");
750 + MonExitWithLastError(hr, "Failed to set event to notify waiter thread of incoming message");
751 }
752 break;
753
@@ -746,17 +761,17 @@ static DWORD WINAPI CoordinatorThread(
761 pRemoveMessage = reinterpret_cast<MON_REMOVE_MESSAGE *>(msg.wParam);
762
763 hr = DuplicateRemoveMessage(pRemoveMessage, &pTempRemoveMessage);
749 - ExitOnFailure(hr, "Failed to duplicate remove message");
764 + MonExitOnFailure(hr, "Failed to duplicate remove message");
765
766 if (!::PostThreadMessageW(pWaiterContext->dwWaiterThreadId, MON_MESSAGE_REMOVE, reinterpret_cast<WPARAM>(pTempRemoveMessage), msg.lParam))
767 {
753 - ExitWithLastError(hr, "Failed to send message to waiter thread to add monitor");
768 + MonExitWithLastError(hr, "Failed to send message to waiter thread to add monitor");
769 }
770 pTempRemoveMessage = NULL;
771
772 if (!::SetEvent(pWaiterContext->rgHandles[0]))
773 {
759 - ExitWithLastError(hr, "Failed to set event to notify waiter thread of incoming remove message");
774 + MonExitWithLastError(hr, "Failed to set event to notify waiter thread of incoming remove message");
775 }
776 }
777 MonRemoveMessageDestroy(pRemoveMessage);
@@ -774,7 +789,7 @@ static DWORD WINAPI CoordinatorThread(
789 {
790 if (!::PostThreadMessageW(pm->rgWaiterThreads[i].pWaiterContext->dwWaiterThreadId, MON_MESSAGE_STOP, msg.wParam, msg.lParam))
791 {
777 - ExitWithLastError(hr, "Failed to send message to waiter thread to stop");
792 + MonExitWithLastError(hr, "Failed to send message to waiter thread to stop");
793 }
794 MemRemoveFromArray(reinterpret_cast<LPVOID>(pm->rgWaiterThreads), i, 1, pm->cWaiterThreads, sizeof(MON_WAITER_INFO), TRUE);
795 --pm->cWaiterThreads;
@@ -790,7 +805,7 @@ static DWORD WINAPI CoordinatorThread(
805 uTimerFailedNetworkRetry = ::SetTimer(NULL, uTimerSuccessfulNetworkRetry + 1, MON_THREAD_NETWORK_FAIL_RETRY_IN_MS, NULL);
806 if (0 == uTimerFailedNetworkRetry)
807 {
793 - ExitWithLastError(hr, "Failed to set timer for network fail retry");
808 + MonExitWithLastError(hr, "Failed to set timer for network fail retry");
809 }
810 }
811 ++dwFailingNetworkWaits;
@@ -802,7 +817,7 @@ static DWORD WINAPI CoordinatorThread(
817 {
818 if (!::KillTimer(NULL, uTimerFailedNetworkRetry))
819 {
805 - ExitWithLastError(hr, "Failed to kill timer for network fail retry");
820 + MonExitWithLastError(hr, "Failed to kill timer for network fail retry");
821 }
822 uTimerFailedNetworkRetry = 0;
823 }
@@ -810,7 +825,7 @@ static DWORD WINAPI CoordinatorThread(
825
826 case MON_MESSAGE_NETWORK_STATUS_UPDATE:
827 hr = WaitForNetworkChanges(&hMonitor, pm);
813 - ExitOnFailure(hr, "Failed to re-wait for network changes");
828 + MonExitOnFailure(hr, "Failed to re-wait for network changes");
829
830 // Propagate any network status update messages to all waiter threads
831 for (DWORD i = 0; i < pm->cWaiterThreads; ++i)
@@ -819,12 +834,12 @@ static DWORD WINAPI CoordinatorThread(
834
835 if (!::PostThreadMessageW(pWaiterContext->dwWaiterThreadId, MON_MESSAGE_NETWORK_STATUS_UPDATE, 0, 0))
836 {
822 - ExitWithLastError(hr, "Failed to send message to waiter thread to notify of network status update");
837 + MonExitWithLastError(hr, "Failed to send message to waiter thread to notify of network status update");
838 }
839
840 if (!::SetEvent(pWaiterContext->rgHandles[0]))
841 {
827 - ExitWithLastError(hr, "Failed to set event to notify waiter thread of incoming network status update message");
842 + MonExitWithLastError(hr, "Failed to set event to notify waiter thread of incoming network status update message");
843 }
844 }
845 break;
@@ -837,12 +852,12 @@ static DWORD WINAPI CoordinatorThread(
852
853 if (!::PostThreadMessageW(pWaiterContext->dwWaiterThreadId, msg.wParam == uTimerFailedNetworkRetry ? MON_MESSAGE_NETWORK_RETRY_FAILED_NETWORK_WAITS : MON_MESSAGE_NETWORK_RETRY_SUCCESSFUL_NETWORK_WAITS, 0, 0))
854 {
840 - ExitWithLastError(hr, "Failed to send message to waiter thread to notify of network status update");
855 + MonExitWithLastError(hr, "Failed to send message to waiter thread to notify of network status update");
856 }
857
858 if (!::SetEvent(pWaiterContext->rgHandles[0]))
859 {
845 - ExitWithLastError(hr, "Failed to set event to notify waiter thread of incoming network status update message");
860 + MonExitWithLastError(hr, "Failed to set event to notify waiter thread of incoming network status update message");
861 }
862 }
863 break;
@@ -861,12 +876,12 @@ static DWORD WINAPI CoordinatorThread(
876
877 if (!::PostThreadMessageW(pWaiterContext->dwWaiterThreadId, MON_MESSAGE_DRIVE_STATUS_UPDATE, msg.wParam, msg.lParam))
878 {
864 - ExitWithLastError(hr, "Failed to send message to waiter thread to notify of drive status update");
879 + MonExitWithLastError(hr, "Failed to send message to waiter thread to notify of drive status update");
880 }
881
882 if (!::SetEvent(pWaiterContext->rgHandles[0]))
883 {
869 - ExitWithLastError(hr, "Failed to set event to notify waiter thread of incoming drive status update message");
884 + MonExitWithLastError(hr, "Failed to set event to notify waiter thread of incoming drive status update message");
885 }
886 }
887 break;
@@ -998,7 +1013,7 @@ static HRESULT InitiateWait(
1013 {
1014 continue;
1015 }
1001 - ExitOnWin32Error(er, hr, "Failed to wait on path %ls", pRequest->rgsczPathHierarchy[dwIndex]);
1016 + MonExitOnWin32Error(er, hr, "Failed to wait on path %ls", pRequest->rgsczPathHierarchy[dwIndex]);
1017 }
1018 else
1019 {
@@ -1013,7 +1028,7 @@ static HRESULT InitiateWait(
1028 {
1029 continue;
1030 }
1016 - ExitOnFailure(hr, "Failed to open regkey %ls", pRequest->rgsczPathHierarchy[dwIndex]);
1031 + MonExitOnFailure(hr, "Failed to open regkey %ls", pRequest->rgsczPathHierarchy[dwIndex]);
1032
1033 er = ::RegNotifyChangeKeyValue(pRequest->regkey.hkSubKey, GetRecursiveFlag(pRequest, dwIndex), REG_NOTIFY_CHANGE_NAME | REG_NOTIFY_CHANGE_LAST_SET | REG_NOTIFY_CHANGE_SECURITY, *pHandle, TRUE);
1034 ReleaseRegKey(hk);
@@ -1024,7 +1039,7 @@ static HRESULT InitiateWait(
1039 }
1040 else
1041 {
1027 - ExitOnWin32Error(er, hr, "Failed to wait on subkey %ls", pRequest->rgsczPathHierarchy[dwIndex]);
1042 + MonExitOnWin32Error(er, hr, "Failed to wait on subkey %ls", pRequest->rgsczPathHierarchy[dwIndex]);
1043
1044 fHandleFound = TRUE;
1045 }
@@ -1062,7 +1077,7 @@ static HRESULT InitiateWait(
1077 }
1078 } while (fRedo);
1079
1065 - ExitOnFailure(hr, "Didn't get a successful wait after looping through all available options %ls", pRequest->rgsczPathHierarchy[pRequest->cPathHierarchy - 1]);
1080 + MonExitOnFailure(hr, "Didn't get a successful wait after looping through all available options %ls", pRequest->rgsczPathHierarchy[pRequest->cPathHierarchy - 1]);
1081
1082 if (MON_DIRECTORY == pRequest->type)
1083 {
@@ -1141,7 +1156,7 @@ static DWORD WINAPI WaiterThread(
1156 }
1157
1158 hr = MemInsertIntoArray(reinterpret_cast<void **>(&pWaiterContext->rgHandles), dwNewRequestIndex + 1, 1, pWaiterContext->cHandles, sizeof(HANDLE), MON_ARRAY_GROWTH);
1144 - ExitOnFailure(hr, "Failed to insert additional handle");
1159 + MonExitOnFailure(hr, "Failed to insert additional handle");
1160 ++pWaiterContext->cHandles;
1161
1162 // Ugh - directory types start with INVALID_HANDLE_VALUE instead of NULL
@@ -1151,7 +1166,7 @@ static DWORD WINAPI WaiterThread(
1166 }
1167
1168 hr = MemInsertIntoArray(reinterpret_cast<void **>(&pWaiterContext->rgRequests), dwNewRequestIndex, 1, pWaiterContext->cRequests, sizeof(MON_REQUEST), MON_ARRAY_GROWTH);
1154 - ExitOnFailure(hr, "Failed to insert additional request struct");
1169 + MonExitOnFailure(hr, "Failed to insert additional request struct");
1170 ++pWaiterContext->cRequests;
1171
1172 pWaiterContext->rgRequests[dwNewRequestIndex] = pAddMessage->request;
@@ -1172,10 +1187,10 @@ static DWORD WINAPI WaiterThread(
1187 }
1188 else
1189 {
1175 - ExitOnFailure(hr, "Failed to find request index for remove message");
1190 + MonExitOnFailure(hr, "Failed to find request index for remove message");
1191
1192 hr = RemoveRequest(pWaiterContext, dwRequestIndex);
1178 - ExitOnFailure(hr, "Failed to remove request after request from coordinator thread.");
1193 + MonExitOnFailure(hr, "Failed to remove request after request from coordinator thread.");
1194 }
1195
1196 MonRemoveMessageDestroy(pRemoveMessage);
@@ -1204,7 +1219,7 @@ static DWORD WINAPI WaiterThread(
1219 hrTemp = InitiateWait(pWaiterContext->rgRequests + i, pWaiterContext->rgHandles + i + 1);
1220
1221 hr = UpdateWaitStatus(hrTemp, pWaiterContext, i, &dwNewRequestIndex);
1207 - ExitOnFailure(hr, "Failed to update wait status");
1222 + MonExitOnFailure(hr, "Failed to update wait status");
1223 hrTemp = S_OK;
1224
1225 if (dwNewRequestIndex != i)
@@ -1239,7 +1254,7 @@ static DWORD WINAPI WaiterThread(
1254 hrTemp = InitiateWait(pWaiterContext->rgRequests + i, pWaiterContext->rgHandles + i + 1);
1255
1256 hr = UpdateWaitStatus(hrTemp, pWaiterContext, i, &dwNewRequestIndex);
1242 - ExitOnFailure(hr, "Failed to update wait status");
1257 + MonExitOnFailure(hr, "Failed to update wait status");
1258 hrTemp = S_OK;
1259
1260 if (dwNewRequestIndex != i)
@@ -1274,7 +1289,7 @@ static DWORD WINAPI WaiterThread(
1289 hrTemp = InitiateWait(pWaiterContext->rgRequests + i, pWaiterContext->rgHandles + i + 1);
1290
1291 hr = UpdateWaitStatus(hrTemp, pWaiterContext, i, &dwNewRequestIndex);
1277 - ExitOnFailure(hr, "Failed to update wait status");
1292 + MonExitOnFailure(hr, "Failed to update wait status");
1293 hrTemp = S_OK;
1294
1295 if (dwNewRequestIndex != i)
@@ -1311,7 +1326,7 @@ static DWORD WINAPI WaiterThread(
1326 }
1327
1328 hr = UpdateWaitStatus(hrTemp, pWaiterContext, i, &dwNewRequestIndex);
1314 - ExitOnFailure(hr, "Failed to update wait status");
1329 + MonExitOnFailure(hr, "Failed to update wait status");
1330 hrTemp = S_OK;
1331
1332 if (dwNewRequestIndex != i)
@@ -1354,7 +1369,7 @@ static DWORD WINAPI WaiterThread(
1369 hrTemp = E_PATHNOTFOUND;
1370
1371 hr = UpdateWaitStatus(hrTemp, pWaiterContext, i, &dwNewRequestIndex);
1357 - ExitOnFailure(hr, "Failed to update wait status");
1372 + MonExitOnFailure(hr, "Failed to update wait status");
1373 hrTemp = S_OK;
1374 break;
1375 }
@@ -1385,7 +1400,7 @@ static DWORD WINAPI WaiterThread(
1400 // Initiate re-waits before we notify callback, to ensure we don't miss a single update
1401 hrTemp = InitiateWait(pWaiterContext->rgRequests + dwRequestIndex, pWaiterContext->rgHandles + dwRequestIndex + 1);
1402 hr = UpdateWaitStatus(hrTemp, pWaiterContext, dwRequestIndex, &dwRequestIndex);
1388 - ExitOnFailure(hr, "Failed to update wait status");
1403 + MonExitOnFailure(hr, "Failed to update wait status");
1404 hrTemp = S_OK;
1405
1406 // If there were no errors and we were already waiting on the right target, or if we weren't yet but are able to now, it's a successful notify
@@ -1413,7 +1428,7 @@ static DWORD WINAPI WaiterThread(
1428 }
1429 else if (WAIT_TIMEOUT != dwRet)
1430 {
1416 - ExitWithLastError(hr, "Failed to wait for multiple objects with return code %u", dwRet);
1431 + MonExitWithLastError(hr, "Failed to wait for multiple objects with return code %u", dwRet);
1432 }
1433
1434 // OK, now that we've checked all triggered handles (resetting silence period timers appropriately), check for any pending notifications that we can finally fire
@@ -1432,7 +1447,7 @@ static DWORD WINAPI WaiterThread(
1447 {
1448 Assert(FALSE);
1449 hr = HRESULT_FROM_WIN32(ERROR_EA_LIST_INCONSISTENT);
1435 - ExitOnFailure(hr, "Phantom pending fires were found!");
1450 + MonExitOnFailure(hr, "Phantom pending fires were found!");
1451 }
1452 --cRequestsPendingBeforeLoop;
1453
@@ -1470,13 +1485,13 @@ static DWORD WINAPI WaiterThread(
1485 {
1486 Assert(FALSE);
1487 hr = HRESULT_FROM_WIN32(PEERDIST_ERROR_MISSING_DATA);
1473 - ExitOnFailure(hr, "Missing %u pending fires! Total pending fires: %u, wait: %u", cRequestsPendingBeforeLoop, pWaiterContext->cRequestsPending, dwWait);
1488 + MonExitOnFailure(hr, "Missing %u pending fires! Total pending fires: %u, wait: %u", cRequestsPendingBeforeLoop, pWaiterContext->cRequestsPending, dwWait);
1489 }
1490 if (0 < pWaiterContext->cRequestsPending && DWORD_MAX == dwWait)
1491 {
1492 Assert(FALSE);
1493 hr = HRESULT_FROM_WIN32(ERROR_CANT_WAIT);
1479 - ExitOnFailure(hr, "Pending fires exist, but wait was infinite", cRequestsPendingBeforeLoop);
1494 + MonExitOnFailure(hr, "Pending fires exist (%u), but wait was infinite", cRequestsPendingBeforeLoop);
1495 }
1496 }
1497 } while (fContinue);
@@ -1651,7 +1666,7 @@ static HRESULT RemoveRequest(
1666 // Notify coordinator thread that a wait was removed
1667 if (!::PostThreadMessageW(pWaiterContext->dwCoordinatorThreadId, MON_MESSAGE_REMOVED, static_cast<WPARAM>(::GetCurrentThreadId()), 0))
1668 {
1654 - ExitWithLastError(hr, "Failed to send message to coordinator thread to confirm directory was removed.");
1669 + MonExitWithLastError(hr, "Failed to send message to coordinator thread to confirm directory was removed.");
1670 }
1671
1672 LExit:
@@ -1684,7 +1699,7 @@ static HRESULT DuplicateRemoveMessage(
1699 HRESULT hr = S_OK;
1700
1701 *ppMessage = reinterpret_cast<MON_REMOVE_MESSAGE *>(MemAlloc(sizeof(MON_REMOVE_MESSAGE), TRUE));
1687 - ExitOnNull(*ppMessage, hr, E_OUTOFMEMORY, "Failed to allocate copy of remove message");
1702 + MonExitOnNull(*ppMessage, hr, E_OUTOFMEMORY, "Failed to allocate copy of remove message");
1703
1704 (*ppMessage)->type = pMessage->type;
1705 (*ppMessage)->fRecursive = pMessage->fRecursive;
@@ -1693,13 +1708,13 @@ static HRESULT DuplicateRemoveMessage(
1708 {
1709 case MON_DIRECTORY:
1710 hr = StrAllocString(&(*ppMessage)->directory.sczDirectory, pMessage->directory.sczDirectory, 0);
1696 - ExitOnFailure(hr, "Failed to copy directory");
1711 + MonExitOnFailure(hr, "Failed to copy directory");
1712 break;
1713 case MON_REGKEY:
1714 (*ppMessage)->regkey.hkRoot = pMessage->regkey.hkRoot;
1715 (*ppMessage)->regkey.kbKeyBitness = pMessage->regkey.kbKeyBitness;
1716 hr = StrAllocString(&(*ppMessage)->regkey.sczSubKey, pMessage->regkey.sczSubKey, 0);
1702 - ExitOnFailure(hr, "Failed to copy subkey");
1717 + MonExitOnFailure(hr, "Failed to copy subkey");
1718 break;
1719 default:
1720 Assert(false);
@@ -1764,7 +1779,7 @@ static LRESULT CALLBACK MonWndProc(
1779 // This drive had a status update, so send it out to all threads
1780 if (!::PostThreadMessageW(::GetCurrentThreadId(), MON_MESSAGE_DRIVE_STATUS_UPDATE, static_cast<WPARAM>(chDrive), static_cast<LPARAM>(fArrival)))
1781 {
1767 - ExitWithLastError(hr, "Failed to send drive status update with drive %wc and arrival %ls", chDrive, fArrival ? L"TRUE" : L"FALSE");
1782 + MonExitWithLastError(hr, "Failed to send drive status update with drive %wc and arrival %ls", chDrive, fArrival ? L"TRUE" : L"FALSE");
1783 }
1784 }
1785 dwUnitMask >>= 1;
@@ -1773,7 +1788,7 @@ static LRESULT CALLBACK MonWndProc(
1788 if (chDrive == 'z')
1789 {
1790 hr = E_UNEXPECTED;
1776 - ExitOnFailure(hr, "UnitMask showed drives beyond z:. Remaining UnitMask at this point: %u", dwUnitMask);
1791 + MonExitOnFailure(hr, "UnitMask showed drives beyond z:. Remaining UnitMask at this point: %u", dwUnitMask);
1792 }
1793 }
1794 }
@@ -1785,7 +1800,7 @@ static LRESULT CALLBACK MonWndProc(
1800 if (!pm)
1801 {
1802 hr = E_POINTER;
1788 - ExitOnFailure(hr, "DBT_DEVICEQUERYREMOVE message received with no MON_STRUCT pointer, so message was ignored");
1803 + MonExitOnFailure(hr, "DBT_DEVICEQUERYREMOVE message received with no MON_STRUCT pointer, so message was ignored");
1804 }
1805
1806 fReturnTrue = TRUE;
@@ -1796,7 +1811,7 @@ static LRESULT CALLBACK MonWndProc(
1811 // We must wait for the actual wait handle to be released by waiter thread before telling windows to proceed with device removal, otherwise it could fail
1812 // due to handles still being open, so use a MON_INTERNAL_TEMPORARY_WAIT struct to send and receive a reply from a waiter thread
1813 pm->internalWait.hWait = ::CreateEventW(NULL, TRUE, FALSE, NULL);
1799 - ExitOnNullWithLastError(pm->internalWait.hWait, hr, "Failed to create anonymous event for waiter to notify wndproc device can be removed");
1814 + MonExitOnNullWithLastError(pm->internalWait.hWait, hr, "Failed to create anonymous event for waiter to notify wndproc device can be removed");
1815
1816 pHandle = reinterpret_cast<DEV_BROADCAST_HANDLE*>(lParam);
1817 pm->internalWait.pvContext = pHandle->dbch_handle;
@@ -1808,12 +1823,12 @@ static LRESULT CALLBACK MonWndProc(
1823
1824 if (!::PostThreadMessageW(pWaiterContext->dwWaiterThreadId, MON_MESSAGE_DRIVE_QUERY_REMOVE, reinterpret_cast<WPARAM>(&pm->internalWait), static_cast<LPARAM>(pm->internalWait.dwSendIteration)))
1825 {
1811 - ExitWithLastError(hr, "Failed to send message to waiter thread to notify of drive query remove");
1826 + MonExitWithLastError(hr, "Failed to send message to waiter thread to notify of drive query remove");
1827 }
1828
1829 if (!::SetEvent(pWaiterContext->rgHandles[0]))
1830 {
1816 - ExitWithLastError(hr, "Failed to set event to notify waiter thread of incoming drive query remove message");
1831 + MonExitWithLastError(hr, "Failed to set event to notify waiter thread of incoming drive query remove message");
1832 }
1833 }
1834
@@ -1833,7 +1848,7 @@ static LRESULT CALLBACK MonWndProc(
1848 }
1849 else
1850 {
1836 - ExitWithLastError(hr, "WaitForSingleObject failed with non-timeout reason while waiting for response from waiter thread");
1851 + MonExitWithLastError(hr, "WaitForSingleObject failed with non-timeout reason while waiting for response from waiter thread");
1852 }
1853 ++pm->internalWait.dwSendIteration;
1854 }
@@ -1871,12 +1886,12 @@ static HRESULT CreateMonWindow(
1886 {
1887 if (ERROR_CLASS_ALREADY_EXISTS != ::GetLastError())
1888 {
1874 - ExitWithLastError(hr, "Failed to register MonUtil window class.");
1889 + MonExitWithLastError(hr, "Failed to register MonUtil window class.");
1890 }
1891 }
1892
1893 *pHwnd = ::CreateWindowExW(0, wc.lpszClassName, L"", 0, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, HWND_DESKTOP, NULL, wc.hInstance, pm);
1879 - ExitOnNullWithLastError(*pHwnd, hr, "Failed to create window.");
1894 + MonExitOnNullWithLastError(*pHwnd, hr, "Failed to create window.");
1895
1896 // Rumor has it that drive arrival / removal events can be lost in the rare event that some other application higher up in z-order is hanging if we don't make our window topmost
1897 // SWP_NOACTIVATE is important so the currently active window doesn't lose focus
@@ -1909,7 +1924,7 @@ static HRESULT WaitForNetworkChanges(
1924 if (::WSALookupServiceBegin(&qsRestrictions, LUP_RETURN_ALL, phMonitor))
1925 {
1926 hr = HRESULT_FROM_WIN32(::WSAGetLastError());
1912 - ExitOnFailure(hr, "WSALookupServiceBegin() failed");
1927 + MonExitOnFailure(hr, "WSALookupServiceBegin() failed");
1928 }
1929
1930 wsaCompletion.Type = NSP_NOTIFY_HWND;
@@ -1923,7 +1938,7 @@ static HRESULT WaitForNetworkChanges(
1938 {
1939 hr = E_FAIL;
1940 }
1926 - ExitOnFailure(hr, "WSANSPIoctl() failed with return code %i, wsa last error %u", nResult, ::WSAGetLastError());
1941 + MonExitOnFailure(hr, "WSANSPIoctl() failed with return code %i, wsa last error %u", nResult, ::WSAGetLastError());
1942 }
1943
1944 LExit:
@@ -1960,7 +1975,7 @@ static HRESULT UpdateWaitStatus(
1975 // If it's a network wait, notify coordinator thread that a network wait is failing
1976 if (pRequest->fNetwork && !::PostThreadMessageW(pWaiterContext->dwCoordinatorThreadId, MON_MESSAGE_NETWORK_WAIT_FAILED, 0, 0))
1977 {
1963 - ExitWithLastError(hr, "Failed to send message to coordinator thread to notify a network wait started to fail");
1978 + MonExitWithLastError(hr, "Failed to send message to coordinator thread to notify a network wait started to fail");
1979 }
1980
1981 // Move the failing wait to the end of the list of waits and increment cRequestsFailing so WaitForMultipleObjects isn't passed an invalid handle
@@ -1981,7 +1996,7 @@ static HRESULT UpdateWaitStatus(
1996 // If it's a network wait, notify coordinator thread that a network wait is succeeding again
1997 if (pRequest->fNetwork && !::PostThreadMessageW(pWaiterContext->dwCoordinatorThreadId, MON_MESSAGE_NETWORK_WAIT_SUCCEEDED, 0, 0))
1998 {
1984 - ExitWithLastError(hr, "Failed to send message to coordinator thread to notify a network wait is succeeding again");
1999 + MonExitWithLastError(hr, "Failed to send message to coordinator thread to notify a network wait is succeeding again");
2000 }
2001
2002 --pWaiterContext->cRequestsFailing;
src/dutil/osutil.cpp
+22 -7
@@ -2,6 +2,21 @@
2
3 #include "precomp.h"
4
5 +
6 +// Exit macros
7 +#define OsExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_OSUTIL, x, s, __VA_ARGS__)
8 +#define OsExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_OSUTIL, x, s, __VA_ARGS__)
9 +#define OsExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_OSUTIL, x, s, __VA_ARGS__)
10 +#define OsExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_OSUTIL, x, s, __VA_ARGS__)
11 +#define OsExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_OSUTIL, x, s, __VA_ARGS__)
12 +#define OsExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_OSUTIL, x, s, __VA_ARGS__)
13 +#define OsExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_OSUTIL, p, x, e, s, __VA_ARGS__)
14 +#define OsExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_OSUTIL, p, x, s, __VA_ARGS__)
15 +#define OsExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_OSUTIL, p, x, e, s, __VA_ARGS__)
16 +#define OsExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_OSUTIL, p, x, s, __VA_ARGS__)
17 +#define OsExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_OSUTIL, e, x, s, __VA_ARGS__)
18 +#define OsExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_OSUTIL, g, x, s, __VA_ARGS__)
19 +
20 typedef NTSTATUS(NTAPI* PFN_RTL_GET_VERSION)(_Out_ PRTL_OSVERSIONINFOEXW lpVersionInformation);
21
22 OS_VERSION vOsVersion = OS_VERSION_UNKNOWN;
@@ -127,7 +142,7 @@ extern "C" HRESULT DAPI OsIsRunningPrivileged(
142
143 if (!::OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY, &hToken))
144 {
130 - ExitOnLastError(hr, "Failed to open process token.");
145 + OsExitOnLastError(hr, "Failed to open process token.");
146 }
147
148 if (::GetTokenInformation(hToken, TokenElevationType, &elevationType, sizeof(TOKEN_ELEVATION_TYPE), &dwSize))
@@ -142,7 +157,7 @@ extern "C" HRESULT DAPI OsIsRunningPrivileged(
157 {
158 er = ERROR_SUCCESS;
159 }
145 - ExitOnWin32Error(er, hr, "Failed to get process token information.");
160 + OsExitOnWin32Error(er, hr, "Failed to get process token information.");
161
162 // Fallback to this check for some OS's (like XP)
163 *pfPrivileged = ::AllocateAndInitializeSid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &AdministratorsGroup);
@@ -180,14 +195,14 @@ extern "C" HRESULT DAPI OsIsUacEnabled(
195 {
196 ExitFunction1(hr = S_OK);
197 }
183 - ExitOnFailure(hr, "Failed to open system policy key to detect UAC.");
198 + OsExitOnFailure(hr, "Failed to open system policy key to detect UAC.");
199
200 hr = RegReadNumber(hk, L"EnableLUA", &dwUacEnabled);
201 if (E_FILENOTFOUND == hr)
202 {
203 ExitFunction1(hr = S_OK);
204 }
190 - ExitOnFailure(hr, "Failed to read registry value to detect UAC.");
205 + OsExitOnFailure(hr, "Failed to read registry value to detect UAC.");
206
207 *pfUacEnabled = (0 != dwUacEnabled);
208
@@ -215,12 +230,12 @@ HRESULT DAPI OsRtlGetVersion(
230 hr = LoadSystemLibrary(L"ntdll.dll", &hNtdll);
231 if (E_MODNOTFOUND == hr)
232 {
218 - ExitOnRootFailure(hr = E_NOTIMPL, "Failed to load ntdll.dll");
233 + OsExitOnRootFailure(hr = E_NOTIMPL, "Failed to load ntdll.dll");
234 }
220 - ExitOnFailure(hr, "Failed to load ntdll.dll.");
235 + OsExitOnFailure(hr, "Failed to load ntdll.dll.");
236
237 pfnRtlGetVersion = reinterpret_cast<PFN_RTL_GET_VERSION>(::GetProcAddress(hNtdll, "RtlGetVersion"));
223 - ExitOnNullWithLastError(pfnRtlGetVersion, hr, "Failed to locate RtlGetVersion.");
238 + OsExitOnNullWithLastError(pfnRtlGetVersion, hr, "Failed to locate RtlGetVersion.");
239
240 hr = static_cast<HRESULT>(pfnRtlGetVersion(&vovix));
241
src/dutil/path2utl.cpp
+18 -3
@@ -3,6 +3,21 @@
3 #include "precomp.h"
4
5
6 +// Exit macros
7 +#define PathExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__)
8 +#define PathExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__)
9 +#define PathExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__)
10 +#define PathExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__)
11 +#define PathExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__)
12 +#define PathExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__)
13 +#define PathExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_PATHUTIL, p, x, e, s, __VA_ARGS__)
14 +#define PathExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_PATHUTIL, p, x, s, __VA_ARGS__)
15 +#define PathExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_PATHUTIL, p, x, e, s, __VA_ARGS__)
16 +#define PathExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_PATHUTIL, p, x, s, __VA_ARGS__)
17 +#define PathExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_PATHUTIL, e, x, s, __VA_ARGS__)
18 +#define PathExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_PATHUTIL, g, x, s, __VA_ARGS__)
19 +
20 +
21 DAPI_(HRESULT) PathCanonicalizePath(
22 __in_z LPCWSTR wzPath,
23 __deref_out_z LPWSTR* psczCanonicalized
@@ -12,7 +27,7 @@ DAPI_(HRESULT) PathCanonicalizePath(
27 int cch = MAX_PATH + 1;
28
29 hr = StrAlloc(psczCanonicalized, cch);
15 - ExitOnFailure(hr, "Failed to allocate string for the canonicalized path.");
30 + PathExitOnFailure(hr, "Failed to allocate string for the canonicalized path.");
31
32 if (::PathCanonicalizeW(*psczCanonicalized, wzPath))
33 {
@@ -39,10 +54,10 @@ DAPI_(HRESULT) PathDirectoryContainsPath(
54 LPWSTR sczOriginalDirectory = NULL;
55
56 hr = PathCanonicalizePath(wzPath, &sczOriginalPath);
42 - ExitOnFailure(hr, "Failed to canonicalize the path.");
57 + PathExitOnFailure(hr, "Failed to canonicalize the path.");
58
59 hr = PathCanonicalizePath(wzDirectory, &sczOriginalDirectory);
45 - ExitOnFailure(hr, "Failed to canonicalize the directory.");
60 + PathExitOnFailure(hr, "Failed to canonicalize the directory.");
61
62 if (!sczOriginalPath || !*sczOriginalPath)
63 {
src/dutil/pathutil.cpp
+95 -80
@@ -2,11 +2,26 @@
2
3 #include "precomp.h"
4
5 +
6 +// Exit macros
7 +#define PathExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__)
8 +#define PathExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__)
9 +#define PathExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__)
10 +#define PathExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__)
11 +#define PathExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__)
12 +#define PathExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__)
13 +#define PathExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_PATHUTIL, p, x, e, s, __VA_ARGS__)
14 +#define PathExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_PATHUTIL, p, x, s, __VA_ARGS__)
15 +#define PathExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_PATHUTIL, p, x, e, s, __VA_ARGS__)
16 +#define PathExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_PATHUTIL, p, x, s, __VA_ARGS__)
17 +#define PathExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_PATHUTIL, e, x, s, __VA_ARGS__)
18 +#define PathExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_PATHUTIL, g, x, s, __VA_ARGS__)
19 +
20 #define PATH_GOOD_ENOUGH 64
21
22
23 DAPI_(HRESULT) PathCommandLineAppend(
9 - __deref_out_z LPWSTR* psczCommandLine,
24 + __deref_inout_z LPWSTR* psczCommandLine,
25 __in_z LPCWSTR wzArgument
26 )
27 {
@@ -41,7 +56,7 @@ DAPI_(HRESULT) PathCommandLineAppend(
56 if (fRequiresQuoting)
57 {
58 hr = StrAlloc(&sczQuotedArg, dwMaxEscapedSize + 3); // plus three for the start and end quote plus null terminator.
44 - ExitOnFailure(hr, "Failed to allocate argument to be quoted.");
59 + PathExitOnFailure(hr, "Failed to allocate argument to be quoted.");
60
61 LPCWSTR pwz = wzArgument;
62 LPWSTR pwzQuoted = sczQuotedArg;
@@ -94,11 +109,11 @@ DAPI_(HRESULT) PathCommandLineAppend(
109 if (*psczCommandLine && **psczCommandLine)
110 {
111 hr = StrAllocConcat(psczCommandLine, L" ", 0);
97 - ExitOnFailure(hr, "Failed to append space to command line with existing data.");
112 + PathExitOnFailure(hr, "Failed to append space to command line with existing data.");
113 }
114
115 hr = StrAllocConcat(psczCommandLine, sczQuotedArg ? sczQuotedArg : wzArgument, 0);
101 - ExitOnFailure(hr, "Failed to copy command line argument.");
116 + PathExitOnFailure(hr, "Failed to copy command line argument.");
117
118 LExit:
119 ReleaseStr(sczQuotedArg);
@@ -162,7 +177,7 @@ DAPI_(LPCWSTR) PathExtension(
177
178 DAPI_(HRESULT) PathGetDirectory(
179 __in_z LPCWSTR wzPath,
165 - __out LPWSTR *psczDirectory
180 + __out_z LPWSTR *psczDirectory
181 )
182 {
183 HRESULT hr = S_OK;
@@ -193,7 +208,7 @@ DAPI_(HRESULT) PathGetDirectory(
208 }
209
210 hr = StrAllocString(psczDirectory, wzPath, cchDirectory);
196 - ExitOnFailure(hr, "Failed to copy directory.");
211 + PathExitOnFailure(hr, "Failed to copy directory.");
212
213 LExit:
214 return hr;
@@ -223,28 +238,28 @@ DAPI_(HRESULT) PathExpand(
238 cchExpandedPath = PATH_GOOD_ENOUGH;
239
240 hr = StrAlloc(&sczExpandedPath, cchExpandedPath);
226 - ExitOnFailure(hr, "Failed to allocate space for expanded path.");
241 + PathExitOnFailure(hr, "Failed to allocate space for expanded path.");
242
243 cch = ::ExpandEnvironmentStringsW(wzRelativePath, sczExpandedPath, cchExpandedPath);
244 if (0 == cch)
245 {
231 - ExitWithLastError(hr, "Failed to expand environment variables in string: %ls", wzRelativePath);
246 + PathExitWithLastError(hr, "Failed to expand environment variables in string: %ls", wzRelativePath);
247 }
248 else if (cchExpandedPath < cch)
249 {
250 cchExpandedPath = cch;
251 hr = StrAlloc(&sczExpandedPath, cchExpandedPath);
237 - ExitOnFailure(hr, "Failed to re-allocate more space for expanded path.");
252 + PathExitOnFailure(hr, "Failed to re-allocate more space for expanded path.");
253
254 cch = ::ExpandEnvironmentStringsW(wzRelativePath, sczExpandedPath, cchExpandedPath);
255 if (0 == cch)
256 {
242 - ExitWithLastError(hr, "Failed to expand environment variables in string: %ls", wzRelativePath);
257 + PathExitWithLastError(hr, "Failed to expand environment variables in string: %ls", wzRelativePath);
258 }
259 else if (cchExpandedPath < cch)
260 {
261 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
247 - ExitOnRootFailure(hr, "Failed to allocate buffer for expanded path.");
262 + PathExitOnRootFailure(hr, "Failed to allocate buffer for expanded path.");
263 }
264 }
265
@@ -255,10 +270,10 @@ DAPI_(HRESULT) PathExpand(
270 {
271 hr = S_OK;
272 }
258 - ExitOnFailure(hr, "Failed to prefix long path after expanding environment variables.");
273 + PathExitOnFailure(hr, "Failed to prefix long path after expanding environment variables.");
274
275 hr = StrMaxLength(sczExpandedPath, reinterpret_cast<DWORD_PTR *>(&cchExpandedPath));
261 - ExitOnFailure(hr, "Failed to get max length of expanded path.");
276 + PathExitOnFailure(hr, "Failed to get max length of expanded path.");
277 }
278 }
279
@@ -272,35 +287,35 @@ DAPI_(HRESULT) PathExpand(
287 DWORD cchFullPath = PATH_GOOD_ENOUGH < cchExpandedPath ? cchExpandedPath : PATH_GOOD_ENOUGH;
288
289 hr = StrAlloc(&sczFullPath, cchFullPath);
275 - ExitOnFailure(hr, "Failed to allocate space for full path.");
290 + PathExitOnFailure(hr, "Failed to allocate space for full path.");
291
292 cch = ::GetFullPathNameW(wzPath, cchFullPath, sczFullPath, &wzFileName);
293 if (0 == cch)
294 {
280 - ExitWithLastError(hr, "Failed to get full path for string: %ls", wzPath);
295 + PathExitWithLastError(hr, "Failed to get full path for string: %ls", wzPath);
296 }
297 else if (cchFullPath < cch)
298 {
299 cchFullPath = cch < MAX_PATH ? cch : cch + 7; // ensure space for "\\?\UNC" prefix if needed
300 hr = StrAlloc(&sczFullPath, cchFullPath);
286 - ExitOnFailure(hr, "Failed to re-allocate more space for full path.");
301 + PathExitOnFailure(hr, "Failed to re-allocate more space for full path.");
302
303 cch = ::GetFullPathNameW(wzPath, cchFullPath, sczFullPath, &wzFileName);
304 if (0 == cch)
305 {
291 - ExitWithLastError(hr, "Failed to get full path for string: %ls", wzPath);
306 + PathExitWithLastError(hr, "Failed to get full path for string: %ls", wzPath);
307 }
308 else if (cchFullPath < cch)
309 {
310 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
296 - ExitOnRootFailure(hr, "Failed to allocate buffer for full path.");
311 + PathExitOnRootFailure(hr, "Failed to allocate buffer for full path.");
312 }
313 }
314
315 if (MAX_PATH < cch)
316 {
317 hr = PathPrefix(&sczFullPath);
303 - ExitOnFailure(hr, "Failed to prefix long path after expanding.");
318 + PathExitOnFailure(hr, "Failed to prefix long path after expanding.");
319 }
320 }
321 else
@@ -310,7 +325,7 @@ DAPI_(HRESULT) PathExpand(
325 }
326
327 hr = StrAllocString(psczFullPath, sczFullPath? sczFullPath : wzRelativePath, 0);
313 - ExitOnFailure(hr, "Failed to copy relative path into full path.");
328 + PathExitOnFailure(hr, "Failed to copy relative path into full path.");
329
330 LExit:
331 ReleaseStr(sczFullPath);
@@ -336,7 +351,7 @@ DAPI_(HRESULT) PathPrefix(
351 L'\\' == wzFullPath[2]) // normal path
352 {
353 hr = StrAllocPrefix(psczFullPath, L"\\\\?\\", 4);
339 - ExitOnFailure(hr, "Failed to add prefix to file path.");
354 + PathExitOnFailure(hr, "Failed to add prefix to file path.");
355 }
356 else if (L'\\' == wzFullPath[0] && L'\\' == wzFullPath[1]) // UNC
357 {
@@ -344,18 +359,18 @@ DAPI_(HRESULT) PathPrefix(
359 if (!(L'?' == wzFullPath[2] && L'\\' == wzFullPath[3]))
360 {
361 hr = StrSize(*psczFullPath, &cbFullPath);
347 - ExitOnFailure(hr, "Failed to get size of full path.");
362 + PathExitOnFailure(hr, "Failed to get size of full path.");
363
364 memmove_s(wzFullPath, cbFullPath, wzFullPath + 1, cbFullPath - sizeof(WCHAR));
365
366 hr = StrAllocPrefix(psczFullPath, L"\\\\?\\UNC", 7);
352 - ExitOnFailure(hr, "Failed to add prefix to UNC path.");
367 + PathExitOnFailure(hr, "Failed to add prefix to UNC path.");
368 }
369 }
370 else
371 {
372 hr = E_INVALIDARG;
358 - ExitOnFailure(hr, "Invalid path provided to prefix: %ls.", wzFullPath);
373 + PathExitOnFailure(hr, "Invalid path provided to prefix: %ls.", wzFullPath);
374 }
375
376 LExit:
@@ -372,7 +387,7 @@ DAPI_(HRESULT) PathFixedBackslashTerminate(
387 size_t cchLength = 0;
388
389 hr = ::StringCchLengthW(wzPath, cchPath, &cchLength);
375 - ExitOnFailure(hr, "Failed to get length of path.");
390 + PathExitOnFailure(hr, "Failed to get length of path.");
391
392 if (cchLength >= cchPath)
393 {
@@ -400,15 +415,15 @@ DAPI_(HRESULT) PathBackslashTerminate(
415 size_t cchLength = 0;
416
417 hr = StrMaxLength(*psczPath, &cchPath);
403 - ExitOnFailure(hr, "Failed to get size of path string.");
418 + PathExitOnFailure(hr, "Failed to get size of path string.");
419
420 hr = ::StringCchLengthW(*psczPath, cchPath, &cchLength);
406 - ExitOnFailure(hr, "Failed to get length of path.");
421 + PathExitOnFailure(hr, "Failed to get length of path.");
422
423 if (L'\\' != (*psczPath)[cchLength - 1])
424 {
425 hr = StrAllocConcat(psczPath, L"\\", 1);
411 - ExitOnFailure(hr, "Failed to concat backslash onto string.");
426 + PathExitOnFailure(hr, "Failed to concat backslash onto string.");
427 }
428
429 LExit:
@@ -427,12 +442,12 @@ DAPI_(HRESULT) PathForCurrentProcess(
442 do
443 {
444 hr = StrAlloc(psczFullPath, cch);
430 - ExitOnFailure(hr, "Failed to allocate string for module path.");
445 + PathExitOnFailure(hr, "Failed to allocate string for module path.");
446
447 DWORD cchRequired = ::GetModuleFileNameW(hModule, *psczFullPath, cch);
448 if (0 == cchRequired)
449 {
435 - ExitWithLastError(hr, "Failed to get path for executing process.");
450 + PathExitWithLastError(hr, "Failed to get path for executing process.");
451 }
452 else if (cchRequired == cch)
453 {
@@ -457,15 +472,15 @@ DAPI_(HRESULT) PathRelativeToModule(
472 )
473 {
474 HRESULT hr = PathForCurrentProcess(psczFullPath, hModule);
460 - ExitOnFailure(hr, "Failed to get current module path.");
475 + PathExitOnFailure(hr, "Failed to get current module path.");
476
477 hr = PathGetDirectory(*psczFullPath, psczFullPath);
463 - ExitOnFailure(hr, "Failed to get current module directory.");
478 + PathExitOnFailure(hr, "Failed to get current module directory.");
479
480 if (wzFileName)
481 {
482 hr = PathConcat(*psczFullPath, wzFileName, psczFullPath);
468 - ExitOnFailure(hr, "Failed to append filename.");
483 + PathExitOnFailure(hr, "Failed to append filename.");
484 }
485
486 LExit:
@@ -496,16 +511,16 @@ DAPI_(HRESULT) PathCreateTempFile(
511 if (wzDirectory && *wzDirectory)
512 {
513 hr = StrAllocString(&sczTempPath, wzDirectory, 0);
499 - ExitOnFailure(hr, "Failed to copy temp path.");
514 + PathExitOnFailure(hr, "Failed to copy temp path.");
515 }
516 else
517 {
518 hr = StrAlloc(&sczTempPath, cchTempPath);
504 - ExitOnFailure(hr, "Failed to allocate memory for the temp path.");
519 + PathExitOnFailure(hr, "Failed to allocate memory for the temp path.");
520
521 if (!::GetTempPathW(cchTempPath, sczTempPath))
522 {
508 - ExitWithLastError(hr, "Failed to get temp path.");
523 + PathExitWithLastError(hr, "Failed to get temp path.");
524 }
525 }
526
@@ -514,10 +529,10 @@ DAPI_(HRESULT) PathCreateTempFile(
529 for (DWORD i = 1; i <= dwUniqueCount && INVALID_HANDLE_VALUE == hTempFile; ++i)
530 {
531 hr = StrAllocFormatted(&scz, wzFileNameTemplate, i);
517 - ExitOnFailure(hr, "Failed to allocate memory for file template.");
532 + PathExitOnFailure(hr, "Failed to allocate memory for file template.");
533
534 hr = StrAllocFormatted(&sczTempFile, L"%s%s", sczTempPath, scz);
520 - ExitOnFailure(hr, "Failed to allocate temp file name.");
535 + PathExitOnFailure(hr, "Failed to allocate temp file name.");
536
537 hTempFile = ::CreateFileW(sczTempFile, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, CREATE_NEW, dwFileAttributes, NULL);
538 if (INVALID_HANDLE_VALUE == hTempFile)
@@ -528,7 +543,7 @@ DAPI_(HRESULT) PathCreateTempFile(
543 {
544 hr = S_OK;
545 }
531 - ExitOnFailure(hr, "Failed to create file: %ls", sczTempFile);
546 + PathExitOnFailure(hr, "Failed to create file: %ls", sczTempFile);
547 }
548 }
549 }
@@ -538,17 +553,17 @@ DAPI_(HRESULT) PathCreateTempFile(
553 if (INVALID_HANDLE_VALUE == hTempFile)
554 {
555 hr = StrAlloc(&sczTempFile, MAX_PATH);
541 - ExitOnFailure(hr, "Failed to allocate memory for the temp path");
556 + PathExitOnFailure(hr, "Failed to allocate memory for the temp path");
557
558 if (!::GetTempFileNameW(sczTempPath, L"TMP", 0, sczTempFile))
559 {
545 - ExitWithLastError(hr, "Failed to create new temp file name.");
560 + PathExitWithLastError(hr, "Failed to create new temp file name.");
561 }
562
563 hTempFile = ::CreateFileW(sczTempFile, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, dwFileAttributes, NULL);
564 if (INVALID_HANDLE_VALUE == hTempFile)
565 {
551 - ExitWithLastError(hr, "Failed to open new temp file: %ls", sczTempFile);
566 + PathExitWithLastError(hr, "Failed to open new temp file: %ls", sczTempFile);
567 }
568 }
569
@@ -556,7 +571,7 @@ DAPI_(HRESULT) PathCreateTempFile(
571 if (psczTempFile)
572 {
573 hr = StrAllocString(psczTempFile, sczTempFile, 0);
559 - ExitOnFailure(hr, "Failed to copy temp file string.");
574 + PathExitOnFailure(hr, "Failed to copy temp file string.");
575 }
576
577 if (phTempFile)
@@ -602,24 +617,24 @@ DAPI_(HRESULT) PathCreateTimeBasedTempFile(
617 if (wzDirectory && *wzDirectory)
618 {
619 hr = PathConcat(wzDirectory, wzPrefix, &sczPrefix);
605 - ExitOnFailure(hr, "Failed to combine directory and log prefix.");
620 + PathExitOnFailure(hr, "Failed to combine directory and log prefix.");
621 }
622 else
623 {
624 if (!::GetTempPathW(countof(wzTempPath), wzTempPath))
625 {
611 - ExitWithLastError(hr, "Failed to get temp folder.");
626 + PathExitWithLastError(hr, "Failed to get temp folder.");
627 }
628
629 hr = PathConcat(wzTempPath, wzPrefix, &sczPrefix);
615 - ExitOnFailure(hr, "Failed to concatenate the temp folder and log prefix.");
630 + PathExitOnFailure(hr, "Failed to concatenate the temp folder and log prefix.");
631 }
632
633 hr = PathGetDirectory(sczPrefix, &sczPrefixFolder);
634 if (S_OK == hr)
635 {
636 hr = DirEnsureExists(sczPrefixFolder, NULL);
622 - ExitOnFailure(hr, "Failed to ensure temp file path exists: %ls", sczPrefixFolder);
637 + PathExitOnFailure(hr, "Failed to ensure temp file path exists: %ls", sczPrefixFolder);
638 }
639
640 if (!wzPostfix)
@@ -636,7 +651,7 @@ DAPI_(HRESULT) PathCreateTimeBasedTempFile(
651
652 // Log format: pre YYYY MM dd hh mm ss post ext
653 hr = StrAllocFormatted(&sczTempPath, L"%ls_%04u%02u%02u%02u%02u%02u%ls%ls%ls", sczPrefix, time.wYear, time.wMonth, time.wDay, time.wHour, time.wMinute, time.wSecond, wzPostfix, L'.' == *wzExtension ? L"" : L".", wzExtension);
639 - ExitOnFailure(hr, "failed to allocate memory for the temp path");
654 + PathExitOnFailure(hr, "failed to allocate memory for the temp path");
655
656 hTempFile = ::CreateFileW(sczTempPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
657 if (INVALID_HANDLE_VALUE == hTempFile)
@@ -655,14 +670,14 @@ DAPI_(HRESULT) PathCreateTimeBasedTempFile(
670 }
671
672 hr = HRESULT_FROM_WIN32(er);
658 - ExitOnFailureDebugTrace(hr, "Failed to create temp file: %ls", sczTempPath);
673 + PathExitOnFailureDebugTrace(hr, "Failed to create temp file: %ls", sczTempPath);
674 }
675 } while (fRetry);
676
677 if (psczTempFile)
678 {
679 hr = StrAllocString(psczTempFile, sczTempPath, 0);
665 - ExitOnFailure(hr, "Failed to copy temp path to return.");
680 + PathExitOnFailure(hr, "Failed to copy temp path to return.");
681 }
682
683 if (phTempFile)
@@ -701,29 +716,29 @@ DAPI_(HRESULT) PathCreateTempDirectory(
716 if (wzDirectory && *wzDirectory)
717 {
718 hr = StrAllocString(&sczTempPath, wzDirectory, 0);
704 - ExitOnFailure(hr, "Failed to copy temp path.");
719 + PathExitOnFailure(hr, "Failed to copy temp path.");
720
721 hr = PathBackslashTerminate(&sczTempPath);
707 - ExitOnFailure(hr, "Failed to ensure path ends in backslash: %ls", wzDirectory);
722 + PathExitOnFailure(hr, "Failed to ensure path ends in backslash: %ls", wzDirectory);
723 }
724 else
725 {
726 hr = StrAlloc(&sczTempPath, cchTempPath);
712 - ExitOnFailure(hr, "Failed to allocate memory for the temp path.");
727 + PathExitOnFailure(hr, "Failed to allocate memory for the temp path.");
728
729 if (!::GetTempPathW(cchTempPath, sczTempPath))
730 {
716 - ExitWithLastError(hr, "Failed to get temp path.");
731 + PathExitWithLastError(hr, "Failed to get temp path.");
732 }
733 }
734
735 for (DWORD i = 1; i <= dwUniqueCount; ++i)
736 {
737 hr = StrAllocFormatted(&scz, wzDirectoryNameTemplate, i);
723 - ExitOnFailure(hr, "Failed to allocate memory for directory name template.");
738 + PathExitOnFailure(hr, "Failed to allocate memory for directory name template.");
739
740 hr = StrAllocFormatted(psczTempDirectory, L"%s%s", sczTempPath, scz);
726 - ExitOnFailure(hr, "Failed to allocate temp directory name.");
741 + PathExitOnFailure(hr, "Failed to allocate temp directory name.");
742
743 if (!::CreateDirectoryW(*psczTempDirectory, NULL))
744 {
@@ -750,10 +765,10 @@ DAPI_(HRESULT) PathCreateTempDirectory(
765 break;
766 }
767 }
753 - ExitOnFailure(hr, "Failed to create temp directory.");
768 + PathExitOnFailure(hr, "Failed to create temp directory.");
769
770 hr = PathBackslashTerminate(psczTempDirectory);
756 - ExitOnFailure(hr, "Failed to ensure temp directory is backslash terminated.");
771 + PathExitOnFailure(hr, "Failed to ensure temp directory is backslash terminated.");
772
773 LExit:
774 ReleaseStr(scz);
@@ -771,13 +786,13 @@ DAPI_(HRESULT) PathGetKnownFolder(
786 HRESULT hr = S_OK;
787
788 hr = StrAlloc(psczKnownFolder, MAX_PATH);
774 - ExitOnFailure(hr, "Failed to allocate memory for known folder.");
789 + PathExitOnFailure(hr, "Failed to allocate memory for known folder.");
790
791 hr = ::SHGetFolderPathW(NULL, csidl, NULL, SHGFP_TYPE_CURRENT, *psczKnownFolder);
777 - ExitOnFailure(hr, "Failed to get known folder path.");
792 + PathExitOnFailure(hr, "Failed to get known folder path.");
793
794 hr = PathBackslashTerminate(psczKnownFolder);
780 - ExitOnFailure(hr, "Failed to ensure known folder path is backslash terminated.");
795 + PathExitOnFailure(hr, "Failed to ensure known folder path is backslash terminated.");
796
797 LExit:
798 return hr;
@@ -804,23 +819,23 @@ DAPI_(HRESULT) PathConcat(
819 if (!wzPath2 || !*wzPath2)
820 {
821 hr = StrAllocString(psczCombined, wzPath1, 0);
807 - ExitOnFailure(hr, "Failed to copy just path1 to output.");
822 + PathExitOnFailure(hr, "Failed to copy just path1 to output.");
823 }
824 else if (!wzPath1 || !*wzPath1 || PathIsAbsolute(wzPath2))
825 {
826 hr = StrAllocString(psczCombined, wzPath2, 0);
812 - ExitOnFailure(hr, "Failed to copy just path2 to output.");
827 + PathExitOnFailure(hr, "Failed to copy just path2 to output.");
828 }
829 else
830 {
831 hr = StrAllocString(psczCombined, wzPath1, 0);
817 - ExitOnFailure(hr, "Failed to copy path1 to output.");
832 + PathExitOnFailure(hr, "Failed to copy path1 to output.");
833
834 hr = PathBackslashTerminate(psczCombined);
820 - ExitOnFailure(hr, "Failed to backslashify.");
835 + PathExitOnFailure(hr, "Failed to backslashify.");
836
837 hr = StrAllocConcat(psczCombined, wzPath2, 0);
823 - ExitOnFailure(hr, "Failed to append path2 to output.");
838 + PathExitOnFailure(hr, "Failed to append path2 to output.");
839 }
840
841 LExit:
@@ -839,13 +854,13 @@ DAPI_(HRESULT) PathEnsureQuoted(
854 size_t cchPath = 0;
855
856 hr = ::StringCchLengthW(*ppszPath, STRSAFE_MAX_CCH, &cchPath);
842 - ExitOnFailure(hr, "Failed to get the length of the path.");
857 + PathExitOnFailure(hr, "Failed to get the length of the path.");
858
859 // Handle simple special cases.
860 if (0 == cchPath || (1 == cchPath && L'"' == (*ppszPath)[0]))
861 {
862 hr = StrAllocString(ppszPath, L"\"\"", 2);
848 - ExitOnFailure(hr, "Failed to allocate a quoted empty string.");
863 + PathExitOnFailure(hr, "Failed to allocate a quoted empty string.");
864
865 ExitFunction();
866 }
@@ -853,7 +868,7 @@ DAPI_(HRESULT) PathEnsureQuoted(
868 if (L'"' != (*ppszPath)[0])
869 {
870 hr = StrAllocPrefix(ppszPath, L"\"", 1);
856 - ExitOnFailure(hr, "Failed to allocate an opening quote.");
871 + PathExitOnFailure(hr, "Failed to allocate an opening quote.");
872
873 // Add a char for the opening quote.
874 ++cchPath;
@@ -862,7 +877,7 @@ DAPI_(HRESULT) PathEnsureQuoted(
877 if (L'"' != (*ppszPath)[cchPath - 1])
878 {
879 hr = StrAllocConcat(ppszPath, L"\"", 1);
865 - ExitOnFailure(hr, "Failed to allocate a closing quote.");
880 + PathExitOnFailure(hr, "Failed to allocate a closing quote.");
881
882 // Add a char for the closing quote.
883 ++cchPath;
@@ -876,7 +891,7 @@ DAPI_(HRESULT) PathEnsureQuoted(
891 (*ppszPath)[cchPath - 1] = L'\\';
892
893 hr = StrAllocConcat(ppszPath, L"\"", 1);
879 - ExitOnFailure(hr, "Failed to allocate another closing quote after the backslash.");
894 + PathExitOnFailure(hr, "Failed to allocate another closing quote after the backslash.");
895 }
896 }
897
@@ -897,10 +912,10 @@ DAPI_(HRESULT) PathCompare(
912 LPWSTR sczPath2 = NULL;
913
914 hr = PathExpand(&sczPath1, wzPath1, PATH_EXPAND_ENVIRONMENT | PATH_EXPAND_FULLPATH);
900 - ExitOnFailure(hr, "Failed to expand path1.");
915 + PathExitOnFailure(hr, "Failed to expand path1.");
916
917 hr = PathExpand(&sczPath2, wzPath2, PATH_EXPAND_ENVIRONMENT | PATH_EXPAND_FULLPATH);
903 - ExitOnFailure(hr, "Failed to expand path2.");
918 + PathExitOnFailure(hr, "Failed to expand path2.");
919
920 *pnResult = ::CompareStringW(LOCALE_NEUTRAL, NORM_IGNORECASE, sczPath1, -1, sczPath2, -1);
921
@@ -922,7 +937,7 @@ DAPI_(HRESULT) PathCompress(
937 hPath = ::CreateFileW(wzPath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
938 if (INVALID_HANDLE_VALUE == hPath)
939 {
925 - ExitWithLastError(hr, "Failed to open path %ls for compression.", wzPath);
940 + PathExitWithLastError(hr, "Failed to open path %ls for compression.", wzPath);
941 }
942
943 DWORD dwBytesReturned = 0;
@@ -933,7 +948,7 @@ DAPI_(HRESULT) PathCompress(
948 DWORD er = ::GetLastError();
949 if (ERROR_INVALID_FUNCTION != er)
950 {
936 - ExitOnWin32Error(er, hr, "Failed to set compression state for path %ls.", wzPath);
951 + PathExitOnWin32Error(er, hr, "Failed to set compression state for path %ls.", wzPath);
952 }
953 }
954
@@ -945,7 +960,7 @@ LExit:
960
961 DAPI_(HRESULT) PathGetHierarchyArray(
962 __in_z LPCWSTR wzPath,
948 - __deref_inout_ecount_opt(*pcStrArray) LPWSTR **prgsczPathArray,
963 + __deref_inout_ecount_opt(*pcPathArray) LPWSTR **prgsczPathArray,
964 __inout LPUINT pcPathArray
965 )
966 {
@@ -975,16 +990,16 @@ DAPI_(HRESULT) PathGetHierarchyArray(
990 Assert(cArraySpacesNeeded >= 1);
991
992 hr = MemEnsureArraySize(reinterpret_cast<void **>(prgsczPathArray), cArraySpacesNeeded, sizeof(LPWSTR), 0);
978 - ExitOnFailure(hr, "Failed to allocate array of size %u for parent directories", cArraySpacesNeeded);
993 + PathExitOnFailure(hr, "Failed to allocate array of size %u for parent directories", cArraySpacesNeeded);
994 *pcPathArray = cArraySpacesNeeded;
995
996 hr = StrAllocString(&sczPathCopy, wzPath, 0);
982 - ExitOnFailure(hr, "Failed to allocate copy of original path");
997 + PathExitOnFailure(hr, "Failed to allocate copy of original path");
998
999 for (DWORD i = 0; i < cArraySpacesNeeded; ++i)
1000 {
1001 hr = StrAllocString((*prgsczPathArray) + cArraySpacesNeeded - 1 - i, sczPathCopy, 0);
987 - ExitOnFailure(hr, "Failed to copy path");
1002 + PathExitOnFailure(hr, "Failed to copy path");
1003
1004 // If it ends in a backslash, it's a directory path, so cut off everything the last backslash before we get the directory portion of the path
1005 if (wzPath[lstrlenW(sczPathCopy) - 1] == L'\\')
@@ -993,7 +1008,7 @@ DAPI_(HRESULT) PathGetHierarchyArray(
1008 }
1009
1010 hr = PathGetDirectory(sczPathCopy, &sczNewPathCopy);
996 - ExitOnFailure(hr, "Failed to get directory portion of path");
1011 + PathExitOnFailure(hr, "Failed to get directory portion of path");
1012
1013 ReleaseStr(sczPathCopy);
1014 sczPathCopy = sczNewPathCopy;
src/dutil/perfutil.cpp
+15
@@ -2,6 +2,21 @@
2
3 #include "precomp.h"
4
5 +
6 +// Exit macros
7 +#define PerfExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_PERFUTIL, x, s, __VA_ARGS__)
8 +#define PerfExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_PERFUTIL, x, s, __VA_ARGS__)
9 +#define PerfExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_PERFUTIL, x, s, __VA_ARGS__)
10 +#define PerfExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_PERFUTIL, x, s, __VA_ARGS__)
11 +#define PerfExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_PERFUTIL, x, s, __VA_ARGS__)
12 +#define PerfExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_PERFUTIL, x, s, __VA_ARGS__)
13 +#define PerfExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_PERFUTIL, p, x, e, s, __VA_ARGS__)
14 +#define PerfExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_PERFUTIL, p, x, s, __VA_ARGS__)
15 +#define PerfExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_PERFUTIL, p, x, e, s, __VA_ARGS__)
16 +#define PerfExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_PERFUTIL, p, x, s, __VA_ARGS__)
17 +#define PerfExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_PERFUTIL, e, x, s, __VA_ARGS__)
18 +#define PerfExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_PERFUTIL, g, x, s, __VA_ARGS__)
19 +
20 static BOOL vfHighPerformanceCounter = TRUE; // assume the system has a high performance counter
21 static double vdFrequency = 1;
22
src/dutil/polcutil.cpp
+21 -6
@@ -2,6 +2,21 @@
2
3 #include "precomp.h"
4
5 +
6 +// Exit macros
7 +#define PolcExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_POLCUTIL, x, s, __VA_ARGS__)
8 +#define PolcExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_POLCUTIL, x, s, __VA_ARGS__)
9 +#define PolcExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_POLCUTIL, x, s, __VA_ARGS__)
10 +#define PolcExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_POLCUTIL, x, s, __VA_ARGS__)
11 +#define PolcExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_POLCUTIL, x, s, __VA_ARGS__)
12 +#define PolcExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_POLCUTIL, x, s, __VA_ARGS__)
13 +#define PolcExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_POLCUTIL, p, x, e, s, __VA_ARGS__)
14 +#define PolcExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_POLCUTIL, p, x, s, __VA_ARGS__)
15 +#define PolcExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_POLCUTIL, p, x, e, s, __VA_ARGS__)
16 +#define PolcExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_POLCUTIL, p, x, s, __VA_ARGS__)
17 +#define PolcExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_POLCUTIL, e, x, s, __VA_ARGS__)
18 +#define PolcExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_POLCUTIL, g, x, s, __VA_ARGS__)
19 +
20 const LPCWSTR REGISTRY_POLICIES_KEY = L"SOFTWARE\\Policies\\";
21
22 static HRESULT OpenPolicyKey(
@@ -25,14 +40,14 @@ extern "C" HRESULT DAPI PolcReadNumber(
40 {
41 ExitFunction1(hr = S_FALSE);
42 }
28 - ExitOnFailure(hr, "Failed to open policy key: %ls", wzPolicyPath);
43 + PolcExitOnFailure(hr, "Failed to open policy key: %ls", wzPolicyPath);
44
45 hr = RegReadNumber(hk, wzPolicyName, pdw);
46 if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr)
47 {
48 ExitFunction1(hr = S_FALSE);
49 }
35 - ExitOnFailure(hr, "Failed to open policy key: %ls, name: %ls", wzPolicyPath, wzPolicyName);
50 + PolcExitOnFailure(hr, "Failed to open policy key: %ls, name: %ls", wzPolicyPath, wzPolicyName);
51
52 LExit:
53 ReleaseRegKey(hk);
@@ -60,14 +75,14 @@ extern "C" HRESULT DAPI PolcReadString(
75 {
76 ExitFunction1(hr = S_FALSE);
77 }
63 - ExitOnFailure(hr, "Failed to open policy key: %ls", wzPolicyPath);
78 + PolcExitOnFailure(hr, "Failed to open policy key: %ls", wzPolicyPath);
79
80 hr = RegReadString(hk, wzPolicyName, pscz);
81 if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr)
82 {
83 ExitFunction1(hr = S_FALSE);
84 }
70 - ExitOnFailure(hr, "Failed to open policy key: %ls, name: %ls", wzPolicyPath, wzPolicyName);
85 + PolcExitOnFailure(hr, "Failed to open policy key: %ls, name: %ls", wzPolicyPath, wzPolicyName);
86
87 LExit:
88 ReleaseRegKey(hk);
@@ -99,10 +114,10 @@ static HRESULT OpenPolicyKey(
114 LPWSTR sczPath = NULL;
115
116 hr = PathConcat(REGISTRY_POLICIES_KEY, wzPolicyPath, &sczPath);
102 - ExitOnFailure(hr, "Failed to combine logging path with root path.");
117 + PolcExitOnFailure(hr, "Failed to combine logging path with root path.");
118
119 hr = RegOpen(HKEY_LOCAL_MACHINE, sczPath, KEY_READ, phk);
105 - ExitOnFailure(hr, "Failed to open policy registry key.");
120 + PolcExitOnFailure(hr, "Failed to open policy registry key.");
121
122 LExit:
123 ReleaseStr(sczPath);
src/dutil/proc2utl.cpp
+18 -3
@@ -2,6 +2,21 @@
2
3 #include "precomp.h"
4
5 +
6 +// Exit macros
7 +#define ProcExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__)
8 +#define ProcExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__)
9 +#define ProcExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__)
10 +#define ProcExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__)
11 +#define ProcExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__)
12 +#define ProcExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__)
13 +#define ProcExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_PROCUTIL, p, x, e, s, __VA_ARGS__)
14 +#define ProcExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_PROCUTIL, p, x, s, __VA_ARGS__)
15 +#define ProcExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_PROCUTIL, p, x, e, s, __VA_ARGS__)
16 +#define ProcExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_PROCUTIL, p, x, s, __VA_ARGS__)
17 +#define ProcExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_PROCUTIL, e, x, s, __VA_ARGS__)
18 +#define ProcExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_PROCUTIL, g, x, s, __VA_ARGS__)
19 +
20 /********************************************************************
21 ProcFindAllIdsFromExeName() - returns an array of process ids that are running specified executable.
22
@@ -21,7 +36,7 @@ extern "C" HRESULT DAPI ProcFindAllIdsFromExeName(
36 hSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
37 if (INVALID_HANDLE_VALUE == hSnap)
38 {
24 - ExitWithLastError(hr, "Failed to create snapshot of processes on system");
39 + ProcExitWithLastError(hr, "Failed to create snapshot of processes on system");
40 }
41
42 fContinue = ::Process32FirstW(hSnap, &peData);
@@ -33,13 +48,13 @@ extern "C" HRESULT DAPI ProcFindAllIdsFromExeName(
48 if (!*ppdwProcessIds)
49 {
50 *ppdwProcessIds = static_cast<DWORD*>(MemAlloc(sizeof(DWORD), TRUE));
36 - ExitOnNull(ppdwProcessIds, hr, E_OUTOFMEMORY, "Failed to allocate array for returned process IDs.");
51 + ProcExitOnNull(ppdwProcessIds, hr, E_OUTOFMEMORY, "Failed to allocate array for returned process IDs.");
52 }
53 else
54 {
55 DWORD* pdwReAllocReturnedPids = NULL;
56 pdwReAllocReturnedPids = static_cast<DWORD*>(MemReAlloc(*ppdwProcessIds, sizeof(DWORD) * ((*pcProcessIds) + 1), TRUE));
42 - ExitOnNull(pdwReAllocReturnedPids, hr, E_OUTOFMEMORY, "Failed to re-allocate array for returned process IDs.");
57 + ProcExitOnNull(pdwReAllocReturnedPids, hr, E_OUTOFMEMORY, "Failed to re-allocate array for returned process IDs.");
58
59 *ppdwProcessIds = pdwReAllocReturnedPids;
60 }
src/dutil/proc3utl.cpp
+21 -6
@@ -2,6 +2,21 @@
2
3 #include "precomp.h"
4
5 +
6 +// Exit macros
7 +#define ProcExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__)
8 +#define ProcExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__)
9 +#define ProcExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__)
10 +#define ProcExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__)
11 +#define ProcExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__)
12 +#define ProcExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__)
13 +#define ProcExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_PROCUTIL, p, x, e, s, __VA_ARGS__)
14 +#define ProcExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_PROCUTIL, p, x, s, __VA_ARGS__)
15 +#define ProcExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_PROCUTIL, p, x, e, s, __VA_ARGS__)
16 +#define ProcExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_PROCUTIL, p, x, s, __VA_ARGS__)
17 +#define ProcExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_PROCUTIL, e, x, s, __VA_ARGS__)
18 +#define ProcExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_PROCUTIL, g, x, s, __VA_ARGS__)
19 +
20 static HRESULT GetActiveSessionUserToken(
21 __out HANDLE *phToken
22 );
@@ -25,20 +40,20 @@ extern "C" HRESULT DAPI ProcExecuteAsInteractiveUser(
40 PROCESS_INFORMATION pi = { };
41
42 hr = GetActiveSessionUserToken(&hToken);
28 - ExitOnFailure(hr, "Failed to get active session user token.");
43 + ProcExitOnFailure(hr, "Failed to get active session user token.");
44
45 if (!::CreateEnvironmentBlock(&pEnvironment, hToken, FALSE))
46 {
32 - ExitWithLastError(hr, "Failed to create environment block for UI process.");
47 + ProcExitWithLastError(hr, "Failed to create environment block for UI process.");
48 }
49
50 hr = StrAllocFormatted(&sczFullCommandLine, L"\"%ls\" %ls", wzExecutablePath, wzCommandLine);
36 - ExitOnFailure(hr, "Failed to allocate full command-line.");
51 + ProcExitOnFailure(hr, "Failed to allocate full command-line.");
52
53 si.cb = sizeof(si);
54 if (!::CreateProcessAsUserW(hToken, wzExecutablePath, sczFullCommandLine, NULL, NULL, FALSE, CREATE_UNICODE_ENVIRONMENT, pEnvironment, NULL, &si, &pi))
55 {
41 - ExitWithLastError(hr, "Failed to create UI process: %ls", sczFullCommandLine);
56 + ProcExitWithLastError(hr, "Failed to create UI process: %ls", sczFullCommandLine);
57 }
58
59 *phProcess = pi.hProcess;
@@ -74,7 +89,7 @@ static HRESULT GetActiveSessionUserToken(
89 // Loop through the sessions looking for the active one.
90 if (!::WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1, &pSessionInfo, &cSessions))
91 {
77 - ExitWithLastError(hr, "Failed to enumerate sessions.");
92 + ProcExitWithLastError(hr, "Failed to enumerate sessions.");
93 }
94
95 for (DWORD i = 0; i < cSessions; ++i)
@@ -96,7 +111,7 @@ static HRESULT GetActiveSessionUserToken(
111 // Get the user token from the active session.
112 if (!::WTSQueryUserToken(dwSessionId, &hToken))
113 {
99 - ExitWithLastError(hr, "Failed to get active session user token.");
114 + ProcExitWithLastError(hr, "Failed to get active session user token.");
115 }
116
117 *phToken = hToken;
src/dutil/procutil.cpp
+36 -21
@@ -3,6 +3,21 @@
3 #include "precomp.h"
4
5
6 +// Exit macros
7 +#define ProcExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__)
8 +#define ProcExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__)
9 +#define ProcExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__)
10 +#define ProcExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__)
11 +#define ProcExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__)
12 +#define ProcExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__)
13 +#define ProcExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_PROCUTIL, p, x, e, s, __VA_ARGS__)
14 +#define ProcExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_PROCUTIL, p, x, s, __VA_ARGS__)
15 +#define ProcExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_PROCUTIL, p, x, e, s, __VA_ARGS__)
16 +#define ProcExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_PROCUTIL, p, x, s, __VA_ARGS__)
17 +#define ProcExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_PROCUTIL, e, x, s, __VA_ARGS__)
18 +#define ProcExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_PROCUTIL, g, x, s, __VA_ARGS__)
19 +
20 +
21 // private functions
22 static HRESULT CreatePipes(
23 __out HANDLE *phOutRead,
@@ -30,7 +45,7 @@ extern "C" HRESULT DAPI ProcElevated(
45
46 if (!::OpenProcessToken(hProcess, TOKEN_QUERY, &hToken))
47 {
33 - ExitWithLastError(hr, "Failed to open process token.");
48 + ProcExitWithLastError(hr, "Failed to open process token.");
49 }
50
51 if (::GetTokenInformation(hToken, TokenElevation, &tokenElevated, sizeof(TOKEN_ELEVATION), &cbToken))
@@ -50,7 +65,7 @@ extern "C" HRESULT DAPI ProcElevated(
65 }
66 else
67 {
53 - ExitOnRootFailure(hr, "Failed to get elevation token from process.");
68 + ProcExitOnRootFailure(hr, "Failed to get elevation token from process.");
69 }
70 }
71
@@ -76,7 +91,7 @@ extern "C" HRESULT DAPI ProcWow64(
91 USHORT pProcessMachine = IMAGE_FILE_MACHINE_UNKNOWN;
92 if (!pfnIsWow64Process2(hProcess, &pProcessMachine, nullptr))
93 {
79 - ExitWithLastError(hr, "Failed to check WOW64 process - IsWow64Process2.");
94 + ProcExitWithLastError(hr, "Failed to check WOW64 process - IsWow64Process2.");
95 }
96
97 if (pProcessMachine != IMAGE_FILE_MACHINE_UNKNOWN)
@@ -93,7 +108,7 @@ extern "C" HRESULT DAPI ProcWow64(
108 {
109 if (!pfnIsWow64Process(hProcess, &fIsWow64))
110 {
96 - ExitWithLastError(hr, "Failed to check WOW64 process - IsWow64Process.");
111 + ProcExitWithLastError(hr, "Failed to check WOW64 process - IsWow64Process.");
112 }
113 }
114 }
@@ -121,7 +136,7 @@ extern "C" HRESULT DAPI ProcDisableWowFileSystemRedirection(
136
137 if (!pfnWow64DisableWow64FsRedirection(&pfsr->pvRevertState))
138 {
124 - ExitWithLastError(hr, "Failed to disable file system redirection.");
139 + ProcExitWithLastError(hr, "Failed to disable file system redirection.");
140 }
141
142 pfsr->fDisabled = TRUE;
@@ -143,7 +158,7 @@ extern "C" HRESULT DAPI ProcRevertWowFileSystemRedirection(
158
159 if (!pfnWow64RevertWow64FsRedirection(pfsr->pvRevertState))
160 {
146 - ExitWithLastError(hr, "Failed to revert file system redirection.");
161 + ProcExitWithLastError(hr, "Failed to revert file system redirection.");
162 }
163
164 pfsr->fDisabled = FALSE;
@@ -168,13 +183,13 @@ extern "C" HRESULT DAPI ProcExec(
183 PROCESS_INFORMATION pi = { };
184
185 hr = StrAllocFormatted(&sczFullCommandLine, L"\"%ls\" %ls", wzExecutablePath, wzCommandLine ? wzCommandLine : L"");
171 - ExitOnFailure(hr, "Failed to allocate full command-line.");
186 + ProcExitOnFailure(hr, "Failed to allocate full command-line.");
187
188 si.cb = sizeof(si);
189 si.wShowWindow = static_cast<WORD>(nCmdShow);
190 if (!::CreateProcessW(wzExecutablePath, sczFullCommandLine, NULL, NULL, FALSE, 0, 0, NULL, &si, &pi))
191 {
177 - ExitWithLastError(hr, "Failed to create process: %ls", sczFullCommandLine);
192 + ProcExitWithLastError(hr, "Failed to create process: %ls", sczFullCommandLine);
193 }
194
195 *phProcess = pi.hProcess;
@@ -213,7 +228,7 @@ extern "C" HRESULT DAPI ProcExecute(
228
229 // Create redirect pipes.
230 hr = CreatePipes(&hOutRead, &hOutWrite, &hErrWrite, &hInRead, &hInWrite);
216 - ExitOnFailure(hr, "failed to create output pipes");
231 + ProcExitOnFailure(hr, "failed to create output pipes");
232
233 // Set up startup structure.
234 si.cb = sizeof(STARTUPINFOW);
@@ -249,7 +264,7 @@ extern "C" HRESULT DAPI ProcExecute(
264 }
265 else
266 {
252 - ExitWithLastError(hr, "Process failed to execute.");
267 + ProcExitWithLastError(hr, "Process failed to execute.");
268 }
269
270 *phProcess = pi.hProcess;
@@ -305,7 +320,7 @@ extern "C" HRESULT DAPI ProcWaitForCompletion(
320 er = ::WaitForSingleObject(hProcess, dwTimeout);
321 if (WAIT_FAILED == er)
322 {
308 - ExitWithLastError(hr, "Failed to wait for process to complete.");
323 + ProcExitWithLastError(hr, "Failed to wait for process to complete.");
324 }
325 else if (WAIT_TIMEOUT == er)
326 {
@@ -314,7 +329,7 @@ extern "C" HRESULT DAPI ProcWaitForCompletion(
329
330 if (!::GetExitCodeProcess(hProcess, &er))
331 {
317 - ExitWithLastError(hr, "Failed to get process return code.");
332 + ProcExitWithLastError(hr, "Failed to get process return code.");
333 }
334
335 *pReturnCode = er;
@@ -340,7 +355,7 @@ extern "C" HRESULT DAPI ProcWaitForIds(
355 DWORD cProcesses = 0;
356
357 rghProcesses = static_cast<HANDLE*>(MemAlloc(sizeof(DWORD) * cProcessIds, TRUE));
343 - ExitOnNull(rgdwProcessIds, hr, E_OUTOFMEMORY, "Failed to allocate array for process ID Handles.");
358 + ProcExitOnNull(rgdwProcessIds, hr, E_OUTOFMEMORY, "Failed to allocate array for process ID Handles.");
359
360 for (DWORD i = 0; i < cProcessIds; ++i)
361 {
@@ -354,11 +369,11 @@ extern "C" HRESULT DAPI ProcWaitForIds(
369 er = ::WaitForMultipleObjects(cProcesses, rghProcesses, TRUE, dwMilliseconds);
370 if (WAIT_FAILED == er)
371 {
357 - ExitWithLastError(hr, "Failed to wait for process to complete.");
372 + ProcExitWithLastError(hr, "Failed to wait for process to complete.");
373 }
374 else if (WAIT_TIMEOUT == er)
375 {
361 - ExitOnWin32Error(er, hr, "Timed out while waiting for process to complete.");
376 + ProcExitOnWin32Error(er, hr, "Timed out while waiting for process to complete.");
377 }
378
379 LExit:
@@ -393,7 +408,7 @@ extern "C" HRESULT DAPI ProcCloseIds(
408 {
409 if (!::EnumWindows(&CloseWindowEnumCallback, pdwProcessIds[i]))
410 {
396 - ExitWithLastError(hr, "Failed to enumerate windows.");
411 + ProcExitWithLastError(hr, "Failed to enumerate windows.");
412 }
413 }
414
@@ -430,30 +445,30 @@ static HRESULT CreatePipes(
445 // Create pipes
446 if (!::CreatePipe(&hOutTemp, &hOutWrite, &sa, 0))
447 {
433 - ExitWithLastError(hr, "failed to create output pipe");
448 + ProcExitWithLastError(hr, "failed to create output pipe");
449 }
450
451 if (!::CreatePipe(&hInRead, &hInTemp, &sa, 0))
452 {
438 - ExitWithLastError(hr, "failed to create input pipe");
453 + ProcExitWithLastError(hr, "failed to create input pipe");
454 }
455
456 // Duplicate output pipe so standard error and standard output write to the same pipe.
457 if (!::DuplicateHandle(::GetCurrentProcess(), hOutWrite, ::GetCurrentProcess(), &hErrWrite, 0, TRUE, DUPLICATE_SAME_ACCESS))
458 {
444 - ExitWithLastError(hr, "failed to duplicate write handle");
459 + ProcExitWithLastError(hr, "failed to duplicate write handle");
460 }
461
462 // We need to create new "output read" and "input write" handles that are non inheritable. Otherwise CreateProcess will creates handles in
463 // the child process that can't be closed.
464 if (!::DuplicateHandle(::GetCurrentProcess(), hOutTemp, ::GetCurrentProcess(), &hOutRead, 0, FALSE, DUPLICATE_SAME_ACCESS))
465 {
451 - ExitWithLastError(hr, "failed to duplicate output pipe");
466 + ProcExitWithLastError(hr, "failed to duplicate output pipe");
467 }
468
469 if (!::DuplicateHandle(::GetCurrentProcess(), hInTemp, ::GetCurrentProcess(), &hInWrite, 0, FALSE, DUPLICATE_SAME_ACCESS))
470 {
456 - ExitWithLastError(hr, "failed to duplicate input pipe");
471 + ProcExitWithLastError(hr, "failed to duplicate input pipe");
472 }
473
474 // now that everything has succeeded, assign to the outputs
src/dutil/regutil.cpp
+76 -61
@@ -2,6 +2,21 @@
2
3 #include "precomp.h"
4
5 +
6 +// Exit macros
7 +#define RegExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_REGUTIL, x, s, __VA_ARGS__)
8 +#define RegExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_REGUTIL, x, s, __VA_ARGS__)
9 +#define RegExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_REGUTIL, x, s, __VA_ARGS__)
10 +#define RegExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_REGUTIL, x, s, __VA_ARGS__)
11 +#define RegExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_REGUTIL, x, s, __VA_ARGS__)
12 +#define RegExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_REGUTIL, x, s, __VA_ARGS__)
13 +#define RegExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_REGUTIL, p, x, e, s, __VA_ARGS__)
14 +#define RegExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_REGUTIL, p, x, s, __VA_ARGS__)
15 +#define RegExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_REGUTIL, p, x, e, s, __VA_ARGS__)
16 +#define RegExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_REGUTIL, p, x, s, __VA_ARGS__)
17 +#define RegExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_REGUTIL, e, x, s, __VA_ARGS__)
18 +#define RegExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_REGUTIL, g, x, s, __VA_ARGS__)
19 +
20 static PFN_REGCREATEKEYEXW vpfnRegCreateKeyExW = ::RegCreateKeyExW;
21 static PFN_REGOPENKEYEXW vpfnRegOpenKeyExW = ::RegOpenKeyExW;
22 static PFN_REGDELETEKEYEXW vpfnRegDeleteKeyExW = NULL;
@@ -34,7 +49,7 @@ extern "C" HRESULT DAPI RegInitialize(
49 HRESULT hr = S_OK;
50
51 hr = LoadSystemLibrary(L"AdvApi32.dll", &vhAdvApi32Dll);
37 - ExitOnFailure(hr, "Failed to load AdvApi32.dll");
52 + RegExitOnFailure(hr, "Failed to load AdvApi32.dll");
53
54 // ignore failures - if this doesn't exist, we'll fall back to RegDeleteKeyW
55 vpfnRegDeleteKeyExWFromLibrary = reinterpret_cast<PFN_REGDELETEKEYEXW>(::GetProcAddress(vhAdvApi32Dll, "RegDeleteKeyExW"));
@@ -114,7 +129,7 @@ extern "C" HRESULT DAPI RegCreate(
129 DWORD er = ERROR_SUCCESS;
130
131 er = vpfnRegCreateKeyExW(hkRoot, wzSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, dwAccess, NULL, phk, NULL);
117 - ExitOnWin32Error(er, hr, "Failed to create registry key.");
132 + RegExitOnWin32Error(er, hr, "Failed to create registry key.");
133
134 LExit:
135 return hr;
@@ -140,7 +155,7 @@ HRESULT DAPI RegCreateEx(
155 DWORD dwDisposition;
156
157 er = vpfnRegCreateKeyExW(hkRoot, wzSubKey, 0, NULL, fVolatile ? REG_OPTION_VOLATILE : REG_OPTION_NON_VOLATILE, dwAccess, pSecurityAttributes, phk, &dwDisposition);
143 - ExitOnWin32Error(er, hr, "Failed to create registry key.");
158 + RegExitOnWin32Error(er, hr, "Failed to create registry key.");
159
160 if (pfCreated)
161 {
@@ -171,7 +186,7 @@ extern "C" HRESULT DAPI RegOpen(
186 {
187 ExitFunction1(hr = E_FILENOTFOUND);
188 }
174 - ExitOnWin32Error(er, hr, "Failed to open registry key.");
189 + RegExitOnWin32Error(er, hr, "Failed to open registry key.");
190
191 LExit:
192 return hr;
@@ -199,7 +214,7 @@ extern "C" HRESULT DAPI RegDelete(
214 if (!vfRegInitialized && REG_KEY_DEFAULT != kbKeyBitness)
215 {
216 hr = E_INVALIDARG;
202 - ExitOnFailure(hr, "RegInitialize must be called first in order to RegDelete() a key with non-default bit attributes!");
217 + RegExitOnFailure(hr, "RegInitialize must be called first in order to RegDelete() a key with non-default bit attributes!");
218 }
219
220 switch (kbKeyBitness)
@@ -222,18 +237,18 @@ extern "C" HRESULT DAPI RegDelete(
237 {
238 ExitFunction1(hr = S_OK);
239 }
225 - ExitOnFailure(hr, "Failed to open this key for enumerating subkeys", wzSubKey);
240 + RegExitOnFailure(hr, "Failed to open this key for enumerating subkeys: %ls", wzSubKey);
241
242 // Yes, keep enumerating the 0th item, because we're deleting it every time
243 while (E_NOMOREITEMS != (hr = RegKeyEnum(hkKey, 0, &pszEnumeratedSubKey)))
244 {
230 - ExitOnFailure(hr, "Failed to enumerate key 0");
245 + RegExitOnFailure(hr, "Failed to enumerate key 0");
246
247 hr = PathConcat(wzSubKey, pszEnumeratedSubKey, &pszRecursiveSubKey);
233 - ExitOnFailure(hr, "Failed to concatenate paths while recursively deleting subkeys. Path1: %ls, Path2: %ls", wzSubKey, pszEnumeratedSubKey);
248 + RegExitOnFailure(hr, "Failed to concatenate paths while recursively deleting subkeys. Path1: %ls, Path2: %ls", wzSubKey, pszEnumeratedSubKey);
249
250 hr = RegDelete(hkRoot, pszRecursiveSubKey, kbKeyBitness, fDeleteTree);
236 - ExitOnFailure(hr, "Failed to recursively delete subkey: %ls", pszRecursiveSubKey);
251 + RegExitOnFailure(hr, "Failed to recursively delete subkey: %ls", pszRecursiveSubKey);
252 }
253
254 hr = S_OK;
@@ -246,7 +261,7 @@ extern "C" HRESULT DAPI RegDelete(
261 {
262 ExitFunction1(hr = E_FILENOTFOUND);
263 }
249 - ExitOnWin32Error(er, hr, "Failed to delete registry key (ex).");
264 + RegExitOnWin32Error(er, hr, "Failed to delete registry key (ex).");
265 }
266 else
267 {
@@ -255,7 +270,7 @@ extern "C" HRESULT DAPI RegDelete(
270 {
271 ExitFunction1(hr = E_FILENOTFOUND);
272 }
258 - ExitOnWin32Error(er, hr, "Failed to delete registry key.");
273 + RegExitOnWin32Error(er, hr, "Failed to delete registry key.");
274 }
275
276 LExit:
@@ -284,7 +299,7 @@ extern "C" HRESULT DAPI RegKeyEnum(
299 if (psczKey && *psczKey)
300 {
301 hr = StrMaxLength(*psczKey, reinterpret_cast<DWORD_PTR*>(&cch));
287 - ExitOnFailure(hr, "Failed to determine length of string.");
302 + RegExitOnFailure(hr, "Failed to determine length of string.");
303 }
304
305 if (2 > cch)
@@ -292,18 +307,18 @@ extern "C" HRESULT DAPI RegKeyEnum(
307 cch = 2;
308
309 hr = StrAlloc(psczKey, cch);
295 - ExitOnFailure(hr, "Failed to allocate string to minimum size.");
310 + RegExitOnFailure(hr, "Failed to allocate string to minimum size.");
311 }
312
313 er = vpfnRegEnumKeyExW(hk, dwIndex, *psczKey, &cch, NULL, NULL, NULL, NULL);
314 if (ERROR_MORE_DATA == er)
315 {
316 er = vpfnRegQueryInfoKeyW(hk, NULL, NULL, NULL, NULL, &cch, NULL, NULL, NULL, NULL, NULL, NULL);
302 - ExitOnWin32Error(er, hr, "Failed to get max size of subkey name under registry key.");
317 + RegExitOnWin32Error(er, hr, "Failed to get max size of subkey name under registry key.");
318
319 ++cch; // add one because RegQueryInfoKeyW() returns the length of the subkeys without the null terminator.
320 hr = StrAlloc(psczKey, cch);
306 - ExitOnFailure(hr, "Failed to allocate string bigger for enum registry key.");
321 + RegExitOnFailure(hr, "Failed to allocate string bigger for enum registry key.");
322
323 er = vpfnRegEnumKeyExW(hk, dwIndex, *psczKey, &cch, NULL, NULL, NULL, NULL);
324 }
@@ -311,7 +326,7 @@ extern "C" HRESULT DAPI RegKeyEnum(
326 {
327 ExitFunction1(hr = E_NOMOREITEMS);
328 }
314 - ExitOnWin32Error(er, hr, "Failed to enum registry key.");
329 + RegExitOnWin32Error(er, hr, "Failed to enum registry key.");
330
331 // Always ensure the registry key name is null terminated.
332 #pragma prefast(push)
@@ -340,20 +355,20 @@ HRESULT DAPI RegValueEnum(
355 DWORD cbValueName = 0;
356
357 er = vpfnRegQueryInfoKeyW(hk, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &cbValueName, NULL, NULL, NULL);
343 - ExitOnWin32Error(er, hr, "Failed to get max size of value name under registry key.");
358 + RegExitOnWin32Error(er, hr, "Failed to get max size of value name under registry key.");
359
360 // Add one for null terminator
361 ++cbValueName;
362
363 hr = StrAlloc(psczName, cbValueName);
349 - ExitOnFailure(hr, "Failed to allocate array for registry value name");
364 + RegExitOnFailure(hr, "Failed to allocate array for registry value name");
365
366 er = vpfnRegEnumValueW(hk, dwIndex, *psczName, &cbValueName, NULL, pdwType, NULL, NULL);
367 if (ERROR_NO_MORE_ITEMS == er)
368 {
369 ExitFunction1(hr = E_NOMOREITEMS);
370 }
356 - ExitOnWin32Error(er, hr, "Failed to enumerate registry value");
371 + RegExitOnWin32Error(er, hr, "Failed to enumerate registry value");
372
373 LExit:
374 return hr;
@@ -376,7 +391,7 @@ HRESULT DAPI RegGetType(
391 {
392 ExitFunction1(hr = E_FILENOTFOUND);
393 }
379 - ExitOnWin32Error(er, hr, "Failed to read registry value.");
394 + RegExitOnWin32Error(er, hr, "Failed to read registry value.");
395 LExit:
396
397 return hr;
@@ -400,20 +415,20 @@ HRESULT DAPI RegReadBinary(
415 DWORD dwType = 0;
416
417 er = vpfnRegQueryValueExW(hk, wzName, NULL, &dwType, NULL, &cb);
403 - ExitOnWin32Error(er, hr, "Failed to get size of registry value.");
418 + RegExitOnWin32Error(er, hr, "Failed to get size of registry value.");
419
420 // Zero-length binary values can exist
421 if (0 < cb)
422 {
423 pbBuffer = static_cast<LPBYTE>(MemAlloc(cb, FALSE));
409 - ExitOnNull(pbBuffer, hr, E_OUTOFMEMORY, "Failed to allocate buffer for binary registry value.");
424 + RegExitOnNull(pbBuffer, hr, E_OUTOFMEMORY, "Failed to allocate buffer for binary registry value.");
425
426 er = vpfnRegQueryValueExW(hk, wzName, NULL, &dwType, pbBuffer, &cb);
427 if (E_FILENOTFOUND == HRESULT_FROM_WIN32(er))
428 {
429 ExitFunction1(hr = E_FILENOTFOUND);
430 }
416 - ExitOnWin32Error(er, hr, "Failed to read registry value.");
431 + RegExitOnWin32Error(er, hr, "Failed to read registry value.");
432 }
433
434 if (REG_BINARY == dwType)
@@ -425,7 +440,7 @@ HRESULT DAPI RegReadBinary(
440 else
441 {
442 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATATYPE);
428 - ExitOnRootFailure(hr, "Error reading binary registry value due to unexpected data type: %u", dwType);
443 + RegExitOnRootFailure(hr, "Error reading binary registry value due to unexpected data type: %u", dwType);
444 }
445
446 LExit:
@@ -455,7 +470,7 @@ extern "C" HRESULT DAPI RegReadString(
470 if (psczValue && *psczValue)
471 {
472 hr = StrMaxLength(*psczValue, reinterpret_cast<DWORD_PTR*>(&cch));
458 - ExitOnFailure(hr, "Failed to determine length of string.");
473 + RegExitOnFailure(hr, "Failed to determine length of string.");
474 }
475
476 if (2 > cch)
@@ -463,7 +478,7 @@ extern "C" HRESULT DAPI RegReadString(
478 cch = 2;
479
480 hr = StrAlloc(psczValue, cch);
466 - ExitOnFailure(hr, "Failed to allocate string to minimum size.");
481 + RegExitOnFailure(hr, "Failed to allocate string to minimum size.");
482 }
483
484 cb = sizeof(WCHAR) * (cch - 1); // subtract one to ensure there will be a space at the end of the string for the null terminator.
@@ -472,7 +487,7 @@ extern "C" HRESULT DAPI RegReadString(
487 {
488 cch = cb / sizeof(WCHAR) + 1; // add one to ensure there will be space at the end for the null terminator
489 hr = StrAlloc(psczValue, cch);
475 - ExitOnFailure(hr, "Failed to allocate string bigger for registry value.");
490 + RegExitOnFailure(hr, "Failed to allocate string bigger for registry value.");
491
492 er = vpfnRegQueryValueExW(hk, wzName, NULL, &dwType, reinterpret_cast<LPBYTE>(*psczValue), &cb);
493 }
@@ -480,7 +495,7 @@ extern "C" HRESULT DAPI RegReadString(
495 {
496 ExitFunction1(hr = E_FILENOTFOUND);
497 }
483 - ExitOnWin32Error(er, hr, "Failed to read registry key.");
498 + RegExitOnWin32Error(er, hr, "Failed to read registry key.");
499
500 if (REG_SZ == dwType || REG_EXPAND_SZ == dwType)
501 {
@@ -490,16 +505,16 @@ extern "C" HRESULT DAPI RegReadString(
505 if (REG_EXPAND_SZ == dwType)
506 {
507 hr = StrAllocString(&sczExpand, *psczValue, 0);
493 - ExitOnFailure(hr, "Failed to copy registry value to expand.");
508 + RegExitOnFailure(hr, "Failed to copy registry value to expand.");
509
510 hr = PathExpand(psczValue, sczExpand, PATH_EXPAND_ENVIRONMENT);
496 - ExitOnFailure(hr, "Failed to expand registry value: %ls", *psczValue);
511 + RegExitOnFailure(hr, "Failed to expand registry value: %ls", *psczValue);
512 }
513 }
514 else
515 {
516 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATATYPE);
502 - ExitOnRootFailure(hr, "Error reading string registry value due to unexpected data type: %u", dwType);
517 + RegExitOnRootFailure(hr, "Error reading string registry value due to unexpected data type: %u", dwType);
518 }
519
520 LExit:
@@ -516,7 +531,7 @@ LExit:
531 HRESULT DAPI RegReadStringArray(
532 __in HKEY hk,
533 __in_z_opt LPCWSTR wzName,
519 - __deref_out_ecount_opt(pcStrings) LPWSTR** prgsczStrings,
534 + __deref_out_ecount_opt(*pcStrings) LPWSTR** prgsczStrings,
535 __out DWORD *pcStrings
536 )
537 {
@@ -534,7 +549,7 @@ HRESULT DAPI RegReadStringArray(
549 {
550 cch = cb / sizeof(WCHAR);
551 hr = StrAlloc(&sczValue, cch);
537 - ExitOnFailure(hr, "Failed to allocate string for registry value.");
552 + RegExitOnFailure(hr, "Failed to allocate string for registry value.");
553
554 er = vpfnRegQueryValueExW(hk, wzName, NULL, &dwType, reinterpret_cast<LPBYTE>(sczValue), &cb);
555 }
@@ -542,18 +557,18 @@ HRESULT DAPI RegReadStringArray(
557 {
558 ExitFunction1(hr = E_FILENOTFOUND);
559 }
545 - ExitOnWin32Error(er, hr, "Failed to read registry key.");
560 + RegExitOnWin32Error(er, hr, "Failed to read registry key.");
561
562 if (cb / sizeof(WCHAR) != cch)
563 {
564 hr = E_UNEXPECTED;
550 - ExitOnFailure(hr, "The size of registry value %ls unexpected changed between 2 reads", wzName);
565 + RegExitOnFailure(hr, "The size of registry value %ls unexpected changed between 2 reads", wzName);
566 }
567
568 if (REG_MULTI_SZ != dwType)
569 {
570 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATATYPE);
556 - ExitOnRootFailure(hr, "Tried to read string array, but registry value %ls is of an incorrect type", wzName);
571 + RegExitOnRootFailure(hr, "Tried to read string array, but registry value %ls is of an incorrect type", wzName);
572 }
573
574 // Value exists, but is empty, so no strings to return.
@@ -568,7 +583,7 @@ HRESULT DAPI RegReadStringArray(
583 if (L'\0' != sczValue[cch-1] || L'\0' != sczValue[cch-2])
584 {
585 hr = E_INVALIDARG;
571 - ExitOnFailure(hr, "Tried to read string array, but registry value %ls is invalid (isn't double-null-terminated)", wzName);
586 + RegExitOnFailure(hr, "Tried to read string array, but registry value %ls is invalid (isn't double-null-terminated)", wzName);
587 }
588
589 cch = cb / sizeof(WCHAR);
@@ -583,7 +598,7 @@ HRESULT DAPI RegReadStringArray(
598 // There's one string for every null character encountered (except the extra 1 at the end of the string)
599 *pcStrings = dwNullCharacters - 1;
600 hr = MemEnsureArraySize(reinterpret_cast<LPVOID *>(prgsczStrings), *pcStrings, sizeof(LPWSTR), 0);
586 - ExitOnFailure(hr, "Failed to resize array while reading REG_MULTI_SZ value");
601 + RegExitOnFailure(hr, "Failed to resize array while reading REG_MULTI_SZ value");
602
603 #pragma prefast(push)
604 #pragma prefast(disable:26010)
@@ -591,7 +606,7 @@ HRESULT DAPI RegReadStringArray(
606 for (DWORD i = 0; i < *pcStrings; ++i)
607 {
608 hr = StrAllocString(&(*prgsczStrings)[i], wzSource, 0);
594 - ExitOnFailure(hr, "Failed to allocate copy of string");
609 + RegExitOnFailure(hr, "Failed to allocate copy of string");
610
611 // Skip past this string
612 wzSource += lstrlenW(wzSource) + 1;
@@ -630,19 +645,19 @@ extern "C" HRESULT DAPI RegReadVersion(
645 if (REG_SZ == dwType || REG_EXPAND_SZ == dwType)
646 {
647 hr = RegReadString(hk, wzName, &sczVersion);
633 - ExitOnFailure(hr, "Failed to read registry version as string.");
648 + RegExitOnFailure(hr, "Failed to read registry version as string.");
649
650 hr = FileVersionFromStringEx(sczVersion, 0, pdw64Version);
636 - ExitOnFailure(hr, "Failed to convert registry string to version.");
651 + RegExitOnFailure(hr, "Failed to convert registry string to version.");
652 }
653 else if (REG_QWORD == dwType)
654 {
640 - ExitOnWin32Error(er, hr, "Failed to read registry key.");
655 + RegExitOnWin32Error(er, hr, "Failed to read registry key.");
656 }
657 else // unexpected data type
658 {
659 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATATYPE);
645 - ExitOnRootFailure(hr, "Error reading version registry value due to unexpected data type: %u", dwType);
660 + RegExitOnRootFailure(hr, "Error reading version registry value due to unexpected data type: %u", dwType);
661 }
662
663 LExit:
@@ -672,12 +687,12 @@ extern "C" HRESULT DAPI RegReadNumber(
687 {
688 ExitFunction1(hr = E_FILENOTFOUND);
689 }
675 - ExitOnWin32Error(er, hr, "Failed to query registry key value.");
690 + RegExitOnWin32Error(er, hr, "Failed to query registry key value.");
691
692 if (REG_DWORD != dwType)
693 {
694 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATATYPE);
680 - ExitOnRootFailure(hr, "Error reading version registry value due to unexpected data type: %u", dwType);
695 + RegExitOnRootFailure(hr, "Error reading version registry value due to unexpected data type: %u", dwType);
696 }
697
698 LExit:
@@ -705,12 +720,12 @@ extern "C" HRESULT DAPI RegReadQword(
720 {
721 ExitFunction1(hr = E_FILENOTFOUND);
722 }
708 - ExitOnWin32Error(er, hr, "Failed to query registry key value.");
723 + RegExitOnWin32Error(er, hr, "Failed to query registry key value.");
724
725 if (REG_QWORD != dwType)
726 {
727 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATATYPE);
713 - ExitOnRootFailure(hr, "Error reading version registry value due to unexpected data type: %u", dwType);
728 + RegExitOnRootFailure(hr, "Error reading version registry value due to unexpected data type: %u", dwType);
729 }
730
731 LExit:
@@ -733,7 +748,7 @@ HRESULT DAPI RegWriteBinary(
748 DWORD er = ERROR_SUCCESS;
749
750 er = vpfnRegSetValueExW(hk, wzName, 0, REG_BINARY, pbBuffer, cbBuffer);
736 - ExitOnWin32Error(er, hr, "Failed to write binary registry value with name: %ls", wzName);
751 + RegExitOnWin32Error(er, hr, "Failed to write binary registry value with name: %ls", wzName);
752
753 LExit:
754 return hr;
@@ -788,7 +803,7 @@ extern "C" HRESULT DAPI RegWriteStringFormatted(
803 va_start(args, szFormat);
804 hr = StrAllocFormattedArgs(&sczValue, szFormat, args);
805 va_end(args);
791 - ExitOnFailure(hr, "Failed to allocate %ls value.", wzName);
806 + RegExitOnFailure(hr, "Failed to allocate %ls value.", wzName);
807
808 hr = WriteStringToRegistry(hk, wzName, sczValue, REG_SZ);
809
@@ -832,18 +847,18 @@ HRESULT DAPI RegWriteStringArray(
847 {
848 dwTemp = dwTotalStringSize;
849 hr = ::DWordAdd(dwTemp, 1 + lstrlenW(rgwzValues[i]), &dwTotalStringSize);
835 - ExitOnFailure(hr, "DWORD Overflow while adding length of string to write REG_MULTI_SZ");
850 + RegExitOnFailure(hr, "DWORD Overflow while adding length of string to write REG_MULTI_SZ");
851 }
852
853 hr = StrAlloc(&sczWriteValue, dwTotalStringSize);
839 - ExitOnFailure(hr, "Failed to allocate space for string while writing REG_MULTI_SZ");
854 + RegExitOnFailure(hr, "Failed to allocate space for string while writing REG_MULTI_SZ");
855
856 wzCopyDestination = sczWriteValue;
857 dwTemp = dwTotalStringSize;
858 for (DWORD i = 0; i < cValues; ++i)
859 {
860 hr = ::StringCchCopyW(wzCopyDestination, dwTotalStringSize, rgwzValues[i]);
846 - ExitOnFailure(hr, "failed to copy string: %ls", rgwzValues[i]);
861 + RegExitOnFailure(hr, "failed to copy string: %ls", rgwzValues[i]);
862
863 dwTemp -= lstrlenW(rgwzValues[i]) + 1;
864 wzCopyDestination += lstrlenW(rgwzValues[i]) + 1;
@@ -853,10 +868,10 @@ HRESULT DAPI RegWriteStringArray(
868 }
869
870 hr = ::DWordMult(dwTotalStringSize, sizeof(WCHAR), &cbTotalStringSize);
856 - ExitOnFailure(hr, "Failed to get total string size in bytes");
871 + RegExitOnFailure(hr, "Failed to get total string size in bytes");
872
873 er = vpfnRegSetValueExW(hk, wzName, 0, REG_MULTI_SZ, reinterpret_cast<const BYTE *>(wzWriteValue), cbTotalStringSize);
859 - ExitOnWin32Error(er, hr, "Failed to set registry value to array of strings (first string of which is): %ls", wzWriteValue);
874 + RegExitOnWin32Error(er, hr, "Failed to set registry value to array of strings (first string of which is): %ls", wzWriteValue);
875
876 LExit:
877 ReleaseStr(sczWriteValue);
@@ -878,7 +893,7 @@ extern "C" HRESULT DAPI RegWriteNumber(
893 DWORD er = ERROR_SUCCESS;
894
895 er = vpfnRegSetValueExW(hk, wzName, 0, REG_DWORD, reinterpret_cast<const BYTE *>(&dwValue), sizeof(dwValue));
881 - ExitOnWin32Error(er, hr, "Failed to set %ls value.", wzName);
896 + RegExitOnWin32Error(er, hr, "Failed to set %ls value.", wzName);
897
898 LExit:
899 return hr;
@@ -898,7 +913,7 @@ extern "C" HRESULT DAPI RegWriteQword(
913 DWORD er = ERROR_SUCCESS;
914
915 er = vpfnRegSetValueExW(hk, wzName, 0, REG_QWORD, reinterpret_cast<const BYTE *>(&qwValue), sizeof(qwValue));
901 - ExitOnWin32Error(er, hr, "Failed to set %ls value.", wzName);
916 + RegExitOnWin32Error(er, hr, "Failed to set %ls value.", wzName);
917
918 LExit:
919 return hr;
@@ -918,7 +933,7 @@ extern "C" HRESULT DAPI RegQueryKey(
933 DWORD er = ERROR_SUCCESS;
934
935 er = vpfnRegQueryInfoKeyW(hk, NULL, NULL, NULL, pcSubKeys, NULL, NULL, pcValues, NULL, NULL, NULL, NULL);
921 - ExitOnWin32Error(er, hr, "Failed to get the number of subkeys and values under registry key.");
936 + RegExitOnWin32Error(er, hr, "Failed to get the number of subkeys and values under registry key.");
937
938 LExit:
939 return hr;
@@ -938,11 +953,11 @@ static HRESULT WriteStringToRegistry(
953
954 if (wzValue)
955 {
941 - hr = ::StringCbLengthW(wzValue, DWORD_MAX, reinterpret_cast<size_t*>(&cbValue));
942 - ExitOnFailure(hr, "Failed to determine length of registry value: %ls", wzName);
956 + hr = ::StringCbLengthW(wzValue, STRSAFE_MAX_CCH * sizeof(TCHAR), reinterpret_cast<size_t*>(&cbValue));
957 + RegExitOnFailure(hr, "Failed to determine length of registry value: %ls", wzName);
958
959 er = vpfnRegSetValueExW(hk, wzName, 0, dwType, reinterpret_cast<const BYTE *>(wzValue), cbValue);
945 - ExitOnWin32Error(er, hr, "Failed to set registry value: %ls", wzName);
960 + RegExitOnWin32Error(er, hr, "Failed to set registry value: %ls", wzName);
961 }
962 else
963 {
@@ -951,7 +966,7 @@ static HRESULT WriteStringToRegistry(
966 {
967 er = ERROR_SUCCESS;
968 }
954 - ExitOnWin32Error(er, hr, "Failed to delete registry value: %ls", wzName);
969 + RegExitOnWin32Error(er, hr, "Failed to delete registry value: %ls", wzName);
970 }
971
972 LExit:
src/dutil/resrutil.cpp
+30 -15
@@ -2,6 +2,21 @@
2
3 #include "precomp.h"
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 +
20 #define RES_STRINGS_PER_BLOCK 16
21
22
@@ -33,7 +48,7 @@ extern "C" HRESULT DAPI ResGetStringLangId(
48 if (wzPath && *wzPath)
49 {
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);
52 }
53
54 #pragma prefast(push)
@@ -41,7 +56,7 @@ extern "C" HRESULT DAPI ResGetStringLangId(
56 if (!::EnumResourceLanguagesA(hModule, RT_STRING, MAKEINTRESOURCE(dwBlockId), static_cast<ENUMRESLANGPROC>(EnumLangIdProc), reinterpret_cast<LONG_PTR>(&wFoundLangId)))
57 #pragma prefast(pop)
58 {
44 - ExitWithLastError(hr, "Failed to find string language identifier.");
59 + ResrExitWithLastError(hr, "Failed to find string language identifier.");
60 }
61
62 *pwLangId = wFoundLangId;
@@ -76,12 +91,12 @@ extern "C" HRESULT DAPI ResReadString(
91 do
92 {
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);
95
96 cchReturned = ::LoadStringW(hinst, uID, *ppwzString, cch);
97 if (0 == cchReturned)
98 {
84 - ExitWithLastError(hr, "Failed to load string resource id: %d", uID);
99 + ResrExitWithLastError(hr, "Failed to load string resource id: %d", uID);
100 }
101
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(
107 hr = S_FALSE;
108 }
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);
111
112 LExit:
113 return hr;
@@ -119,7 +134,7 @@ extern "C" HRESULT DAPI ResReadStringAnsi(
134 do
135 {
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);
138
139 #pragma prefast(push)
140 #pragma prefast(disable:25068)
@@ -127,7 +142,7 @@ extern "C" HRESULT DAPI ResReadStringAnsi(
142 #pragma prefast(pop)
143 if (0 == cchReturned)
144 {
130 - ExitWithLastError(hr, "Failed to load string resource id: %d", uID);
145 + ResrExitWithLastError(hr, "Failed to load string resource id: %d", uID);
146 }
147
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(
153 hr = S_FALSE;
154 }
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);
157
158 LExit:
159 return hr;
@@ -169,19 +184,19 @@ extern "C" HRESULT DAPI ResReadData(
184 #pragma prefast(disable:25068)
185 hRsrc = ::FindResourceExA(hinst, RT_RCDATA, szDataName, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
186 #pragma prefast(pop)
172 - ExitOnNullWithLastError(hRsrc, hr, "Failed to find resource.");
187 + ResrExitOnNullWithLastError(hRsrc, hr, "Failed to find resource.");
188
189 hData = ::LoadResource(hinst, hRsrc);
175 - ExitOnNullWithLastError(hData, hr, "Failed to load resource.");
190 + ResrExitOnNullWithLastError(hData, hr, "Failed to load resource.");
191
192 cbData = ::SizeofResource(hinst, hRsrc);
193 if (!cbData)
194 {
180 - ExitWithLastError(hr, "Failed to get size of resource.");
195 + ResrExitWithLastError(hr, "Failed to get size of resource.");
196 }
197
198 *ppv = ::LockResource(hData);
184 - ExitOnNullWithLastError(*ppv, hr, "Failed to lock data resource.");
199 + ResrExitOnNullWithLastError(*ppv, hr, "Failed to lock data resource.");
200 *pcb = cbData;
201
202 LExit:
@@ -207,18 +222,18 @@ extern "C" HRESULT DAPI ResExportDataToFile(
222 BOOL bCreatedFile = FALSE;
223
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);
226
227 hFile = ::CreateFileW(wzTargetFile, GENERIC_WRITE, 0, NULL, dwCreationDisposition, FILE_ATTRIBUTE_NORMAL, NULL);
228 if (INVALID_HANDLE_VALUE == hFile)
229 {
215 - ExitWithLastError(hr, "Failed to CreateFileW for %ls.", wzTargetFile);
230 + ResrExitWithLastError(hr, "Failed to CreateFileW for %ls.", wzTargetFile);
231 }
232 bCreatedFile = TRUE;
233
234 if (!::WriteFile(hFile, pData, cbData, &cbWritten, NULL))
235 {
221 - ExitWithLastError(hr, "Failed to ::WriteFile for %ls.", wzTargetFile);
236 + ResrExitWithLastError(hr, "Failed to ::WriteFile for %ls.", wzTargetFile);
237 }
238
239 LExit:
src/dutil/reswutil.cpp
+40 -25
@@ -2,6 +2,21 @@
2
3 #include "precomp.h"
4
5 +
6 +// Exit macros
7 +#define ReswExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_RESWUTIL, x, s, __VA_ARGS__)
8 +#define ReswExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_RESWUTIL, x, s, __VA_ARGS__)
9 +#define ReswExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_RESWUTIL, x, s, __VA_ARGS__)
10 +#define ReswExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_RESWUTIL, x, s, __VA_ARGS__)
11 +#define ReswExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_RESWUTIL, x, s, __VA_ARGS__)
12 +#define ReswExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_RESWUTIL, x, s, __VA_ARGS__)
13 +#define ReswExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_RESWUTIL, p, x, e, s, __VA_ARGS__)
14 +#define ReswExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_RESWUTIL, p, x, s, __VA_ARGS__)
15 +#define ReswExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_RESWUTIL, p, x, e, s, __VA_ARGS__)
16 +#define ReswExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_RESWUTIL, p, x, s, __VA_ARGS__)
17 +#define ReswExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_RESWUTIL, e, x, s, __VA_ARGS__)
18 +#define ReswExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_RESWUTIL, g, x, s, __VA_ARGS__)
19 +
20 #define RES_STRINGS_PER_BLOCK 16
21
22 // Internal data structure format for a string block in a resource table.
@@ -66,31 +81,31 @@ extern "C" HRESULT DAPI ResWriteString(
81 DWORD dwStringId = (dwDataId % RES_STRINGS_PER_BLOCK);
82
83 hModule = LoadLibraryExW(wzResourceFile, NULL, DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE);
69 - ExitOnNullWithLastError(hModule, hr, "Failed to load library: %ls", wzResourceFile);
84 + ReswExitOnNullWithLastError(hModule, hr, "Failed to load library: %ls", wzResourceFile);
85
86 hr = StringBlockInitialize(hModule, dwBlockId, wLangId, &StrBlock);
72 - ExitOnFailure(hr, "Failed to get string block to update.");
87 + ReswExitOnFailure(hr, "Failed to get string block to update.");
88
89 hr = StringBlockChangeString(&StrBlock, dwStringId, wzData);
75 - ExitOnFailure(hr, "Failed to update string block string.");
90 + ReswExitOnFailure(hr, "Failed to update string block string.");
91
92 hr = StringBlockConvertToResourceData(&StrBlock, &pvData, &cbData);
78 - ExitOnFailure(hr, "Failed to convert string block to resource data.");
93 + ReswExitOnFailure(hr, "Failed to convert string block to resource data.");
94
95 ::FreeLibrary(hModule);
96 hModule = NULL;
97
98 hUpdate = ::BeginUpdateResourceW(wzResourceFile, FALSE);
84 - ExitOnNullWithLastError(hUpdate, hr, "Failed to ::BeginUpdateResourcesW.");
99 + ReswExitOnNullWithLastError(hUpdate, hr, "Failed to ::BeginUpdateResourcesW.");
100
101 if (!::UpdateResourceA(hUpdate, RT_STRING, MAKEINTRESOURCE(dwBlockId), wLangId, pvData, cbData))
102 {
88 - ExitWithLastError(hr, "Failed to ::UpdateResourceA.");
103 + ReswExitWithLastError(hr, "Failed to ::UpdateResourceA.");
104 }
105
106 if (!::EndUpdateResource(hUpdate, FALSE))
107 {
93 - ExitWithLastError(hr, "Failed to ::EndUpdateResourceW.");
108 + ReswExitWithLastError(hr, "Failed to ::EndUpdateResourceW.");
109 }
110
111 hUpdate = NULL;
@@ -134,16 +149,16 @@ extern "C" HRESULT DAPI ResWriteData(
149 HANDLE hUpdate = NULL;
150
151 hUpdate = ::BeginUpdateResourceW(wzResourceFile, FALSE);
137 - ExitOnNullWithLastError(hUpdate, hr, "Failed to ::BeginUpdateResourcesW.");
152 + ReswExitOnNullWithLastError(hUpdate, hr, "Failed to ::BeginUpdateResourcesW.");
153
154 if (!::UpdateResourceA(hUpdate, RT_RCDATA, szDataName, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), pData, cbData))
155 {
141 - ExitWithLastError(hr, "Failed to ::UpdateResourceA.");
156 + ReswExitWithLastError(hr, "Failed to ::UpdateResourceA.");
157 }
158
159 if (!::EndUpdateResource(hUpdate, FALSE))
160 {
146 - ExitWithLastError(hr, "Failed to ::EndUpdateResourceW.");
161 + ReswExitWithLastError(hr, "Failed to ::EndUpdateResourceW.");
162 }
163
164 hUpdate = NULL;
@@ -177,23 +192,23 @@ extern "C" HRESULT DAPI ResImportDataFromFile(
192 hFile = ::CreateFileW(wzSourceFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
193 if (INVALID_HANDLE_VALUE == hFile)
194 {
180 - ExitWithLastError(hr, "Failed to CreateFileW for %ls.", wzSourceFile);
195 + ReswExitWithLastError(hr, "Failed to CreateFileW for %ls.", wzSourceFile);
196 }
197
198 cbFile = ::GetFileSize(hFile, NULL);
199 if (!cbFile)
200 {
186 - ExitWithLastError(hr, "Failed to GetFileSize for %ls.", wzSourceFile);
201 + ReswExitWithLastError(hr, "Failed to GetFileSize for %ls.", wzSourceFile);
202 }
203
204 hMap = ::CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
190 - ExitOnNullWithLastError(hMap, hr, "Failed to CreateFileMapping for %ls.", wzSourceFile);
205 + ReswExitOnNullWithLastError(hMap, hr, "Failed to CreateFileMapping for %ls.", wzSourceFile);
206
207 pv = ::MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, cbFile);
193 - ExitOnNullWithLastError(pv, hr, "Failed to MapViewOfFile for %ls.", wzSourceFile);
208 + ReswExitOnNullWithLastError(pv, hr, "Failed to MapViewOfFile for %ls.", wzSourceFile);
209
210 hr = ResWriteData(wzTargetFile, szDataName, pv, cbFile);
196 - ExitOnFailure(hr, "Failed to ResSetData %s on file %ls.", szDataName, wzTargetFile);
211 + ReswExitOnFailure(hr, "Failed to ResSetData %s on file %ls.", szDataName, wzTargetFile);
212
213 LExit:
214 if (pv)
@@ -226,25 +241,25 @@ static HRESULT StringBlockInitialize(
241 DWORD cbData = 0;
242
243 hRsrc = ::FindResourceExA(hModule, RT_STRING, MAKEINTRESOURCE(dwBlockId), wLangId);
229 - ExitOnNullWithLastError(hRsrc, hr, "Failed to ::FindResourceExW.");
244 + ReswExitOnNullWithLastError(hRsrc, hr, "Failed to ::FindResourceExW.");
245
246 hData = ::LoadResource(hModule, hRsrc);
232 - ExitOnNullWithLastError(hData, hr, "Failed to ::LoadResource.");
247 + ReswExitOnNullWithLastError(hData, hr, "Failed to ::LoadResource.");
248
249 cbData = ::SizeofResource(hModule, hRsrc);
250 if (!cbData)
251 {
237 - ExitWithLastError(hr, "Failed to ::SizeofResource.");
252 + ReswExitWithLastError(hr, "Failed to ::SizeofResource.");
253 }
254
255 pvData = ::LockResource(hData);
241 - ExitOnNullWithLastError(pvData, hr, "Failed to lock data resource.");
256 + ReswExitOnNullWithLastError(pvData, hr, "Failed to lock data resource.");
257
258 pStrBlock->dwBlockId = dwBlockId;
259 pStrBlock->wLangId = wLangId;
260
261 hr = StringBlockConvertFromResourceData(pStrBlock, pvData, cbData);
247 - ExitOnFailure(hr, "Failed to convert string block from resource data.");
262 + ReswExitOnFailure(hr, "Failed to convert string block from resource data.");
263
264 LExit:
265 return hr;
@@ -276,10 +291,10 @@ static HRESULT StringBlockChangeString(
291 DWORD cchData = lstrlenW(szData);
292
293 pwzData = static_cast<LPWSTR>(MemAlloc((cchData + 1) * sizeof(WCHAR), TRUE));
279 - ExitOnNull(pwzData, hr, E_OUTOFMEMORY, "Failed to allocate new block string.");
294 + ReswExitOnNull(pwzData, hr, E_OUTOFMEMORY, "Failed to allocate new block string.");
295
296 hr = ::StringCchCopyW(pwzData, cchData + 1, szData);
282 - ExitOnFailure(hr, "Failed to copy new block string.");
297 + ReswExitOnFailure(hr, "Failed to copy new block string.");
298
299 ReleaseNullMem(pStrBlock->rgwz[dwStringId]);
300
@@ -311,7 +326,7 @@ static HRESULT StringBlockConvertToResourceData(
326 cbData *= sizeof(WCHAR);
327
328 pvData = MemAlloc(cbData, TRUE);
314 - ExitOnNull(pvData, hr, E_OUTOFMEMORY, "Failed to allocate buffer to convert string block.");
329 + ReswExitOnNull(pvData, hr, E_OUTOFMEMORY, "Failed to allocate buffer to convert string block.");
330
331 pwz = static_cast<LPWSTR>(pvData);
332 for (DWORD i = 0; i < RES_STRINGS_PER_BLOCK; ++i)
@@ -355,10 +370,10 @@ static HRESULT StringBlockConvertFromResourceData(
370 ++pwzParse;
371
372 pStrBlock->rgwz[i] = static_cast<LPWSTR>(MemAlloc((cchParse + 1) * sizeof(WCHAR), TRUE));
358 - ExitOnNull(pStrBlock->rgwz[i], hr, E_OUTOFMEMORY, "Failed to populate pStrBlock.");
373 + ReswExitOnNull(pStrBlock->rgwz[i], hr, E_OUTOFMEMORY, "Failed to populate pStrBlock.");
374
375 hr = ::StringCchCopyNExW(pStrBlock->rgwz[i], cchParse + 1, pwzParse, cchParse, NULL, NULL, STRSAFE_FILL_BEHIND_NULL);
361 - ExitOnFailure(hr, "Failed to copy parsed resource data into string block.");
376 + ReswExitOnFailure(hr, "Failed to copy parsed resource data into string block.");
377
378 pwzParse += cchParse;
379 }
src/dutil/rexutil.cpp
+37 -22
@@ -3,6 +3,21 @@
3 #include "precomp.h"
4 #include "rexutil.h"
5
6 +
7 +// Exit macros
8 +#define RexExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_REXUTIL, x, s, __VA_ARGS__)
9 +#define RexExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_REXUTIL, x, s, __VA_ARGS__)
10 +#define RexExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_REXUTIL, x, s, __VA_ARGS__)
11 +#define RexExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_REXUTIL, x, s, __VA_ARGS__)
12 +#define RexExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_REXUTIL, x, s, __VA_ARGS__)
13 +#define RexExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_REXUTIL, x, s, __VA_ARGS__)
14 +#define RexExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_REXUTIL, p, x, e, s, __VA_ARGS__)
15 +#define RexExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_REXUTIL, p, x, s, __VA_ARGS__)
16 +#define RexExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_REXUTIL, p, x, e, s, __VA_ARGS__)
17 +#define RexExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_REXUTIL, p, x, s, __VA_ARGS__)
18 +#define RexExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_REXUTIL, e, x, s, __VA_ARGS__)
19 +#define RexExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_REXUTIL, g, x, s, __VA_ARGS__)
20 +
21 //
22 // static globals
23 //
@@ -60,7 +75,7 @@ extern "C" HRESULT RexInitialize()
75 if (!vhfdi)
76 {
77 hr = E_FAIL;
63 - ExitOnFailure(hr, "failed to initialize cabinet.dll"); // TODO: put verf info in trace message here
78 + RexExitOnFailure(hr, "failed to initialize cabinet.dll"); // TODO: put verf info in trace message here
79 }
80
81 ::ZeroMemory(vrgffFileTable, sizeof(vrgffFileTable));
@@ -123,12 +138,12 @@ extern "C" HRESULT RexExtract(
138 // load the cabinet resource
139 //
140 hResInfo = ::FindResourceExA(NULL, RT_RCDATA, szResource, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
126 - ExitOnNullWithLastError(hResInfo, hr, "Failed to find resource.");
141 + RexExitOnNullWithLastError(hResInfo, hr, "Failed to find resource.");
142 //hResInfo = ::FindResourceW(NULL, wzResource, /*RT_RCDATA*/MAKEINTRESOURCEW(10));
143 //ExitOnNullWithLastError(hResInfo, hr, "failed to load resource info");
144
145 hRes = ::LoadResource(NULL, hResInfo);
131 - ExitOnNullWithLastError(hRes, hr, "failed to load resource");
146 + RexExitOnNullWithLastError(hRes, hr, "failed to load resource");
147
148 vcbRes = ::SizeofResource(NULL, hResInfo);
149 vpbRes = (const BYTE*)::LockResource(hRes);
@@ -140,11 +155,11 @@ extern "C" HRESULT RexExtract(
155 //
156 //if (!::WideCharToMultiByte(CP_ACP, 0, wzResource, -1, vszResource, countof(vszResource), NULL, NULL))
157 //{
143 - // ExitOnLastError(hr, "failed to convert cabinet resource name to ASCII: %ls", wzResource);
158 + // RexExitOnLastError(hr, "failed to convert cabinet resource name to ASCII: %ls", wzResource);
159 //}
160
161 hr = ::StringCchCopyA(vszResource, countof(vszResource), szResource);
147 - ExitOnFailure(hr, "Failed to copy resource name to global.");
162 + RexExitOnFailure(hr, "Failed to copy resource name to global.");
163
164 //
165 // iterate through files in cabinet extracting them to the callback function
@@ -193,7 +208,7 @@ static __callback INT_PTR FAR DIAMONDAPI RexOpen(__in_z char FAR *pszFile, int o
208 if ((oflag != (/*_O_BINARY*/ 0x8000 | /*_O_RDONLY*/ 0x0000)) || (pmode != (_S_IREAD | _S_IWRITE)))
209 {
210 hr = E_OUTOFMEMORY;
196 - ExitOnFailure(hr, "FDI asked for to create a scratch file, which is unusual");
211 + RexExitOnFailure(hr, "FDI asked for to create a scratch file, which is unusual");
212 }
213
214 // find an empty spot in the fake file table
@@ -209,7 +224,7 @@ static __callback INT_PTR FAR DIAMONDAPI RexOpen(__in_z char FAR *pszFile, int o
224 if (FILETABLESIZE <= i)
225 {
226 hr = E_OUTOFMEMORY;
212 - ExitOnFailure(hr, "File table exceeded");
227 + RexExitOnFailure(hr, "File table exceeded");
228 }
229
230 if (0 == lstrcmpA(vszResource, pszFile))
@@ -225,7 +240,7 @@ static __callback INT_PTR FAR DIAMONDAPI RexOpen(__in_z char FAR *pszFile, int o
240 hFile = ::CreateFileA(pszFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
241 if (INVALID_HANDLE_VALUE == hFile)
242 {
228 - ExitWithLastError(hr, "failed to open file: %s", pszFile);
243 + RexExitWithLastError(hr, "failed to open file: %s", pszFile);
244 }
245
246 vrgffFileTable[i].fUsed = TRUE;
@@ -267,7 +282,7 @@ static __callback UINT FAR DIAMONDAPI RexRead(INT_PTR hf, __out_bcount(cb) void
282
283 if (!::ReadFile(vrgffFileTable[hf].hFile, pv, cb, &cbRead, NULL))
284 {
270 - ExitWithLastError(hr, "failed to read during cabinet extraction");
285 + RexExitWithLastError(hr, "failed to read during cabinet extraction");
286 }
287 }
288
@@ -292,7 +307,7 @@ static __callback UINT FAR DIAMONDAPI RexWrite(INT_PTR hf, __in_bcount(cb) void
307 Assert(vrgffFileTable[hf].hFile && vrgffFileTable[hf].hFile != INVALID_HANDLE_VALUE);
308 if (!::WriteFile(reinterpret_cast<HANDLE>(vrgffFileTable[hf].hFile), pv, cb, &cbWrite, NULL))
309 {
295 - ExitWithLastError(hr, "failed to write during cabinet extraction");
310 + RexExitWithLastError(hr, "failed to write during cabinet extraction");
311 }
312
313 // call the writer callback if defined
@@ -333,7 +348,7 @@ static __callback long FAR DIAMONDAPI RexSeek(INT_PTR hf, long dist, int seektyp
348 default :
349 dwMoveMethod = 0;
350 hr = E_UNEXPECTED;
336 - ExitOnFailure(hr, "unexpected seektype in FDISeek(): %d", seektype);
351 + RexExitOnFailure(hr, "unexpected seektype in FDISeek(): %d", seektype);
352 }
353
354 if (MEMORY_FILE == vrgffFileTable[hf].fftType)
@@ -362,7 +377,7 @@ static __callback long FAR DIAMONDAPI RexSeek(INT_PTR hf, long dist, int seektyp
377 lMove = ::SetFilePointer(vrgffFileTable[hf].hFile, dist, NULL, dwMoveMethod);
378 if (0xFFFFFFFF == lMove)
379 {
365 - ExitWithLastError(hr, "failed to move file pointer %d bytes", dist);
380 + RexExitWithLastError(hr, "failed to move file pointer %d bytes", dist);
381 }
382 }
383
@@ -394,7 +409,7 @@ __callback int FAR DIAMONDAPI RexClose(INT_PTR hf)
409
410 if (!::CloseHandle(vrgffFileTable[hf].hFile))
411 {
397 - ExitWithLastError(hr, "failed to close file during cabinet extraction");
412 + RexExitWithLastError(hr, "failed to close file during cabinet extraction");
413 }
414
415 vrgffFileTable[hf].hFile = INVALID_HANDLE_VALUE;
@@ -440,7 +455,7 @@ static __callback INT_PTR DIAMONDAPI RexCallback(FDINOTIFICATIONTYPE iNotificati
455 sz = static_cast<LPCSTR>(pFDINotify->psz1);
456 if (!::MultiByteToWideChar(CP_ACP, 0, sz, -1, wz, countof(wz)))
457 {
443 - ExitWithLastError(hr, "failed to convert cabinet file id to unicode: %s", sz);
458 + RexExitWithLastError(hr, "failed to convert cabinet file id to unicode: %s", sz);
459 }
460
461 if (prcs->pfnProgress)
@@ -457,25 +472,25 @@ static __callback INT_PTR DIAMONDAPI RexCallback(FDINOTIFICATIONTYPE iNotificati
472 // get the created date for the resource in the cabinet
473 if (!::DosDateTimeToFileTime(pFDINotify->date, pFDINotify->time, &ft))
474 {
460 - ExitWithLastError(hr, "failed to get time for resource: %ls", wz);
475 + RexExitWithLastError(hr, "failed to get time for resource: %ls", wz);
476 }
477
478 WCHAR wzPath[MAX_PATH];
479
480 hr = ::StringCchCopyW(wzPath, countof(wzPath), prcs->pwzExtractDir);
466 - ExitOnFailure(hr, "failed to copy extract directory: %ls for file: %ls", prcs->pwzExtractDir, wz);
481 + RexExitOnFailure(hr, "failed to copy extract directory: %ls for file: %ls", prcs->pwzExtractDir, wz);
482
483 if (L'*' == *prcs->pwzExtract)
484 {
485 hr = ::StringCchCatW(wzPath, countof(wzPath), wz);
471 - ExitOnFailure(hr, "failed to concat onto path: %ls file: %ls", wzPath, wz);
486 + RexExitOnFailure(hr, "failed to concat onto path: %ls file: %ls", wzPath, wz);
487 }
488 else
489 {
490 Assert(*prcs->pwzExtractName);
491
492 hr = ::StringCchCatW(wzPath, countof(wzPath), prcs->pwzExtractName);
478 - ExitOnFailure(hr, "failed to concat onto path: %ls file: %ls", wzPath, prcs->pwzExtractName);
493 + RexExitOnFailure(hr, "failed to concat onto path: %ls file: %ls", wzPath, prcs->pwzExtractName);
494 }
495
496 // Quickly chop off the file name part of the path to ensure the path exists
@@ -486,7 +501,7 @@ static __callback INT_PTR DIAMONDAPI RexCallback(FDINOTIFICATIONTYPE iNotificati
501 *wzFile = L'\0';
502
503 hr = DirEnsureExists(wzPath, NULL);
489 - ExitOnFailure(hr, "failed to ensure directory: %ls", wzPath);
504 + RexExitOnFailure(hr, "failed to ensure directory: %ls", wzPath);
505
506 hr = S_OK;
507
@@ -505,14 +520,14 @@ static __callback INT_PTR DIAMONDAPI RexCallback(FDINOTIFICATIONTYPE iNotificati
520 if (FILETABLESIZE <= i)
521 {
522 hr = E_OUTOFMEMORY;
508 - ExitOnFailure(hr, "File table exceeded");
523 + RexExitOnFailure(hr, "File table exceeded");
524 }
525
526 // open the file
527 hFile = ::CreateFileW(wzPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
528 if (INVALID_HANDLE_VALUE == hFile)
529 {
515 - ExitWithLastError(hr, "failed to open file: %ls", wzPath);
530 + RexExitWithLastError(hr, "failed to open file: %ls", wzPath);
531 }
532
533 vrgffFileTable[i].fUsed = TRUE;
@@ -545,7 +560,7 @@ static __callback INT_PTR DIAMONDAPI RexCallback(FDINOTIFICATIONTYPE iNotificati
560 sz = static_cast<LPCSTR>(pFDINotify->psz1);
561 if (!::MultiByteToWideChar(CP_ACP, 0, sz, -1, wz, countof(wz)))
562 {
548 - ExitWithLastError(hr, "failed to convert cabinet file id to unicode: %s", sz);
563 + RexExitWithLastError(hr, "failed to convert cabinet file id to unicode: %s", sz);
564 }
565
566 RexClose(pFDINotify->hf);
src/dutil/rmutil.cpp
+39 -24
@@ -3,6 +3,21 @@
3 #include "precomp.h"
4 #include <restartmanager.h>
5
6 +
7 +// Exit macros
8 +#define RmExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_RMUTIL, x, s, __VA_ARGS__)
9 +#define RmExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_RMUTIL, x, s, __VA_ARGS__)
10 +#define RmExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_RMUTIL, x, s, __VA_ARGS__)
11 +#define RmExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_RMUTIL, x, s, __VA_ARGS__)
12 +#define RmExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_RMUTIL, x, s, __VA_ARGS__)
13 +#define RmExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_RMUTIL, x, s, __VA_ARGS__)
14 +#define RmExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_RMUTIL, p, x, e, s, __VA_ARGS__)
15 +#define RmExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_RMUTIL, p, x, s, __VA_ARGS__)
16 +#define RmExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_RMUTIL, p, x, e, s, __VA_ARGS__)
17 +#define RmExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_RMUTIL, p, x, s, __VA_ARGS__)
18 +#define RmExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_RMUTIL, e, x, s, __VA_ARGS__)
19 +#define RmExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_RMUTIL, g, x, s, __VA_ARGS__)
20 +
21 #define ARRAY_GROWTH_SIZE 5
22
23 typedef DWORD (WINAPI *PFNRMJOINSESSION)(
@@ -80,13 +95,13 @@ extern "C" HRESULT DAPI RmuJoinSession(
95 *ppSession = NULL;
96
97 pSession = static_cast<PRMU_SESSION>(MemAlloc(sizeof(RMU_SESSION), TRUE));
83 - ExitOnNull(pSession, hr, E_OUTOFMEMORY, "Failed to allocate the RMU_SESSION structure.");
98 + RmExitOnNull(pSession, hr, E_OUTOFMEMORY, "Failed to allocate the RMU_SESSION structure.");
99
100 hr = RmuInitialize();
86 - ExitOnFailure(hr, "Failed to initialize Restart Manager.");
101 + RmExitOnFailure(hr, "Failed to initialize Restart Manager.");
102
103 er = vpfnRmJoinSession(&pSession->dwSessionHandle, wzSessionKey);
89 - ExitOnWin32Error(er, hr, "Failed to join Restart Manager session %ls.", wzSessionKey);
104 + RmExitOnWin32Error(er, hr, "Failed to join Restart Manager session %ls.", wzSessionKey);
105
106 ::InitializeCriticalSection(&pSession->cs);
107 pSession->fInitialized = TRUE;
@@ -120,7 +135,7 @@ extern "C" HRESULT DAPI RmuAddFile(
135
136 // Create or grow the jagged array.
137 hr = StrArrayAllocString(&pSession->rgsczFilenames, &pSession->cFilenames, wzPath, 0);
123 - ExitOnFailure(hr, "Failed to add the filename to the array.");
138 + RmExitOnFailure(hr, "Failed to add the filename to the array.");
139
140 LExit:
141 ::LeaveCriticalSection(&pSession->cs);
@@ -161,29 +176,29 @@ extern "C" HRESULT DAPI RmuAddProcessById(
176 // Adding SeDebugPrivilege in the event that the process targeted by ::OpenProcess() is in a another user context.
177 if (!::OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, &hToken))
178 {
164 - ExitWithLastError(hr, "Failed to get process token.");
179 + RmExitWithLastError(hr, "Failed to get process token.");
180 }
181
182 priv.PrivilegeCount = 1;
183 priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
184 if (!::LookupPrivilegeValueW(NULL, L"SeDebugPrivilege", &priv.Privileges[0].Luid))
185 {
171 - ExitWithLastError(hr, "Failed to get debug privilege LUID.");
186 + RmExitWithLastError(hr, "Failed to get debug privilege LUID.");
187 }
188
189 cbPrevPriv = sizeof(TOKEN_PRIVILEGES);
190 pPrevPriv = static_cast<TOKEN_PRIVILEGES*>(MemAlloc(cbPrevPriv, TRUE));
176 - ExitOnNull(pPrevPriv, hr, E_OUTOFMEMORY, "Failed to allocate memory for empty previous privileges.");
191 + RmExitOnNull(pPrevPriv, hr, E_OUTOFMEMORY, "Failed to allocate memory for empty previous privileges.");
192
193 if (!::AdjustTokenPrivileges(hToken, FALSE, &priv, cbPrevPriv, pPrevPriv, &cbPrevPriv))
194 {
195 LPVOID pv = MemReAlloc(pPrevPriv, cbPrevPriv, TRUE);
181 - ExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to allocate memory for previous privileges.");
196 + RmExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to allocate memory for previous privileges.");
197 pPrevPriv = static_cast<TOKEN_PRIVILEGES*>(pv);
198
199 if (!::AdjustTokenPrivileges(hToken, FALSE, &priv, cbPrevPriv, pPrevPriv, &cbPrevPriv))
200 {
186 - ExitWithLastError(hr, "Failed to get debug privilege LUID.");
201 + RmExitWithLastError(hr, "Failed to get debug privilege LUID.");
202 }
203 }
204
@@ -195,13 +210,13 @@ extern "C" HRESULT DAPI RmuAddProcessById(
210 {
211 if (!::GetProcessTimes(hProcess, &CreationTime, &ExitTime, &KernelTime, &UserTime))
212 {
198 - ExitWithLastError(hr, "Failed to get the process times for process ID %d.", dwProcessId);
213 + RmExitWithLastError(hr, "Failed to get the process times for process ID %d.", dwProcessId);
214 }
215
216 ::EnterCriticalSection(&pSession->cs);
217 fLocked = TRUE;
218 hr = RmuApplicationArrayAlloc(&pSession->rgApplications, &pSession->cApplications, dwProcessId, CreationTime);
204 - ExitOnFailure(hr, "Failed to add the application to the array.");
219 + RmExitOnFailure(hr, "Failed to add the application to the array.");
220 }
221 else
222 {
@@ -213,7 +228,7 @@ extern "C" HRESULT DAPI RmuAddProcessById(
228 }
229 else
230 {
216 - ExitOnWin32Error(er, hr, "Failed to open the process ID %d.", dwProcessId);
231 + RmExitOnWin32Error(er, hr, "Failed to open the process ID %d.", dwProcessId);
232 }
233 }
234
@@ -258,7 +273,7 @@ extern "C" HRESULT DAPI RmuAddProcessesByName(
273 BOOL fNotFound = FALSE;
274
275 hr = ProcFindAllIdsFromExeName(wzProcessName, &pdwProcessIds, &cProcessIds);
261 - ExitOnFailure(hr, "Failed to enumerate all the processes by name %ls.", wzProcessName);
276 + RmExitOnFailure(hr, "Failed to enumerate all the processes by name %ls.", wzProcessName);
277
278 for (DWORD i = 0; i < cProcessIds; ++i)
279 {
@@ -270,7 +285,7 @@ extern "C" HRESULT DAPI RmuAddProcessesByName(
285 }
286 else
287 {
273 - ExitOnFailure(hr, "Failed to add process %ls (%d) to the Restart Manager session.", wzProcessName, pdwProcessIds[i]);
288 + RmExitOnFailure(hr, "Failed to add process %ls (%d) to the Restart Manager session.", wzProcessName, pdwProcessIds[i]);
289 }
290 }
291
@@ -303,7 +318,7 @@ extern "C" HRESULT DAPI RmuAddService(
318 ::EnterCriticalSection(&pSession->cs);
319
320 hr = StrArrayAllocString(&pSession->rgsczServiceNames, &pSession->cServiceNames, wzServiceName, 0);
306 - ExitOnFailure(hr, "Failed to add the service name to the array.");
321 + RmExitOnFailure(hr, "Failed to add the service name to the array.");
322
323 LExit:
324 ::LeaveCriticalSection(&pSession->cs);
@@ -341,7 +356,7 @@ extern "C" HRESULT DAPI RmuRegisterResources(
356 pSession->cServiceNames,
357 pSession->rgsczServiceNames
358 );
344 - ExitOnWin32Error(er, hr, "Failed to register the resources with the Restart Manager session.");
359 + RmExitOnWin32Error(er, hr, "Failed to register the resources with the Restart Manager session.");
360
361 // Empty the arrays if registered in case additional resources are added later.
362 ReleaseNullStrArray(pSession->rgsczFilenames, pSession->cFilenames);
@@ -373,11 +388,11 @@ extern "C" HRESULT DAPI RmuEndSession(
388 if (!pSession->fStartedSessionHandle)
389 {
390 hr = RmuRegisterResources(pSession);
376 - ExitOnFailure(hr, "Failed to register remaining resources.");
391 + RmExitOnFailure(hr, "Failed to register remaining resources.");
392 }
393
394 er = vpfnRmEndSession(pSession->dwSessionHandle);
380 - ExitOnWin32Error(er, hr, "Failed to end the Restart Manager session.");
395 + RmExitOnWin32Error(er, hr, "Failed to end the Restart Manager session.");
396
397 LExit:
398 if (pSession->fInitialized)
@@ -404,16 +419,16 @@ static HRESULT RmuInitialize()
419 if (1 == iRef && !vhModule)
420 {
421 hr = LoadSystemLibrary(L"rstrtmgr.dll", &hModule);
407 - ExitOnFailure(hr, "Failed to load the rstrtmgr.dll module.");
422 + RmExitOnFailure(hr, "Failed to load the rstrtmgr.dll module.");
423
424 vpfnRmJoinSession = reinterpret_cast<PFNRMJOINSESSION>(::GetProcAddress(hModule, "RmJoinSession"));
410 - ExitOnNullWithLastError(vpfnRmJoinSession, hr, "Failed to get the RmJoinSession procedure from rstrtmgr.dll.");
425 + RmExitOnNullWithLastError(vpfnRmJoinSession, hr, "Failed to get the RmJoinSession procedure from rstrtmgr.dll.");
426
427 vpfnRmRegisterResources = reinterpret_cast<PFNRMREGISTERRESOURCES>(::GetProcAddress(hModule, "RmRegisterResources"));
413 - ExitOnNullWithLastError(vpfnRmRegisterResources, hr, "Failed to get the RmRegisterResources procedure from rstrtmgr.dll.");
428 + RmExitOnNullWithLastError(vpfnRmRegisterResources, hr, "Failed to get the RmRegisterResources procedure from rstrtmgr.dll.");
429
430 vpfnRmEndSession = reinterpret_cast<PFNRMENDSESSION>(::GetProcAddress(hModule, "RmEndSession"));
416 - ExitOnNullWithLastError(vpfnRmEndSession, hr, "Failed to get the RmEndSession procedure from rstrtmgr.dll.");
431 + RmExitOnNullWithLastError(vpfnRmEndSession, hr, "Failed to get the RmEndSession procedure from rstrtmgr.dll.");
432
433 vhModule = hModule;
434 }
@@ -447,7 +462,7 @@ static HRESULT RmuApplicationArrayAlloc(
462 RM_UNIQUE_PROCESS *pApplication = NULL;
463
464 hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(prgApplications), *pcApplications + 1, sizeof(RM_UNIQUE_PROCESS), ARRAY_GROWTH_SIZE);
450 - ExitOnFailure(hr, "Failed to allocate memory for the application array.");
465 + RmExitOnFailure(hr, "Failed to allocate memory for the application array.");
466
467 pApplication = static_cast<RM_UNIQUE_PROCESS*>(&(*prgApplications)[*pcApplications]);
468 pApplication->dwProcessId = dwProcessId;
@@ -466,7 +481,7 @@ static HRESULT RmuApplicationArrayFree(
481 HRESULT hr = S_OK;
482
483 hr = MemFree(rgApplications);
469 - ExitOnFailure(hr, "Failed to free memory for the application array.");
484 + RmExitOnFailure(hr, "Failed to free memory for the application array.");
485
486 LExit:
487 return hr;
src/dutil/rssutil.cpp
+70 -55
@@ -2,6 +2,21 @@
2
3 #include "precomp.h"
4
5 +
6 +// Exit macros
7 +#define RssExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_RSSUTIL, x, s, __VA_ARGS__)
8 +#define RssExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_RSSUTIL, x, s, __VA_ARGS__)
9 +#define RssExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_RSSUTIL, x, s, __VA_ARGS__)
10 +#define RssExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_RSSUTIL, x, s, __VA_ARGS__)
11 +#define RssExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_RSSUTIL, x, s, __VA_ARGS__)
12 +#define RssExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_RSSUTIL, x, s, __VA_ARGS__)
13 +#define RssExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_RSSUTIL, p, x, e, s, __VA_ARGS__)
14 +#define RssExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_RSSUTIL, p, x, s, __VA_ARGS__)
15 +#define RssExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_RSSUTIL, p, x, e, s, __VA_ARGS__)
16 +#define RssExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_RSSUTIL, p, x, s, __VA_ARGS__)
17 +#define RssExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_RSSUTIL, e, x, s, __VA_ARGS__)
18 +#define RssExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_RSSUTIL, g, x, s, __VA_ARGS__)
19 +
20 static HRESULT ParseRssDocument(
21 __in IXMLDOMDocument *pixd,
22 __out RSS_CHANNEL **ppChannel
@@ -68,10 +83,10 @@ extern "C" HRESULT DAPI RssParseFromString(
83 IXMLDOMDocument *pixdRss = NULL;
84
85 hr = XmlLoadDocument(wzRssString, &pixdRss);
71 - ExitOnFailure(hr, "Failed to load RSS string as XML document.");
86 + RssExitOnFailure(hr, "Failed to load RSS string as XML document.");
87
88 hr = ParseRssDocument(pixdRss, &pNewChannel);
74 - ExitOnFailure(hr, "Failed to parse RSS document.");
89 + RssExitOnFailure(hr, "Failed to parse RSS document.");
90
91 *ppChannel = pNewChannel;
92 pNewChannel = NULL;
@@ -102,10 +117,10 @@ extern "C" HRESULT DAPI RssParseFromFile(
117 IXMLDOMDocument *pixdRss = NULL;
118
119 hr = XmlLoadDocumentFromFile(wzRssFile, &pixdRss);
105 - ExitOnFailure(hr, "Failed to load RSS string as XML document.");
120 + RssExitOnFailure(hr, "Failed to load RSS string as XML document.");
121
122 hr = ParseRssDocument(pixdRss, &pNewChannel);
108 - ExitOnFailure(hr, "Failed to parse RSS document.");
123 + RssExitOnFailure(hr, "Failed to parse RSS document.");
124
125 *ppChannel = pNewChannel;
126 pNewChannel = NULL;
@@ -175,17 +190,17 @@ static HRESULT ParseRssDocument(
190 // Get the document element and start processing channels.
191 //
192 hr = pixd ->get_documentElement(&pRssElement);
178 - ExitOnFailure(hr, "failed get_documentElement in ParseRssDocument");
193 + RssExitOnFailure(hr, "failed get_documentElement in ParseRssDocument");
194
195 hr = pRssElement->get_childNodes(&pChannelNodes);
181 - ExitOnFailure(hr, "Failed to get child nodes of Rss Document element.");
196 + RssExitOnFailure(hr, "Failed to get child nodes of Rss Document element.");
197
198 while (S_OK == (hr = XmlNextElement(pChannelNodes, &pNode, &bstrNodeName)))
199 {
200 if (0 == lstrcmpW(bstrNodeName, L"channel"))
201 {
202 hr = ParseRssChannel(pNode, &pNewChannel);
188 - ExitOnFailure(hr, "Failed to parse RSS channel.");
203 + RssExitOnFailure(hr, "Failed to parse RSS channel.");
204 }
205 else if (0 == lstrcmpW(bstrNodeName, L"link"))
206 {
@@ -242,13 +257,13 @@ static HRESULT ParseRssChannel(
257 // the RSS_CHANNEL structure
258 //
259 hr = XmlSelectNodes(pixnChannel, L"item", &pNodeList);
245 - ExitOnFailure(hr, "Failed to select all RSS items in an RSS channel.");
260 + RssExitOnFailure(hr, "Failed to select all RSS items in an RSS channel.");
261
262 hr = pNodeList->get_length(&cItems);
248 - ExitOnFailure(hr, "Failed to count the number of RSS items in RSS channel.");
263 + RssExitOnFailure(hr, "Failed to count the number of RSS items in RSS channel.");
264
265 pNewChannel = static_cast<RSS_CHANNEL*>(MemAlloc(sizeof(RSS_CHANNEL) + sizeof(RSS_ITEM) * cItems, TRUE));
251 - ExitOnNull(pNewChannel, hr, E_OUTOFMEMORY, "Failed to allocate RSS channel structure.");
266 + RssExitOnNull(pNewChannel, hr, E_OUTOFMEMORY, "Failed to allocate RSS channel structure.");
267
268 pNewChannel->cItems = cItems;
269
@@ -256,7 +271,7 @@ static HRESULT ParseRssChannel(
271 // Process the elements under a channel now.
272 //
273 hr = pixnChannel->get_childNodes(&pNodeList);
259 - ExitOnFailure(hr, "Failed to get child nodes of RSS channel element.");
274 + RssExitOnFailure(hr, "Failed to get child nodes of RSS channel element.");
275
276 cItems = 0; // reset the counter and use this to walk through the channel items
277 while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, &bstrNodeName)))
@@ -264,45 +279,45 @@ static HRESULT ParseRssChannel(
279 if (0 == lstrcmpW(bstrNodeName, L"title"))
280 {
281 hr = XmlGetText(pNode, &bstrNodeValue);
267 - ExitOnFailure(hr, "Failed to get RSS channel title.");
282 + RssExitOnFailure(hr, "Failed to get RSS channel title.");
283
284 hr = StrAllocString(&pNewChannel->wzTitle, bstrNodeValue, 0);
270 - ExitOnFailure(hr, "Failed to allocate RSS channel title.");
285 + RssExitOnFailure(hr, "Failed to allocate RSS channel title.");
286 }
287 else if (0 == lstrcmpW(bstrNodeName, L"link"))
288 {
289 hr = XmlGetText(pNode, &bstrNodeValue);
275 - ExitOnFailure(hr, "Failed to get RSS channel link.");
290 + RssExitOnFailure(hr, "Failed to get RSS channel link.");
291
292 hr = StrAllocString(&pNewChannel->wzLink, bstrNodeValue, 0);
278 - ExitOnFailure(hr, "Failed to allocate RSS channel link.");
293 + RssExitOnFailure(hr, "Failed to allocate RSS channel link.");
294 }
295 else if (0 == lstrcmpW(bstrNodeName, L"description"))
296 {
297 hr = XmlGetText(pNode, &bstrNodeValue);
283 - ExitOnFailure(hr, "Failed to get RSS channel description.");
298 + RssExitOnFailure(hr, "Failed to get RSS channel description.");
299
300 hr = StrAllocString(&pNewChannel->wzDescription, bstrNodeValue, 0);
286 - ExitOnFailure(hr, "Failed to allocate RSS channel description.");
301 + RssExitOnFailure(hr, "Failed to allocate RSS channel description.");
302 }
303 else if (0 == lstrcmpW(bstrNodeName, L"ttl"))
304 {
305 hr = XmlGetText(pNode, &bstrNodeValue);
291 - ExitOnFailure(hr, "Failed to get RSS channel description.");
306 + RssExitOnFailure(hr, "Failed to get RSS channel description.");
307
308 pNewChannel->dwTimeToLive = (DWORD)wcstoul(bstrNodeValue, NULL, 10);
309 }
310 else if (0 == lstrcmpW(bstrNodeName, L"item"))
311 {
312 hr = ParseRssItem(pNode, cItems, pNewChannel);
298 - ExitOnFailure(hr, "Failed to parse RSS item.");
313 + RssExitOnFailure(hr, "Failed to parse RSS item.");
314
315 ++cItems;
316 }
317 else
318 {
319 hr = ParseRssUnknownElement(pNode, &pNewChannel->pUnknownElements);
305 - ExitOnFailure(hr, "Failed to parse unknown RSS channel element: %ls", bstrNodeName);
320 + RssExitOnFailure(hr, "Failed to parse unknown RSS channel element: %ls", bstrNodeName);
321 }
322
323 ReleaseNullBSTR(bstrNodeValue);
@@ -349,7 +364,7 @@ static HRESULT ParseRssItem(
364 if (pChannel->cItems <= cItem)
365 {
366 hr = E_UNEXPECTED;
352 - ExitOnFailure(hr, "Unexpected number of items parsed.");
367 + RssExitOnFailure(hr, "Unexpected number of items parsed.");
368 }
369
370 pItem = pChannel->rgItems + cItem;
@@ -358,71 +373,71 @@ static HRESULT ParseRssItem(
373 // Process the elements under an item now.
374 //
375 hr = pixnItem->get_childNodes(&pNodeList);
361 - ExitOnFailure(hr, "Failed to get child nodes of RSS item element.");
376 + RssExitOnFailure(hr, "Failed to get child nodes of RSS item element.");
377 while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, &bstrNodeName)))
378 {
379 if (0 == lstrcmpW(bstrNodeName, L"title"))
380 {
381 hr = XmlGetText(pNode, &bstrNodeValue);
367 - ExitOnFailure(hr, "Failed to get RSS channel title.");
382 + RssExitOnFailure(hr, "Failed to get RSS channel title.");
383
384 hr = StrAllocString(&pItem->wzTitle, bstrNodeValue, 0);
370 - ExitOnFailure(hr, "Failed to allocate RSS item title.");
385 + RssExitOnFailure(hr, "Failed to allocate RSS item title.");
386 }
387 else if (0 == lstrcmpW(bstrNodeName, L"link"))
388 {
389 hr = XmlGetText(pNode, &bstrNodeValue);
375 - ExitOnFailure(hr, "Failed to get RSS channel link.");
390 + RssExitOnFailure(hr, "Failed to get RSS channel link.");
391
392 hr = StrAllocString(&pItem->wzLink, bstrNodeValue, 0);
378 - ExitOnFailure(hr, "Failed to allocate RSS item link.");
393 + RssExitOnFailure(hr, "Failed to allocate RSS item link.");
394 }
395 else if (0 == lstrcmpW(bstrNodeName, L"description"))
396 {
397 hr = XmlGetText(pNode, &bstrNodeValue);
383 - ExitOnFailure(hr, "Failed to get RSS item description.");
398 + RssExitOnFailure(hr, "Failed to get RSS item description.");
399
400 hr = StrAllocString(&pItem->wzDescription, bstrNodeValue, 0);
386 - ExitOnFailure(hr, "Failed to allocate RSS item description.");
401 + RssExitOnFailure(hr, "Failed to allocate RSS item description.");
402 }
403 else if (0 == lstrcmpW(bstrNodeName, L"guid"))
404 {
405 hr = XmlGetText(pNode, &bstrNodeValue);
391 - ExitOnFailure(hr, "Failed to get RSS item guid.");
406 + RssExitOnFailure(hr, "Failed to get RSS item guid.");
407
408 hr = StrAllocString(&pItem->wzGuid, bstrNodeValue, 0);
394 - ExitOnFailure(hr, "Failed to allocate RSS item guid.");
409 + RssExitOnFailure(hr, "Failed to allocate RSS item guid.");
410 }
411 else if (0 == lstrcmpW(bstrNodeName, L"pubDate"))
412 {
413 hr = XmlGetText(pNode, &bstrNodeValue);
399 - ExitOnFailure(hr, "Failed to get RSS item guid.");
414 + RssExitOnFailure(hr, "Failed to get RSS item guid.");
415
416 hr = TimeFromString(bstrNodeValue, &pItem->ftPublished);
402 - ExitOnFailure(hr, "Failed to convert RSS item time.");
417 + RssExitOnFailure(hr, "Failed to convert RSS item time.");
418 }
419 else if (0 == lstrcmpW(bstrNodeName, L"enclosure"))
420 {
421 hr = XmlGetAttribute(pNode, L"url", &bstrNodeValue);
407 - ExitOnFailure(hr, "Failed to get RSS item enclosure url.");
422 + RssExitOnFailure(hr, "Failed to get RSS item enclosure url.");
423
424 hr = StrAllocString(&pItem->wzEnclosureUrl, bstrNodeValue, 0);
410 - ExitOnFailure(hr, "Failed to allocate RSS item enclosure url.");
425 + RssExitOnFailure(hr, "Failed to allocate RSS item enclosure url.");
426 ReleaseNullBSTR(bstrNodeValue);
427
428 hr = XmlGetAttributeNumber(pNode, L"length", &pItem->dwEnclosureSize);
414 - ExitOnFailure(hr, "Failed to get RSS item enclosure length.");
429 + RssExitOnFailure(hr, "Failed to get RSS item enclosure length.");
430
431 hr = XmlGetAttribute(pNode, L"type", &bstrNodeValue);
417 - ExitOnFailure(hr, "Failed to get RSS item enclosure type.");
432 + RssExitOnFailure(hr, "Failed to get RSS item enclosure type.");
433
434 hr = StrAllocString(&pItem->wzEnclosureType, bstrNodeValue, 0);
420 - ExitOnFailure(hr, "Failed to allocate RSS item enclosure type.");
435 + RssExitOnFailure(hr, "Failed to allocate RSS item enclosure type.");
436 }
437 else
438 {
439 hr = ParseRssUnknownElement(pNode, &pItem->pUnknownElements);
425 - ExitOnFailure(hr, "Failed to parse unknown RSS item element: %ls", bstrNodeName);
440 + RssExitOnFailure(hr, "Failed to parse unknown RSS item element: %ls", bstrNodeName);
441 }
442
443 ReleaseNullBSTR(bstrNodeValue);
@@ -460,39 +475,39 @@ static HRESULT ParseRssUnknownElement(
475 RSS_UNKNOWN_ELEMENT* pNewUnknownElement;
476
477 pNewUnknownElement = static_cast<RSS_UNKNOWN_ELEMENT*>(MemAlloc(sizeof(RSS_UNKNOWN_ELEMENT), TRUE));
463 - ExitOnNull(pNewUnknownElement, hr, E_OUTOFMEMORY, "Failed to allocate unknown element.");
478 + RssExitOnNull(pNewUnknownElement, hr, E_OUTOFMEMORY, "Failed to allocate unknown element.");
479
480 hr = pNode->get_namespaceURI(&bstrNodeNamespace);
481 if (S_OK == hr)
482 {
483 hr = StrAllocString(&pNewUnknownElement->wzNamespace, bstrNodeNamespace, 0);
469 - ExitOnFailure(hr, "Failed to allocate RSS unknown element namespace.");
484 + RssExitOnFailure(hr, "Failed to allocate RSS unknown element namespace.");
485 }
486 else if (S_FALSE == hr)
487 {
488 hr = S_OK;
489 }
475 - ExitOnFailure(hr, "Failed to get unknown element namespace.");
490 + RssExitOnFailure(hr, "Failed to get unknown element namespace.");
491
492 hr = pNode->get_baseName(&bstrNodeName);
478 - ExitOnFailure(hr, "Failed to get unknown element name.");
493 + RssExitOnFailure(hr, "Failed to get unknown element name.");
494
495 hr = StrAllocString(&pNewUnknownElement->wzElement, bstrNodeName, 0);
481 - ExitOnFailure(hr, "Failed to allocate RSS unknown element name.");
496 + RssExitOnFailure(hr, "Failed to allocate RSS unknown element name.");
497
498 hr = XmlGetText(pNode, &bstrNodeValue);
484 - ExitOnFailure(hr, "Failed to get unknown element value.");
499 + RssExitOnFailure(hr, "Failed to get unknown element value.");
500
501 hr = StrAllocString(&pNewUnknownElement->wzValue, bstrNodeValue, 0);
487 - ExitOnFailure(hr, "Failed to allocate RSS unknown element value.");
502 + RssExitOnFailure(hr, "Failed to allocate RSS unknown element value.");
503
504 hr = pNode->get_attributes(&pixnnmAttributes);
490 - ExitOnFailure(hr, "Failed get attributes on RSS unknown element.");
505 + RssExitOnFailure(hr, "Failed get attributes on RSS unknown element.");
506
507 while (S_OK == (hr = pixnnmAttributes->nextNode(&pixnAttribute)))
508 {
509 hr = ParseRssUnknownAttribute(pixnAttribute, &pNewUnknownElement->pAttributes);
495 - ExitOnFailure(hr, "Failed to parse attribute on RSS unknown element.");
510 + RssExitOnFailure(hr, "Failed to parse attribute on RSS unknown element.");
511
512 ReleaseNullObject(pixnAttribute);
513 }
@@ -501,7 +516,7 @@ static HRESULT ParseRssUnknownElement(
516 {
517 hr = S_OK;
518 }
504 - ExitOnFailure(hr, "Failed to enumerate all attributes on RSS unknown element.");
519 + RssExitOnFailure(hr, "Failed to enumerate all attributes on RSS unknown element.");
520
521 RSS_UNKNOWN_ELEMENT** ppTail = ppUnknownElement;
522 while (*ppTail)
@@ -543,31 +558,31 @@ static HRESULT ParseRssUnknownAttribute(
558 RSS_UNKNOWN_ATTRIBUTE* pNewUnknownAttribute;
559
560 pNewUnknownAttribute = static_cast<RSS_UNKNOWN_ATTRIBUTE*>(MemAlloc(sizeof(RSS_UNKNOWN_ATTRIBUTE), TRUE));
546 - ExitOnNull(pNewUnknownAttribute, hr, E_OUTOFMEMORY, "Failed to allocate unknown attribute.");
561 + RssExitOnNull(pNewUnknownAttribute, hr, E_OUTOFMEMORY, "Failed to allocate unknown attribute.");
562
563 hr = pNode->get_namespaceURI(&bstrNodeNamespace);
564 if (S_OK == hr)
565 {
566 hr = StrAllocString(&pNewUnknownAttribute->wzNamespace, bstrNodeNamespace, 0);
552 - ExitOnFailure(hr, "Failed to allocate RSS unknown attribute namespace.");
567 + RssExitOnFailure(hr, "Failed to allocate RSS unknown attribute namespace.");
568 }
569 else if (S_FALSE == hr)
570 {
571 hr = S_OK;
572 }
558 - ExitOnFailure(hr, "Failed to get unknown attribute namespace.");
573 + RssExitOnFailure(hr, "Failed to get unknown attribute namespace.");
574
575 hr = pNode->get_baseName(&bstrNodeName);
561 - ExitOnFailure(hr, "Failed to get unknown attribute name.");
576 + RssExitOnFailure(hr, "Failed to get unknown attribute name.");
577
578 hr = StrAllocString(&pNewUnknownAttribute->wzAttribute, bstrNodeName, 0);
564 - ExitOnFailure(hr, "Failed to allocate RSS unknown attribute name.");
579 + RssExitOnFailure(hr, "Failed to allocate RSS unknown attribute name.");
580
581 hr = XmlGetText(pNode, &bstrNodeValue);
567 - ExitOnFailure(hr, "Failed to get unknown attribute value.");
582 + RssExitOnFailure(hr, "Failed to get unknown attribute value.");
583
584 hr = StrAllocString(&pNewUnknownAttribute->wzValue, bstrNodeValue, 0);
570 - ExitOnFailure(hr, "Failed to allocate RSS unknown attribute value.");
585 + RssExitOnFailure(hr, "Failed to allocate RSS unknown attribute value.");
586
587 RSS_UNKNOWN_ATTRIBUTE** ppTail = ppUnknownAttribute;
588 while (*ppTail)
src/dutil/shelutil.cpp
+42 -27
@@ -2,6 +2,21 @@
2
3 #include "precomp.h"
4
5 +
6 +// Exit macros
7 +#define ShelExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_SHELUTIL, x, s, __VA_ARGS__)
8 +#define ShelExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_SHELUTIL, x, s, __VA_ARGS__)
9 +#define ShelExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_SHELUTIL, x, s, __VA_ARGS__)
10 +#define ShelExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_SHELUTIL, x, s, __VA_ARGS__)
11 +#define ShelExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_SHELUTIL, x, s, __VA_ARGS__)
12 +#define ShelExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_SHELUTIL, x, s, __VA_ARGS__)
13 +#define ShelExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_SHELUTIL, p, x, e, s, __VA_ARGS__)
14 +#define ShelExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_SHELUTIL, p, x, s, __VA_ARGS__)
15 +#define ShelExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_SHELUTIL, p, x, e, s, __VA_ARGS__)
16 +#define ShelExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_SHELUTIL, p, x, s, __VA_ARGS__)
17 +#define ShelExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_SHELUTIL, e, x, s, __VA_ARGS__)
18 +#define ShelExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_SHELUTIL, g, x, s, __VA_ARGS__)
19 +
20 static PFN_SHELLEXECUTEEXW vpfnShellExecuteExW = ::ShellExecuteExW;
21
22 static HRESULT GetDesktopShellView(
@@ -55,7 +70,7 @@ extern "C" HRESULT DAPI ShelExec(
70
71 if (!vpfnShellExecuteExW(&shExecInfo))
72 {
58 - ExitWithLastError(hr, "ShellExecEx failed with return code: %d", Dutil_er);
73 + ShelExitWithLastError(hr, "ShellExecEx failed with return code: %d", Dutil_er);
74 }
75
76 if (phProcess)
@@ -93,44 +108,44 @@ extern "C" HRESULT DAPI ShelExecUnelevated(
108 IShellDispatch2* psd = NULL;
109
110 bstrTargetPath = ::SysAllocString(wzTargetPath);
96 - ExitOnNull(bstrTargetPath, hr, E_OUTOFMEMORY, "Failed to allocate target path BSTR.");
111 + ShelExitOnNull(bstrTargetPath, hr, E_OUTOFMEMORY, "Failed to allocate target path BSTR.");
112
113 if (wzParameters && *wzParameters)
114 {
115 vtParameters.vt = VT_BSTR;
116 vtParameters.bstrVal = ::SysAllocString(wzParameters);
102 - ExitOnNull(bstrTargetPath, hr, E_OUTOFMEMORY, "Failed to allocate parameters BSTR.");
117 + ShelExitOnNull(bstrTargetPath, hr, E_OUTOFMEMORY, "Failed to allocate parameters BSTR.");
118 }
119
120 if (wzVerb && *wzVerb)
121 {
122 vtVerb.vt = VT_BSTR;
123 vtVerb.bstrVal = ::SysAllocString(wzVerb);
109 - ExitOnNull(bstrTargetPath, hr, E_OUTOFMEMORY, "Failed to allocate verb BSTR.");
124 + ShelExitOnNull(bstrTargetPath, hr, E_OUTOFMEMORY, "Failed to allocate verb BSTR.");
125 }
126
127 if (wzWorkingDirectory && *wzWorkingDirectory)
128 {
129 vtWorkingDirectory.vt = VT_BSTR;
130 vtWorkingDirectory.bstrVal = ::SysAllocString(wzWorkingDirectory);
116 - ExitOnNull(bstrTargetPath, hr, E_OUTOFMEMORY, "Failed to allocate working directory BSTR.");
131 + ShelExitOnNull(bstrTargetPath, hr, E_OUTOFMEMORY, "Failed to allocate working directory BSTR.");
132 }
133
134 vtShow.vt = VT_INT;
135 vtShow.intVal = nShowCmd;
136
137 hr = GetDesktopShellView(IID_PPV_ARGS(&psv));
123 - ExitOnFailure(hr, "Failed to get desktop shell view.");
138 + ShelExitOnFailure(hr, "Failed to get desktop shell view.");
139
140 hr = GetShellDispatchFromView(psv, IID_PPV_ARGS(&psd));
126 - ExitOnFailure(hr, "Failed to get shell dispatch from view.");
141 + ShelExitOnFailure(hr, "Failed to get shell dispatch from view.");
142
143 hr = psd->ShellExecute(bstrTargetPath, vtParameters, vtWorkingDirectory, vtVerb, vtShow);
144 if (S_FALSE == hr)
145 {
146 hr = HRESULT_FROM_WIN32(ERROR_CANCELLED);
147 }
133 - ExitOnRootFailure(hr, "Failed to launch unelevate executable: %ls", bstrTargetPath);
148 + ShelExitOnRootFailure(hr, "Failed to launch unelevate executable: %ls", bstrTargetPath);
149
150 LExit:
151 ReleaseObject(psd);
@@ -157,13 +172,13 @@ extern "C" HRESULT DAPI ShelGetFolder(
172 WCHAR wzPath[MAX_PATH];
173
174 hr = ::SHGetFolderPathW(NULL, csidlFolder | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, wzPath);
160 - ExitOnFailure(hr, "Failed to get folder path for CSIDL: %d", csidlFolder);
175 + ShelExitOnFailure(hr, "Failed to get folder path for CSIDL: %d", csidlFolder);
176
177 hr = StrAllocString(psczFolderPath, wzPath, 0);
163 - ExitOnFailure(hr, "Failed to copy shell folder path: %ls", wzPath);
178 + ShelExitOnFailure(hr, "Failed to copy shell folder path: %ls", wzPath);
179
180 hr = PathBackslashTerminate(psczFolderPath);
166 - ExitOnFailure(hr, "Failed to backslash terminate shell folder path: %ls", *psczFolderPath);
181 + ShelExitOnFailure(hr, "Failed to backslash terminate shell folder path: %ls", *psczFolderPath);
182
183 LExit:
184 return hr;
@@ -206,19 +221,19 @@ extern "C" HRESULT DAPI ShelGetKnownFolder(
221 TraceError(hr, "Failed to load shell32.dll");
222 ExitFunction1(hr = E_NOTIMPL);
223 }
209 - ExitOnFailure(hr, "Failed to load shell32.dll.");
224 + ShelExitOnFailure(hr, "Failed to load shell32.dll.");
225
226 pfn = reinterpret_cast<PFN_SHGetKnownFolderPath>(::GetProcAddress(hShell32Dll, "SHGetKnownFolderPath"));
212 - ExitOnNull(pfn, hr, E_NOTIMPL, "Failed to find SHGetKnownFolderPath entry point.");
227 + ShelExitOnNull(pfn, hr, E_NOTIMPL, "Failed to find SHGetKnownFolderPath entry point.");
228
229 hr = pfn(rfidFolder, KF_FLAG_CREATE, NULL, &pwzPath);
215 - ExitOnFailure(hr, "Failed to get known folder path.");
230 + ShelExitOnFailure(hr, "Failed to get known folder path.");
231
232 hr = StrAllocString(psczFolderPath, pwzPath, 0);
218 - ExitOnFailure(hr, "Failed to copy shell folder path: %ls", pwzPath);
233 + ShelExitOnFailure(hr, "Failed to copy shell folder path: %ls", pwzPath);
234
235 hr = PathBackslashTerminate(psczFolderPath);
221 - ExitOnFailure(hr, "Failed to backslash terminate shell folder path: %ls", *psczFolderPath);
236 + ShelExitOnFailure(hr, "Failed to backslash terminate shell folder path: %ls", *psczFolderPath);
237
238 LExit:
239 if (pwzPath)
@@ -255,32 +270,32 @@ static HRESULT GetDesktopShellView(
270 // desktop web browser and then grabs its view
271 // returns IShellView, IFolderView and related interfaces
272 hr = ::CoCreateInstance(CLSID_ShellWindows, NULL, CLSCTX_LOCAL_SERVER, IID_PPV_ARGS(&psw));
258 - ExitOnFailure(hr, "Failed to get shell view.");
273 + ShelExitOnFailure(hr, "Failed to get shell view.");
274
275 hr = psw->FindWindowSW(&vEmpty, &vEmpty, SWC_DESKTOP, (long*)&hwnd, SWFO_NEEDDISPATCH, &pdisp);
276 if (S_OK == hr)
277 {
278 hr = IUnknown_QueryService(pdisp, SID_STopLevelBrowser, IID_PPV_ARGS(&psb));
264 - ExitOnFailure(hr, "Failed to get desktop window.");
279 + ShelExitOnFailure(hr, "Failed to get desktop window.");
280
281 hr = psb->QueryActiveShellView(&psv);
267 - ExitOnFailure(hr, "Failed to get active shell view.");
282 + ShelExitOnFailure(hr, "Failed to get active shell view.");
283
284 hr = psv->QueryInterface(riid, ppv);
270 - ExitOnFailure(hr, "Failed to query for the desktop shell view.");
285 + ShelExitOnFailure(hr, "Failed to query for the desktop shell view.");
286 }
287 else if (S_FALSE == hr)
288 {
289 //Windows XP
290 hr = SHGetDesktopFolder(&psf);
276 - ExitOnFailure(hr, "Failed to get desktop folder.");
291 + ShelExitOnFailure(hr, "Failed to get desktop folder.");
292
293 hr = psf->CreateViewObject(NULL, IID_IShellView, ppv);
279 - ExitOnFailure(hr, "Failed to query for the desktop shell view.");
294 + ShelExitOnFailure(hr, "Failed to query for the desktop shell view.");
295 }
296 else
297 {
283 - ExitOnFailure(hr, "Failed to get desktop window.");
298 + ShelExitOnFailure(hr, "Failed to get desktop window.");
299 }
300
301 LExit:
@@ -307,16 +322,16 @@ static HRESULT GetShellDispatchFromView(
322 // From a shell view object, gets its automation interface and from that get the shell
323 // application object that implements IShellDispatch2 and related interfaces.
324 hr = psv->GetItemObject(SVGIO_BACKGROUND, IID_PPV_ARGS(&pdispBackground));
310 - ExitOnFailure(hr, "Failed to get the automation interface for shell.");
325 + ShelExitOnFailure(hr, "Failed to get the automation interface for shell.");
326
327 hr = pdispBackground->QueryInterface(IID_PPV_ARGS(&psfvd));
313 - ExitOnFailure(hr, "Failed to get shell folder view dual.");
328 + ShelExitOnFailure(hr, "Failed to get shell folder view dual.");
329
330 hr = psfvd->get_Application(&pdisp);
316 - ExitOnFailure(hr, "Failed to application object.");
331 + ShelExitOnFailure(hr, "Failed to application object.");
332
333 hr = pdisp->QueryInterface(riid, ppv);
319 - ExitOnFailure(hr, "Failed to get IShellDispatch2.");
334 + ShelExitOnFailure(hr, "Failed to get IShellDispatch2.");
335
336 LExit:
337 ReleaseObject(pdisp);
src/dutil/sqlutil.cpp
+67 -52
@@ -9,6 +9,21 @@
9 #define DBINITCONSTANTS
10 #include "sqlutil.h"
11
12 +
13 +// Exit macros
14 +#define SqlExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_SQLUTIL, x, s, __VA_ARGS__)
15 +#define SqlExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_SQLUTIL, x, s, __VA_ARGS__)
16 +#define SqlExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_SQLUTIL, x, s, __VA_ARGS__)
17 +#define SqlExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_SQLUTIL, x, s, __VA_ARGS__)
18 +#define SqlExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_SQLUTIL, x, s, __VA_ARGS__)
19 +#define SqlExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_SQLUTIL, x, s, __VA_ARGS__)
20 +#define SqlExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_SQLUTIL, p, x, e, s, __VA_ARGS__)
21 +#define SqlExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_SQLUTIL, p, x, s, __VA_ARGS__)
22 +#define SqlExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_SQLUTIL, p, x, e, s, __VA_ARGS__)
23 +#define SqlExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_SQLUTIL, p, x, s, __VA_ARGS__)
24 +#define SqlExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_SQLUTIL, e, x, s, __VA_ARGS__)
25 +#define SqlExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_SQLUTIL, g, x, s, __VA_ARGS__)
26 +
27 // private prototypes
28 static HRESULT FileSpecToString(
29 __in const SQL_FILESPEC* psf,
@@ -54,7 +69,7 @@ extern "C" HRESULT DAPI SqlConnectDatabase(
69 //obtain access to the SQLOLEDB provider
70 hr = ::CoCreateInstance(CLSID_SQLOLEDB, NULL, CLSCTX_INPROC_SERVER,
71 IID_IDBInitialize, (LPVOID*)&pidbInitialize);
57 - ExitOnFailure(hr, "failed to create IID_IDBInitialize object");
72 + SqlExitOnFailure(hr, "failed to create IID_IDBInitialize object");
73
74 // if there is an instance
75 if (wzInstance && *wzInstance)
@@ -65,7 +80,7 @@ extern "C" HRESULT DAPI SqlConnectDatabase(
80 {
81 hr = StrAllocString(&pwzServerInstance, wzServer, 0);
82 }
68 - ExitOnFailure(hr, "failed to allocate memory for the server instance");
83 + SqlExitOnFailure(hr, "failed to allocate memory for the server instance");
84
85 // server[\instance]
86 rgdbpInit[cProperties].dwPropertyID = DBPROP_INIT_DATASOURCE;
@@ -124,13 +139,13 @@ extern "C" HRESULT DAPI SqlConnectDatabase(
139
140 // create and set the property set
141 hr = pidbInitialize->QueryInterface(IID_IDBProperties, (LPVOID*)&pidbProperties);
127 - ExitOnFailure(hr, "failed to get IID_IDBProperties object");
142 + SqlExitOnFailure(hr, "failed to get IID_IDBProperties object");
143 hr = pidbProperties->SetProperties(1, rgdbpsetInit);
129 - ExitOnFailure(hr, "failed to set properties");
144 + SqlExitOnFailure(hr, "failed to set properties");
145
146 //initialize connection to datasource
147 hr = pidbInitialize->Initialize();
133 - ExitOnFailure(hr, "failed to initialize connection to database: %ls", wzDatabase);
148 + SqlExitOnFailure(hr, "failed to initialize connection to database: %ls", wzDatabase);
149
150 hr = pidbInitialize->QueryInterface(IID_IDBCreateSession, (LPVOID*)ppidbSession);
151
@@ -163,10 +178,10 @@ extern "C" HRESULT DAPI SqlStartTransaction(
178 HRESULT hr = S_OK;
179
180 hr = pidbSession->CreateSession(NULL, IID_IDBCreateCommand, (IUnknown**)ppidbCommand);
166 - ExitOnFailure(hr, "unable to create command from session");
181 + SqlExitOnFailure(hr, "unable to create command from session");
182
183 hr = (*ppidbCommand)->QueryInterface(IID_ITransactionLocal, (LPVOID*)ppit);
169 - ExitOnFailure(hr, "Unable to QueryInterface session to get ITransactionLocal");
184 + SqlExitOnFailure(hr, "Unable to QueryInterface session to get ITransactionLocal");
185
186 hr = ((ITransactionLocal*)*ppit)->StartTransaction(ISOLATIONLEVEL_SERIALIZABLE, 0, NULL, NULL);
187
@@ -192,12 +207,12 @@ extern "C" HRESULT DAPI SqlEndTransaction(
207 if (fCommit)
208 {
209 hr = pit->Commit(FALSE, XACTTC_SYNC, 0);
195 - ExitOnFailure(hr, "commit of transaction failed");
210 + SqlExitOnFailure(hr, "commit of transaction failed");
211 }
212 else
213 {
214 hr = pit->Abort(NULL, FALSE, FALSE);
200 - ExitOnFailure(hr, "abort of transaction failed");
215 + SqlExitOnFailure(hr, "abort of transaction failed");
216 }
217
218 LExit:
@@ -231,7 +246,7 @@ extern "C" HRESULT DAPI SqlDatabaseExists(
246 IDBCreateSession* pidbSession = NULL;
247
248 hr = SqlConnectDatabase(wzServer, wzInstance, L"master", fIntegratedAuth, wzUser, wzPassword, &pidbSession);
234 - ExitOnFailure(hr, "failed to connect to 'master' database on server %ls", wzServer);
249 + SqlExitOnFailure(hr, "failed to connect to 'master' database on server %ls", wzServer);
250
251 hr = SqlSessionDatabaseExists(pidbSession, wzDatabase, pbstrErrorDescription);
252
@@ -271,17 +286,17 @@ extern "C" HRESULT DAPI SqlSessionDatabaseExists(
286 // query to see if the database exists
287 //
288 hr = StrAllocFormatted(&pwzQuery, L"SELECT name FROM sysdatabases WHERE name='%s'", wzDatabase);
274 - ExitOnFailure(hr, "failed to allocate query string to ensure database exists");
289 + SqlExitOnFailure(hr, "failed to allocate query string to ensure database exists");
290
291 hr = SqlSessionExecuteQuery(pidbSession, pwzQuery, &pirs, NULL, pbstrErrorDescription);
277 - ExitOnFailure(hr, "failed to get database list from 'master' database");
292 + SqlExitOnFailure(hr, "failed to get database list from 'master' database");
293 Assert(pirs);
294
295 //
296 // check to see if the database was returned
297 //
298 hr = pirs->GetNextRows(DB_NULL_HCHAPTER, 0, 1, &cRows, &prow);
284 - ExitOnFailure(hr, "failed to get row with database name");
299 + SqlExitOnFailure(hr, "failed to get row with database name");
300
301 // succeeded but no database
302 if ((DB_S_ENDOFROWSET == hr) || (0 == cRows))
@@ -324,10 +339,10 @@ extern "C" HRESULT DAPI SqlDatabaseEnsureExists(
339 // connect to the master database to create the new database
340 //
341 hr = SqlConnectDatabase(wzServer, wzInstance, L"master", fIntegratedAuth, wzUser, wzPassword, &pidbSession);
327 - ExitOnFailure(hr, "failed to connect to 'master' database on server %ls", wzServer);
342 + SqlExitOnFailure(hr, "failed to connect to 'master' database on server %ls", wzServer);
343
344 hr = SqlSessionDatabaseEnsureExists(pidbSession, wzDatabase, psfDatabase, psfLog, pbstrErrorDescription);
330 - ExitOnFailure(hr, "failed to create database: %ls", wzDatabase);
345 + SqlExitOnFailure(hr, "failed to create database: %ls", wzDatabase);
346
347 Assert(S_OK == hr);
348 LExit:
@@ -355,12 +370,12 @@ extern "C" HRESULT DAPI SqlSessionDatabaseEnsureExists(
370 HRESULT hr = S_OK;
371
372 hr = SqlSessionDatabaseExists(pidbSession, wzDatabase, pbstrErrorDescription);
358 - ExitOnFailure(hr, "failed to determine if exists, database: %ls", wzDatabase);
373 + SqlExitOnFailure(hr, "failed to determine if exists, database: %ls", wzDatabase);
374
375 if (S_FALSE == hr)
376 {
377 hr = SqlSessionCreateDatabase(pidbSession, wzDatabase, psfDatabase, psfLog, pbstrErrorDescription);
363 - ExitOnFailure(hr, "failed to create database: %1", wzDatabase);
378 + SqlExitOnFailure(hr, "failed to create database: %ls", wzDatabase);
379 }
380 // else database already exists, return S_FALSE
381
@@ -398,10 +413,10 @@ extern "C" HRESULT DAPI SqlCreateDatabase(
413 // connect to the master database to create the new database
414 //
415 hr = SqlConnectDatabase(wzServer, wzInstance, L"master", fIntegratedAuth, wzUser, wzPassword, &pidbSession);
401 - ExitOnFailure(hr, "failed to connect to 'master' database on server %ls", wzServer);
416 + SqlExitOnFailure(hr, "failed to connect to 'master' database on server %ls", wzServer);
417
418 hr = SqlSessionCreateDatabase(pidbSession, wzDatabase, psfDatabase, psfLog, pbstrErrorDescription);
404 - ExitOnFailure(hr, "failed to create database: %ls", wzDatabase);
419 + SqlExitOnFailure(hr, "failed to create database: %ls", wzDatabase);
420
421 Assert(S_OK == hr);
422 LExit:
@@ -433,23 +448,23 @@ extern "C" HRESULT DAPI SqlSessionCreateDatabase(
448 if (psfDatabase)
449 {
450 hr = FileSpecToString(psfDatabase, &pwzDbFile);
436 - ExitOnFailure(hr, "failed to convert db filespec to string");
451 + SqlExitOnFailure(hr, "failed to convert db filespec to string");
452 }
453
454 if (psfLog)
455 {
456 hr = FileSpecToString(psfLog, &pwzLogFile);
442 - ExitOnFailure(hr, "failed to convert log filespec to string");
457 + SqlExitOnFailure(hr, "failed to convert log filespec to string");
458 }
459
460 hr = EscapeSqlIdentifier(wzDatabase, &pwzDatabaseEscaped);
446 - ExitOnFailure(hr, "failed to escape database string");
461 + SqlExitOnFailure(hr, "failed to escape database string");
462
463 hr = StrAllocFormatted(&pwzQuery, L"CREATE DATABASE %s %s%s %s%s", pwzDatabaseEscaped, pwzDbFile ? L"ON " : L"", pwzDbFile ? pwzDbFile : L"", pwzLogFile ? L"LOG ON " : L"", pwzLogFile ? pwzLogFile : L"");
449 - ExitOnFailure(hr, "failed to allocate query to create database: %ls", pwzDatabaseEscaped);
464 + SqlExitOnFailure(hr, "failed to allocate query to create database: %ls", pwzDatabaseEscaped);
465
466 hr = SqlSessionExecuteQuery(pidbSession, pwzQuery, NULL, NULL, pbstrErrorDescription);
452 - ExitOnFailure(hr, "failed to create database: %ls, Query: %ls", pwzDatabaseEscaped, pwzQuery);
467 + SqlExitOnFailure(hr, "failed to create database: %ls, Query: %ls", pwzDatabaseEscaped, pwzQuery);
468
469 LExit:
470 ReleaseStr(pwzQuery);
@@ -486,7 +501,7 @@ extern "C" HRESULT DAPI SqlDropDatabase(
501 // connect to the master database to search for wzDatabase
502 //
503 hr = SqlConnectDatabase(wzServer, wzInstance, L"master", fIntegratedAuth, wzUser, wzPassword, &pidbSession);
489 - ExitOnFailure(hr, "Failed to connect to 'master' database");
504 + SqlExitOnFailure(hr, "Failed to connect to 'master' database");
505
506 hr = SqlSessionDropDatabase(pidbSession, wzDatabase, pbstrErrorDescription);
507
@@ -515,18 +530,18 @@ extern "C" HRESULT DAPI SqlSessionDropDatabase(
530 LPWSTR pwzDatabaseEscaped = NULL;
531
532 hr = SqlSessionDatabaseExists(pidbSession, wzDatabase, pbstrErrorDescription);
518 - ExitOnFailure(hr, "failed to determine if exists, database: %ls", wzDatabase);
533 + SqlExitOnFailure(hr, "failed to determine if exists, database: %ls", wzDatabase);
534
535 hr = EscapeSqlIdentifier(wzDatabase, &pwzDatabaseEscaped);
521 - ExitOnFailure(hr, "failed to escape database string");
536 + SqlExitOnFailure(hr, "failed to escape database string");
537
538 if (S_OK == hr)
539 {
540 hr = StrAllocFormatted(&pwzQuery, L"DROP DATABASE %s", pwzDatabaseEscaped);
526 - ExitOnFailure(hr, "failed to allocate query to drop database: %ls", pwzDatabaseEscaped);
541 + SqlExitOnFailure(hr, "failed to allocate query to drop database: %ls", pwzDatabaseEscaped);
542
543 hr = SqlSessionExecuteQuery(pidbSession, pwzQuery, NULL, NULL, pbstrErrorDescription);
529 - ExitOnFailure(hr, "Failed to drop database");
544 + SqlExitOnFailure(hr, "Failed to drop database");
545 }
546
547 LExit:
@@ -567,23 +582,23 @@ extern "C" HRESULT DAPI SqlSessionExecuteQuery(
582 // create the command
583 //
584 hr = pidbSession->CreateSession(NULL, IID_IDBCreateCommand, (IUnknown**)&pidbCommand);
570 - ExitOnFailure(hr, "failed to create database session");
585 + SqlExitOnFailure(hr, "failed to create database session");
586 hr = pidbCommand->CreateCommand(NULL, IID_ICommand, (IUnknown**)&picmd);
572 - ExitOnFailure(hr, "failed to create command to execute session");
587 + SqlExitOnFailure(hr, "failed to create command to execute session");
588
589 //
590 // set the sql text into the command
591 //
592 hr = picmd->QueryInterface(IID_ICommandText, (LPVOID*)&picmdText);
578 - ExitOnFailure(hr, "failed to get command text object for command");
593 + SqlExitOnFailure(hr, "failed to get command text object for command");
594 hr = picmdText->SetCommandText(DBGUID_DEFAULT , wzSql);
580 - ExitOnFailure(hr, "failed to set SQL string: %ls", wzSql);
595 + SqlExitOnFailure(hr, "failed to set SQL string: %ls", wzSql);
596
597 //
598 // execute the command
599 //
600 hr = picmd->Execute(NULL, (ppirs) ? IID_IRowset : IID_NULL, NULL, &cRows, reinterpret_cast<IUnknown**>(ppirs));
586 - ExitOnFailure(hr, "failed to execute SQL string: %ls", wzSql);
601 + SqlExitOnFailure(hr, "failed to execute SQL string: %ls", wzSql);
602
603 if (DB_S_ERRORSOCCURRED == hr)
604 {
@@ -642,21 +657,21 @@ extern "C" HRESULT DAPI SqlCommandExecuteQuery(
657 // create the command
658 //
659 hr = pidbCommand->CreateCommand(NULL, IID_ICommand, (IUnknown**)&picmd);
645 - ExitOnFailure(hr, "failed to create command to execute session");
660 + SqlExitOnFailure(hr, "failed to create command to execute session");
661
662 //
663 // set the sql text into the command
664 //
665 hr = picmd->QueryInterface(IID_ICommandText, (LPVOID*)&picmdText);
651 - ExitOnFailure(hr, "failed to get command text object for command");
666 + SqlExitOnFailure(hr, "failed to get command text object for command");
667 hr = picmdText->SetCommandText(DBGUID_DEFAULT , wzSql);
653 - ExitOnFailure(hr, "failed to set SQL string: %ls", wzSql);
668 + SqlExitOnFailure(hr, "failed to set SQL string: %ls", wzSql);
669
670 //
671 // execute the command
672 //
673 hr = picmd->Execute(NULL, (ppirs) ? IID_IRowset : IID_NULL, NULL, &cRows, reinterpret_cast<IUnknown**>(ppirs));
659 - ExitOnFailure(hr, "failed to execute SQL string: %ls", wzSql);
674 + SqlExitOnFailure(hr, "failed to execute SQL string: %ls", wzSql);
675
676 if (DB_S_ERRORSOCCURRED == hr)
677 {
@@ -700,14 +715,14 @@ extern "C" HRESULT DAPI SqlGetErrorInfo(
715
716 // only ask for error information if the interface supports it.
717 hr = pObjectWithError->QueryInterface(IID_ISupportErrorInfo,(void**)&pISupportErrorInfo);
703 - ExitOnFailure(hr, "No error information was found for object.");
718 + SqlExitOnFailure(hr, "No error information was found for object.");
719
720 hr = pISupportErrorInfo->InterfaceSupportsErrorInfo(IID_InterfaceWithError);
706 - ExitOnFailure(hr, "InterfaceWithError is not supported for object with error");
721 + SqlExitOnFailure(hr, "InterfaceWithError is not supported for object with error");
722
723 // ignore the return of GetErrorInfo it can succeed and return a NULL pointer in pIErrorInfoAll anyway
724 hr = ::GetErrorInfo(0, &pIErrorInfoAll);
710 - ExitOnFailure(hr, "failed to get error info");
725 + SqlExitOnFailure(hr, "failed to get error info");
726
727 if (S_OK == hr && pIErrorInfoAll)
728 {
@@ -787,37 +802,37 @@ static HRESULT FileSpecToString(
802 LPWSTR pwz = NULL;
803
804 hr = StrAllocString(&pwz, L"(", 1024);
790 - ExitOnFailure(hr, "failed to allocate string for database file info");
805 + SqlExitOnFailure(hr, "failed to allocate string for database file info");
806
792 - ExitOnNull(*psf->wzName, hr, E_INVALIDARG, "logical name not specified in database file info");
793 - ExitOnNull(*psf->wzFilename, hr, E_INVALIDARG, "filename not specified in database file info");
807 + SqlExitOnNull(*psf->wzName, hr, E_INVALIDARG, "logical name not specified in database file info");
808 + SqlExitOnNull(*psf->wzFilename, hr, E_INVALIDARG, "filename not specified in database file info");
809
810 hr = StrAllocFormatted(&pwz, L"%sNAME=%s", pwz, psf->wzName);
796 - ExitOnFailure(hr, "failed to format database file info name: %ls", psf->wzName);
811 + SqlExitOnFailure(hr, "failed to format database file info name: %ls", psf->wzName);
812
813 hr = StrAllocFormatted(&pwz, L"%s, FILENAME='%s'", pwz, psf->wzFilename);
799 - ExitOnFailure(hr, "failed to format database file info filename: %ls", psf->wzFilename);
814 + SqlExitOnFailure(hr, "failed to format database file info filename: %ls", psf->wzFilename);
815
816 if (0 != psf->wzSize[0])
817 {
818 hr = StrAllocFormatted(&pwz, L"%s, SIZE=%s", pwz, psf->wzSize);
804 - ExitOnFailure(hr, "failed to format database file info size: %s", psf->wzSize);
819 + SqlExitOnFailure(hr, "failed to format database file info size: %ls", psf->wzSize);
820 }
821
822 if (0 != psf->wzMaxSize[0])
823 {
824 hr = StrAllocFormatted(&pwz, L"%s, MAXSIZE=%s", pwz, psf->wzMaxSize);
810 - ExitOnFailure(hr, "failed to format database file info maxsize: %s", psf->wzMaxSize);
825 + SqlExitOnFailure(hr, "failed to format database file info maxsize: %ls", psf->wzMaxSize);
826 }
827
828 if (0 != psf->wzGrow[0])
829 {
830 hr = StrAllocFormatted(&pwz, L"%s, FILEGROWTH=%s", pwz, psf->wzGrow);
816 - ExitOnFailure(hr, "failed to format database file info growth: %s", psf->wzGrow);
831 + SqlExitOnFailure(hr, "failed to format database file info growth: %ls", psf->wzGrow);
832 }
833
834 hr = StrAllocFormatted(&pwz, L"%s)", pwz);
820 - ExitOnFailure(hr, "failed to allocate string for file spec");
835 + SqlExitOnFailure(hr, "failed to allocate string for file spec");
836
837 *ppwz = pwz;
838 pwz = NULL; // null here so it doesn't get freed below
@@ -850,13 +865,13 @@ static HRESULT EscapeSqlIdentifier(
865 if (cchIdentifier == 0 || (wzIdentifier[0] == '[' && wzIdentifier[cchIdentifier-1] == ']'))
866 {
867 hr = StrAllocString(&pwz, wzIdentifier, 0);
853 - ExitOnFailure(hr, "failed to format database name: %ls", wzIdentifier);
868 + SqlExitOnFailure(hr, "failed to format database name: %ls", wzIdentifier);
869 }
870 else
871 {
872 //escape it
873 hr = StrAllocFormatted(&pwz, L"[%s]", wzIdentifier);
859 - ExitOnFailure(hr, "failed to format escaped database name: %ls", wzIdentifier);
874 + SqlExitOnFailure(hr, "failed to format escaped database name: %ls", wzIdentifier);
875 }
876
877 *ppwz = pwz;
src/dutil/srputil.cpp
+29 -14
@@ -3,6 +3,21 @@
3 #include "precomp.h"
4
5
6 +// Exit macros
7 +#define SrpExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_SRPUTIL, x, s, __VA_ARGS__)
8 +#define SrpExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_SRPUTIL, x, s, __VA_ARGS__)
9 +#define SrpExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_SRPUTIL, x, s, __VA_ARGS__)
10 +#define SrpExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_SRPUTIL, x, s, __VA_ARGS__)
11 +#define SrpExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_SRPUTIL, x, s, __VA_ARGS__)
12 +#define SrpExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_SRPUTIL, x, s, __VA_ARGS__)
13 +#define SrpExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_SRPUTIL, p, x, e, s, __VA_ARGS__)
14 +#define SrpExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_SRPUTIL, p, x, s, __VA_ARGS__)
15 +#define SrpExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_SRPUTIL, p, x, e, s, __VA_ARGS__)
16 +#define SrpExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_SRPUTIL, p, x, s, __VA_ARGS__)
17 +#define SrpExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_SRPUTIL, e, x, s, __VA_ARGS__)
18 +#define SrpExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_SRPUTIL, g, x, s, __VA_ARGS__)
19 +
20 +
21 typedef BOOL (WINAPI *PFN_SETRESTOREPTW)(
22 __in PRESTOREPOINTINFOW pRestorePtSpec,
23 __out PSTATEMGRSTATUS pSMgrStatus
@@ -28,7 +43,7 @@ DAPI_(HRESULT) SrpInitialize(
43 }
44
45 vpfnSRSetRestorePointW = reinterpret_cast<PFN_SETRESTOREPTW>(::GetProcAddress(vhSrClientDll, "SRSetRestorePointW"));
31 - ExitOnNullWithLastError(vpfnSRSetRestorePointW, hr, "Failed to find set restore point proc address.");
46 + SrpExitOnNullWithLastError(vpfnSRSetRestorePointW, hr, "Failed to find set restore point proc address.");
47
48 // If allowed, initialize COM security to enable NetworkService,
49 // LocalService and System to make callbacks to the process
@@ -37,7 +52,7 @@ DAPI_(HRESULT) SrpInitialize(
52 if (fInitializeComSecurity)
53 {
54 hr = InitializeComSecurity();
40 - ExitOnFailure(hr, "Failed to initialize security for COM to talk to system restore.");
55 + SrpExitOnFailure(hr, "Failed to initialize security for COM to talk to system restore.");
56 }
57
58 LExit:
@@ -79,7 +94,7 @@ DAPI_(HRESULT) SrpCreateRestorePoint(
94
95 if (!vpfnSRSetRestorePointW(&restorePoint, &status))
96 {
82 - ExitOnWin32Error(status.nStatus, hr, "Failed to create system restore point.");
97 + SrpExitOnWin32Error(status.nStatus, hr, "Failed to create system restore point.");
98 }
99
100 LExit:
@@ -116,42 +131,42 @@ static HRESULT InitializeComSecurity()
131 // Initialize the security descriptor.
132 if (!::InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION))
133 {
119 - ExitWithLastError(hr, "Failed to initialize security descriptor for system restore.");
134 + SrpExitWithLastError(hr, "Failed to initialize security descriptor for system restore.");
135 }
136
137 // Create an administrator group security identifier (SID).
138 cbSid = sizeof(rgSidBA);
139 if (!::CreateWellKnownSid(WinBuiltinAdministratorsSid, NULL, rgSidBA, &cbSid))
140 {
126 - ExitWithLastError(hr, "Failed to create administrator SID for system restore.");
141 + SrpExitWithLastError(hr, "Failed to create administrator SID for system restore.");
142 }
143
144 // Create a local service security identifier (SID).
145 cbSid = sizeof(rgSidLS);
146 if (!::CreateWellKnownSid(WinLocalServiceSid, NULL, rgSidLS, &cbSid))
147 {
133 - ExitWithLastError(hr, "Failed to create local service SID for system restore.");
148 + SrpExitWithLastError(hr, "Failed to create local service SID for system restore.");
149 }
150
151 // Create a network service security identifier (SID).
152 cbSid = sizeof(rgSidNS);
153 if (!::CreateWellKnownSid(WinNetworkServiceSid, NULL, rgSidNS, &cbSid))
154 {
140 - ExitWithLastError(hr, "Failed to create network service SID for system restore.");
155 + SrpExitWithLastError(hr, "Failed to create network service SID for system restore.");
156 }
157
158 // Create a personal account security identifier (SID).
159 cbSid = sizeof(rgSidPS);
160 if (!::CreateWellKnownSid(WinSelfSid, NULL, rgSidPS, &cbSid))
161 {
147 - ExitWithLastError(hr, "Failed to create self SID for system restore.");
162 + SrpExitWithLastError(hr, "Failed to create self SID for system restore.");
163 }
164
165 // Create a local service security identifier (SID).
166 cbSid = sizeof(rgSidSY);
167 if (!::CreateWellKnownSid(WinLocalSystemSid, NULL, rgSidSY, &cbSid))
168 {
154 - ExitWithLastError(hr, "Failed to create local system SID for system restore.");
169 + SrpExitWithLastError(hr, "Failed to create local system SID for system restore.");
170 }
171
172 // Setup the access control entries (ACE) for COM. COM_RIGHTS_EXECUTE and
@@ -203,29 +218,29 @@ static HRESULT InitializeComSecurity()
218
219 // Create an access control list (ACL) using this ACE list.
220 er = ::SetEntriesInAcl(countof(ea), ea, NULL, &pAcl);
206 - ExitOnWin32Error(er, hr, "Failed to create ACL for system restore.");
221 + SrpExitOnWin32Error(er, hr, "Failed to create ACL for system restore.");
222
223 // Set the security descriptor owner to Administrators.
224 if (!::SetSecurityDescriptorOwner(&sd, rgSidBA, FALSE))
225 {
211 - ExitWithLastError(hr, "Failed to set administrators owner for system restore.");
226 + SrpExitWithLastError(hr, "Failed to set administrators owner for system restore.");
227 }
228
229 // Set the security descriptor group to Administrators.
230 if (!::SetSecurityDescriptorGroup(&sd, rgSidBA, FALSE))
231 {
217 - ExitWithLastError(hr, "Failed to set administrators group access for system restore.");
232 + SrpExitWithLastError(hr, "Failed to set administrators group access for system restore.");
233 }
234
235 // Set the discretionary access control list (DACL) to the ACL.
236 if (!::SetSecurityDescriptorDacl(&sd, TRUE, pAcl, FALSE))
237 {
223 - ExitWithLastError(hr, "Failed to set DACL for system restore.");
238 + SrpExitWithLastError(hr, "Failed to set DACL for system restore.");
239 }
240
241 // Note that an explicit security descriptor is being passed in.
242 hr= ::CoInitializeSecurity(&sd, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_PKT_PRIVACY, RPC_C_IMP_LEVEL_IDENTIFY, NULL, EOAC_DISABLE_AAA | EOAC_NO_CUSTOM_MARSHAL, NULL);
228 - ExitOnFailure(hr, "Failed to initialize COM security for system restore.");
243 + SrpExitOnFailure(hr, "Failed to initialize COM security for system restore.");
244
245 LExit:
246 if (pAcl)
src/dutil/strutil.cpp
+115 -100
@@ -2,6 +2,21 @@
2
3 #include "precomp.h"
4
5 +
6 +// Exit macros
7 +#define StrExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_STRUTIL, x, s, __VA_ARGS__)
8 +#define StrExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_STRUTIL, x, s, __VA_ARGS__)
9 +#define StrExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_STRUTIL, x, s, __VA_ARGS__)
10 +#define StrExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_STRUTIL, x, s, __VA_ARGS__)
11 +#define StrExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_STRUTIL, x, s, __VA_ARGS__)
12 +#define StrExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_STRUTIL, x, s, __VA_ARGS__)
13 +#define StrExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_STRUTIL, p, x, e, s, __VA_ARGS__)
14 +#define StrExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_STRUTIL, p, x, s, __VA_ARGS__)
15 +#define StrExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_STRUTIL, p, x, e, s, __VA_ARGS__)
16 +#define StrExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_STRUTIL, p, x, s, __VA_ARGS__)
17 +#define StrExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_STRUTIL, e, x, s, __VA_ARGS__)
18 +#define StrExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_STRUTIL, g, x, s, __VA_ARGS__)
19 +
20 #define ARRAY_GROWTH_SIZE 5
21
22 // Forward declarations.
@@ -84,7 +99,7 @@ static HRESULT AllocHelper(
99 if (cch >= MAXDWORD / sizeof(WCHAR))
100 {
101 hr = E_OUTOFMEMORY;
87 - ExitOnFailure(hr, "Not enough memory to allocate string of size: %u", cch);
102 + StrExitOnFailure(hr, "Not enough memory to allocate string of size: %u", cch);
103 }
104
105 if (*ppwz)
@@ -93,7 +108,7 @@ static HRESULT AllocHelper(
108 {
109 LPVOID pvNew = NULL;
110 hr = MemReAllocSecure(*ppwz, sizeof(WCHAR)* cch, FALSE, &pvNew);
96 - ExitOnFailure(hr, "Failed to reallocate string");
111 + StrExitOnFailure(hr, "Failed to reallocate string");
112 pwz = static_cast<LPWSTR>(pvNew);
113 }
114 else
@@ -106,7 +121,7 @@ static HRESULT AllocHelper(
121 pwz = static_cast<LPWSTR>(MemAlloc(sizeof(WCHAR) * cch, TRUE));
122 }
123
109 - ExitOnNull(pwz, hr, E_OUTOFMEMORY, "failed to allocate string, len: %u", cch);
124 + StrExitOnNull(pwz, hr, E_OUTOFMEMORY, "failed to allocate string, len: %u", cch);
125
126 *ppwz = pwz;
127 LExit:
@@ -131,12 +146,12 @@ HRESULT DAPI StrTrimCapacity(
146 SIZE_T cchLen = 0;
147
148 hr = ::StringCchLengthW(*ppwz, STRSAFE_MAX_CCH, reinterpret_cast<UINT_PTR*>(&cchLen));
134 - ExitOnFailure(hr, "Failed to calculate length of string");
149 + StrExitOnFailure(hr, "Failed to calculate length of string");
150
151 ++cchLen; // Add 1 for null-terminator
152
153 hr = StrAlloc(ppwz, cchLen);
139 - ExitOnFailure(hr, "Failed to reallocate string");
154 + StrExitOnFailure(hr, "Failed to reallocate string");
155
156 LExit:
157 return hr;
@@ -181,7 +196,7 @@ HRESULT DAPI StrTrimWhitespace(
196 }
197
198 hr = StrAllocString(&sczResult, wzSource, i);
184 - ExitOnFailure(hr, "Failed to copy result string");
199 + StrExitOnFailure(hr, "Failed to copy result string");
200
201 // Output result
202 *ppwz = sczResult;
@@ -212,7 +227,7 @@ extern "C" HRESULT DAPI StrAnsiAlloc(
227 if (cch >= MAXDWORD / sizeof(WCHAR))
228 {
229 hr = E_OUTOFMEMORY;
215 - ExitOnFailure(hr, "Not enough memory to allocate string of size: %u", cch);
230 + StrExitOnFailure(hr, "Not enough memory to allocate string of size: %u", cch);
231 }
232
233 if (*ppsz)
@@ -224,7 +239,7 @@ extern "C" HRESULT DAPI StrAnsiAlloc(
239 psz = static_cast<LPSTR>(MemAlloc(sizeof(CHAR) * cch, TRUE));
240 }
241
227 - ExitOnNull(psz, hr, E_OUTOFMEMORY, "failed to allocate string, len: %u", cch);
242 + StrExitOnNull(psz, hr, E_OUTOFMEMORY, "failed to allocate string, len: %u", cch);
243
244 *ppsz = psz;
245 LExit:
@@ -252,12 +267,12 @@ HRESULT DAPI StrAnsiTrimCapacity(
267 #pragma prefast(disable:25068)
268 hr = ::StringCchLengthA(*ppz, STRSAFE_MAX_CCH, reinterpret_cast<UINT_PTR*>(&cchLen));
269 #pragma prefast(pop)
255 - ExitOnFailure(hr, "Failed to calculate length of string");
270 + StrExitOnFailure(hr, "Failed to calculate length of string");
271
272 ++cchLen; // Add 1 for null-terminator
273
274 hr = StrAnsiAlloc(ppz, cchLen);
260 - ExitOnFailure(hr, "Failed to reallocate string");
275 + StrExitOnFailure(hr, "Failed to reallocate string");
276
277 LExit:
278 return hr;
@@ -302,7 +317,7 @@ HRESULT DAPI StrAnsiTrimWhitespace(
317 }
318
319 hr = StrAnsiAllocStringAnsi(&sczResult, szSource, i);
305 - ExitOnFailure(hr, "Failed to copy result string");
320 + StrExitOnFailure(hr, "Failed to copy result string");
321
322 // Output result
323 *ppz = sczResult;
@@ -375,7 +390,7 @@ static HRESULT AllocStringHelper(
390 if (-1 == cch)
391 {
392 hr = E_INVALIDARG;
378 - ExitOnFailure(hr, "failed to get size of destination string");
393 + StrExitOnFailure(hr, "failed to get size of destination string");
394 }
395 cch /= sizeof(WCHAR); //convert the count in bytes to count in characters
396 }
@@ -387,13 +402,13 @@ static HRESULT AllocStringHelper(
402
403 SIZE_T cchNeeded;
404 hr = ::ULongPtrAdd(cchSource, 1, &cchNeeded); // add one for the null terminator
390 - ExitOnFailure(hr, "source string is too long");
405 + StrExitOnFailure(hr, "source string is too long");
406
407 if (cch < cchNeeded)
408 {
409 cch = cchNeeded;
410 hr = AllocHelper(ppwz, cch, fZeroOnRealloc);
396 - ExitOnFailure(hr, "failed to allocate string from string.");
411 + StrExitOnFailure(hr, "failed to allocate string from string.");
412 }
413
414 // copy everything (the NULL terminator will be included)
@@ -431,7 +446,7 @@ extern "C" HRESULT DAPI StrAnsiAllocString(
446 if (-1 == cch)
447 {
448 hr = E_INVALIDARG;
434 - ExitOnFailure(hr, "failed to get size of destination string");
449 + StrExitOnFailure(hr, "failed to get size of destination string");
450 }
451 cch /= sizeof(CHAR); //convert the count in bytes to count in characters
452 }
@@ -441,7 +456,7 @@ extern "C" HRESULT DAPI StrAnsiAllocString(
456 cchDest = ::WideCharToMultiByte(uiCodepage, 0, wzSource, -1, NULL, 0, NULL, NULL);
457 if (0 == cchDest)
458 {
444 - ExitWithLastError(hr, "failed to get required size for conversion to ANSI: %ls", wzSource);
459 + StrExitWithLastError(hr, "failed to get required size for conversion to ANSI: %ls", wzSource);
460 }
461
462 --cchDest; // subtract one because WideChageToMultiByte includes space for the NULL terminator that we track below
@@ -457,7 +472,7 @@ extern "C" HRESULT DAPI StrAnsiAllocString(
472 if (cch >= MAXDWORD / sizeof(WCHAR))
473 {
474 hr = E_OUTOFMEMORY;
460 - ExitOnFailure(hr, "Not enough memory to allocate string of size: %u", cch);
475 + StrExitOnFailure(hr, "Not enough memory to allocate string of size: %u", cch);
476 }
477
478 if (*ppsz)
@@ -468,14 +483,14 @@ extern "C" HRESULT DAPI StrAnsiAllocString(
483 {
484 psz = static_cast<LPSTR>(MemAlloc(sizeof(CHAR) * cch, TRUE));
485 }
471 - ExitOnNull(psz, hr, E_OUTOFMEMORY, "failed to allocate string, len: %u", cch);
486 + StrExitOnNull(psz, hr, E_OUTOFMEMORY, "failed to allocate string, len: %u", cch);
487
488 *ppsz = psz;
489 }
490
491 if (0 == ::WideCharToMultiByte(uiCodepage, 0, wzSource, 0 == cchSource ? -1 : (int)cchSource, *ppsz, (int)cch, NULL, NULL))
492 {
478 - ExitWithLastError(hr, "failed to convert to ansi: %ls", wzSource);
493 + StrExitWithLastError(hr, "failed to convert to ansi: %ls", wzSource);
494 }
495 (*ppsz)[cchDest] = L'\0';
496
@@ -511,7 +526,7 @@ extern "C" HRESULT DAPI StrAllocStringAnsi(
526 if (-1 == cch)
527 {
528 hr = E_INVALIDARG;
514 - ExitOnFailure(hr, "failed to get size of destination string");
529 + StrExitOnFailure(hr, "failed to get size of destination string");
530 }
531 cch /= sizeof(WCHAR); //convert the count in bytes to count in characters
532 }
@@ -521,7 +536,7 @@ extern "C" HRESULT DAPI StrAllocStringAnsi(
536 cchDest = ::MultiByteToWideChar(uiCodepage, 0, szSource, -1, NULL, 0);
537 if (0 == cchDest)
538 {
524 - ExitWithLastError(hr, "failed to get required size for conversion to unicode: %s", szSource);
539 + StrExitWithLastError(hr, "failed to get required size for conversion to unicode: %s", szSource);
540 }
541
542 --cchDest; //subtract one because MultiByteToWideChar includes space for the NULL terminator that we track below
@@ -537,7 +552,7 @@ extern "C" HRESULT DAPI StrAllocStringAnsi(
552 if (cch >= MAXDWORD / sizeof(WCHAR))
553 {
554 hr = E_OUTOFMEMORY;
540 - ExitOnFailure(hr, "Not enough memory to allocate string of size: %u", cch);
555 + StrExitOnFailure(hr, "Not enough memory to allocate string of size: %u", cch);
556 }
557
558 if (*ppwz)
@@ -549,14 +564,14 @@ extern "C" HRESULT DAPI StrAllocStringAnsi(
564 pwz = static_cast<LPWSTR>(MemAlloc(sizeof(WCHAR) * cch, TRUE));
565 }
566
552 - ExitOnNull(pwz, hr, E_OUTOFMEMORY, "failed to allocate string, len: %u", cch);
567 + StrExitOnNull(pwz, hr, E_OUTOFMEMORY, "failed to allocate string, len: %u", cch);
568
569 *ppwz = pwz;
570 }
571
572 if (0 == ::MultiByteToWideChar(uiCodepage, 0, szSource, 0 == cchSource ? -1 : (int)cchSource, *ppwz, (int)cch))
573 {
559 - ExitWithLastError(hr, "failed to convert to unicode: %s", szSource);
574 + StrExitWithLastError(hr, "failed to convert to unicode: %s", szSource);
575 }
576 (*ppwz)[cchDest] = L'\0';
577
@@ -589,7 +604,7 @@ HRESULT DAPI StrAnsiAllocStringAnsi(
604 if (-1 == cch)
605 {
606 hr = E_INVALIDARG;
592 - ExitOnFailure(hr, "failed to get size of destination string");
607 + StrExitOnFailure(hr, "failed to get size of destination string");
608 }
609 cch /= sizeof(CHAR); //convert the count in bytes to count in characters
610 }
@@ -601,13 +616,13 @@ HRESULT DAPI StrAnsiAllocStringAnsi(
616
617 SIZE_T cchNeeded;
618 hr = ::ULongPtrAdd(cchSource, 1, &cchNeeded); // add one for the null terminator
604 - ExitOnFailure(hr, "source string is too long");
619 + StrExitOnFailure(hr, "source string is too long");
620
621 if (cch < cchNeeded)
622 {
623 cch = cchNeeded;
624 hr = StrAnsiAlloc(ppsz, cch);
610 - ExitOnFailure(hr, "failed to allocate string from string.");
625 + StrExitOnFailure(hr, "failed to allocate string from string.");
626 }
627
628 // copy everything (the NULL terminator will be included)
@@ -647,12 +662,12 @@ extern "C" HRESULT DAPI StrAllocPrefix(
662 if (-1 == cch)
663 {
664 hr = E_INVALIDARG;
650 - ExitOnFailure(hr, "failed to get size of destination string");
665 + StrExitOnFailure(hr, "failed to get size of destination string");
666 }
667 cch /= sizeof(WCHAR); //convert the count in bytes to count in characters
668
669 hr = ::StringCchLengthW(*ppwz, STRSAFE_MAX_CCH, reinterpret_cast<UINT_PTR*>(&cchLen));
655 - ExitOnFailure(hr, "Failed to calculate length of string");
670 + StrExitOnFailure(hr, "Failed to calculate length of string");
671 }
672
673 Assert(cchLen <= cch);
@@ -660,14 +675,14 @@ extern "C" HRESULT DAPI StrAllocPrefix(
675 if (0 == cchPrefix)
676 {
677 hr = ::StringCchLengthW(wzPrefix, STRSAFE_MAX_CCH, reinterpret_cast<UINT_PTR*>(&cchPrefix));
663 - ExitOnFailure(hr, "Failed to calculate length of string");
678 + StrExitOnFailure(hr, "Failed to calculate length of string");
679 }
680
681 if (cch - cchLen < cchPrefix + 1)
682 {
683 cch = cchPrefix + cchLen + 1;
684 hr = StrAlloc(ppwz, cch);
670 - ExitOnFailure(hr, "failed to allocate string from string: %ls", wzPrefix);
685 + StrExitOnFailure(hr, "failed to allocate string from string: %ls", wzPrefix);
686 }
687
688 if (*ppwz)
@@ -681,7 +696,7 @@ extern "C" HRESULT DAPI StrAllocPrefix(
696 else
697 {
698 hr = E_UNEXPECTED;
684 - ExitOnFailure(hr, "for some reason our buffer is still null");
699 + StrExitOnFailure(hr, "for some reason our buffer is still null");
700 }
701
702 LExit:
@@ -753,12 +768,12 @@ static HRESULT AllocConcatHelper(
768 if (-1 == cch)
769 {
770 hr = E_INVALIDARG;
756 - ExitOnFailure(hr, "failed to get size of destination string");
771 + StrExitOnFailure(hr, "failed to get size of destination string");
772 }
773 cch /= sizeof(WCHAR); //convert the count in bytes to count in characters
774
775 hr = ::StringCchLengthW(*ppwz, STRSAFE_MAX_CCH, reinterpret_cast<UINT_PTR*>(&cchLen));
761 - ExitOnFailure(hr, "Failed to calculate length of string");
776 + StrExitOnFailure(hr, "Failed to calculate length of string");
777 }
778
779 Assert(cchLen <= cch);
@@ -766,14 +781,14 @@ static HRESULT AllocConcatHelper(
781 if (0 == cchSource)
782 {
783 hr = ::StringCchLengthW(wzSource, STRSAFE_MAX_CCH, reinterpret_cast<UINT_PTR*>(&cchSource));
769 - ExitOnFailure(hr, "Failed to calculate length of string");
784 + StrExitOnFailure(hr, "Failed to calculate length of string");
785 }
786
787 if (cch - cchLen < cchSource + 1)
788 {
789 cch = (cchSource + cchLen + 1) * 2;
790 hr = AllocHelper(ppwz, cch, fZeroOnRealloc);
776 - ExitOnFailure(hr, "failed to allocate string from string: %ls", wzSource);
791 + StrExitOnFailure(hr, "failed to allocate string from string: %ls", wzSource);
792 }
793
794 if (*ppwz)
@@ -783,7 +798,7 @@ static HRESULT AllocConcatHelper(
798 else
799 {
800 hr = E_UNEXPECTED;
786 - ExitOnFailure(hr, "for some reason our buffer is still null");
801 + StrExitOnFailure(hr, "for some reason our buffer is still null");
802 }
803
804 LExit:
@@ -816,7 +831,7 @@ extern "C" HRESULT DAPI StrAnsiAllocConcat(
831 if (-1 == cch)
832 {
833 hr = E_INVALIDARG;
819 - ExitOnFailure(hr, "failed to get size of destination string");
834 + StrExitOnFailure(hr, "failed to get size of destination string");
835 }
836 cch /= sizeof(CHAR); // convert the count in bytes to count in characters
837
@@ -824,7 +839,7 @@ extern "C" HRESULT DAPI StrAnsiAllocConcat(
839 #pragma prefast(disable:25068)
840 hr = ::StringCchLengthA(*ppz, STRSAFE_MAX_CCH, reinterpret_cast<UINT_PTR*>(&cchLen));
841 #pragma prefast(pop)
827 - ExitOnFailure(hr, "Failed to calculate length of string");
842 + StrExitOnFailure(hr, "Failed to calculate length of string");
843 }
844
845 Assert(cchLen <= cch);
@@ -835,14 +850,14 @@ extern "C" HRESULT DAPI StrAnsiAllocConcat(
850 #pragma prefast(disable:25068)
851 hr = ::StringCchLengthA(pzSource, STRSAFE_MAX_CCH, reinterpret_cast<UINT_PTR*>(&cchSource));
852 #pragma prefast(pop)
838 - ExitOnFailure(hr, "Failed to calculate length of string");
853 + StrExitOnFailure(hr, "Failed to calculate length of string");
854 }
855
856 if (cch - cchLen < cchSource + 1)
857 {
858 cch = (cchSource + cchLen + 1) * 2;
859 hr = StrAnsiAlloc(ppz, cch);
845 - ExitOnFailure(hr, "failed to allocate string from string: %hs", pzSource);
860 + StrExitOnFailure(hr, "failed to allocate string from string: %hs", pzSource);
861 }
862
863 if (*ppz)
@@ -855,7 +870,7 @@ extern "C" HRESULT DAPI StrAnsiAllocConcat(
870 else
871 {
872 hr = E_UNEXPECTED;
858 - ExitOnFailure(hr, "for some reason our buffer is still null");
873 + StrExitOnFailure(hr, "for some reason our buffer is still null");
874 }
875
876 LExit:
@@ -908,7 +923,7 @@ extern "C" HRESULT __cdecl StrAllocConcatFormatted(
923 va_start(args, wzFormat);
924 hr = StrAllocFormattedArgs(&sczFormatted, wzFormat, args);
925 va_end(args);
911 - ExitOnFailure(hr, "Failed to allocate formatted string");
926 + StrExitOnFailure(hr, "Failed to allocate formatted string");
927
928 hr = StrAllocConcat(ppwz, sczFormatted, 0);
929
@@ -942,7 +957,7 @@ extern "C" HRESULT __cdecl StrAllocConcatFormattedSecure(
957 va_start(args, wzFormat);
958 hr = StrAllocFormattedArgsSecure(&sczFormatted, wzFormat, args);
959 va_end(args);
945 - ExitOnFailure(hr, "Failed to allocate formatted string");
960 + StrExitOnFailure(hr, "Failed to allocate formatted string");
961
962 hr = StrAllocConcatSecure(ppwz, sczFormatted, 0);
963
@@ -1068,7 +1083,7 @@ static HRESULT AllocFormattedArgsHelper(
1083 if (-1 == cbOriginal)
1084 {
1085 hr = E_INVALIDARG;
1071 - ExitOnFailure(hr, "failed to get size of destination string");
1086 + StrExitOnFailure(hr, "failed to get size of destination string");
1087 }
1088
1089 cch = cbOriginal / sizeof(WCHAR); //convert the count in bytes to count in characters
@@ -1080,7 +1095,7 @@ static HRESULT AllocFormattedArgsHelper(
1095 cch = 256;
1096
1097 hr = AllocHelper(ppwz, cch, fZeroOnRealloc);
1083 - ExitOnFailure(hr, "failed to allocate string to format: %ls", wzFormat);
1098 + StrExitOnFailure(hr, "failed to allocate string to format: %ls", wzFormat);
1099 }
1100
1101 // format the message (grow until it fits or there is a failure)
@@ -1104,12 +1119,12 @@ static HRESULT AllocFormattedArgsHelper(
1119 cch *= 2;
1120
1121 hr = AllocHelper(ppwz, cch, fZeroOnRealloc);
1107 - ExitOnFailure(hr, "failed to allocate string to format: %ls", wzFormat);
1122 + StrExitOnFailure(hr, "failed to allocate string to format: %ls", wzFormat);
1123
1124 hr = S_FALSE;
1125 }
1126 } while (S_FALSE == hr);
1112 - ExitOnFailure(hr, "failed to format string");
1127 + StrExitOnFailure(hr, "failed to format string");
1128
1129 LExit:
1130 if (pwzOriginal && fZeroOnRealloc)
@@ -1148,7 +1163,7 @@ extern "C" HRESULT DAPI StrAnsiAllocFormattedArgs(
1163 if (-1 == cch)
1164 {
1165 hr = E_INVALIDARG;
1151 - ExitOnFailure(hr, "failed to get size of destination string");
1166 + StrExitOnFailure(hr, "failed to get size of destination string");
1167 }
1168 cch /= sizeof(CHAR); //convert the count in bytes to count in characters
1169
@@ -1159,7 +1174,7 @@ extern "C" HRESULT DAPI StrAnsiAllocFormattedArgs(
1174 {
1175 cch = 256;
1176 hr = StrAnsiAlloc(ppsz, cch);
1162 - ExitOnFailure(hr, "failed to allocate string to format: %s", szFormat);
1177 + StrExitOnFailure(hr, "failed to allocate string to format: %s", szFormat);
1178 }
1179
1180 // format the message (grow until it fits or there is a failure)
@@ -1183,11 +1198,11 @@ extern "C" HRESULT DAPI StrAnsiAllocFormattedArgs(
1198 }
1199 cch *= 2;
1200 hr = StrAnsiAlloc(ppsz, cch);
1186 - ExitOnFailure(hr, "failed to allocate string to format: %hs", szFormat);
1201 + StrExitOnFailure(hr, "failed to allocate string to format: %hs", szFormat);
1202 hr = S_FALSE;
1203 }
1204 } while (S_FALSE == hr);
1190 - ExitOnFailure(hr, "failed to format string");
1205 + StrExitOnFailure(hr, "failed to format string");
1206
1207 LExit:
1208 ReleaseStr(pszOriginal);
@@ -1224,11 +1239,11 @@ extern "C" HRESULT DAPI StrAllocFromError(
1239
1240 if (0 == cchMessage)
1241 {
1227 - ExitWithLastError(hr, "Failed to format message for error: 0x%x", hrError);
1242 + StrExitWithLastError(hr, "Failed to format message for error: 0x%x", hrError);
1243 }
1244
1245 hr = StrAllocString(ppwzMessage, reinterpret_cast<LPCWSTR>(pvMessage), cchMessage);
1231 - ExitOnFailure(hr, "Failed to allocate string for message.");
1246 + StrExitOnFailure(hr, "Failed to allocate string for message.");
1247
1248 LExit:
1249 if (pvMessage)
@@ -1308,7 +1323,7 @@ extern "C" HRESULT DAPI StrFree(
1323 Assert(p);
1324
1325 HRESULT hr = MemFree(p);
1311 - ExitOnFailure(hr, "failed to free string");
1326 + StrExitOnFailure(hr, "failed to free string");
1327
1328 LExit:
1329 return hr;
@@ -1332,7 +1347,7 @@ extern "C" HRESULT DAPI StrReplaceStringAll(
1347 do
1348 {
1349 hr = StrReplaceString(ppwzOriginal, &dwStartIndex, wzOldSubString, wzNewSubString);
1335 - ExitOnFailure(hr, "Failed to replace substring");
1350 + StrExitOnFailure(hr, "Failed to replace substring");
1351 }
1352 while (S_OK == hr);
1353
@@ -1373,21 +1388,21 @@ extern "C" HRESULT DAPI StrReplaceString(
1388 }
1389
1390 hr = ::PtrdiffTToDWord(wzSubLocation - *ppwzOriginal, pdwStartIndex);
1376 - ExitOnFailure(hr, "Failed to diff pointers.");
1391 + StrExitOnFailure(hr, "Failed to diff pointers.");
1392
1393 hr = StrAllocString(&pwzBuffer, *ppwzOriginal, wzSubLocation - *ppwzOriginal);
1379 - ExitOnFailure(hr, "Failed to duplicate string.");
1394 + StrExitOnFailure(hr, "Failed to duplicate string.");
1395
1396 pwzBuffer[wzSubLocation - *ppwzOriginal] = '\0';
1397
1398 hr = StrAllocConcat(&pwzBuffer, wzNewSubString, 0);
1384 - ExitOnFailure(hr, "Failed to append new string.");
1399 + StrExitOnFailure(hr, "Failed to append new string.");
1400
1401 hr = StrAllocConcat(&pwzBuffer, wzSubLocation + wcslen(wzOldSubString), 0);
1387 - ExitOnFailure(hr, "Failed to append post string.");
1402 + StrExitOnFailure(hr, "Failed to append post string.");
1403
1404 hr = StrFree(*ppwzOriginal);
1390 - ExitOnFailure(hr, "Failed to free original string.");
1405 + StrExitOnFailure(hr, "Failed to free original string.");
1406
1407 *ppwzOriginal = pwzBuffer;
1408 *pdwStartIndex = *pdwStartIndex + static_cast<DWORD>(wcslen(wzNewSubString));
@@ -1477,10 +1492,10 @@ HRESULT DAPI StrAllocHexEncode(
1492 SIZE_T cchSource = sizeof(WCHAR) * (cbSource + 1);
1493
1494 hr = StrAlloc(ppwzDest, cchSource);
1480 - ExitOnFailure(hr, "Failed to allocate hex string.");
1495 + StrExitOnFailure(hr, "Failed to allocate hex string.");
1496
1497 hr = StrHexEncode(pbSource, cbSource, *ppwzDest, cchSource);
1483 - ExitOnFailure(hr, "Failed to encode hex string.");
1498 + StrExitOnFailure(hr, "Failed to encode hex string.");
1499
1500 LExit:
1501 return hr;
@@ -1509,7 +1524,7 @@ extern "C" HRESULT DAPI StrHexDecode(
1524 if (cbDest < cchSource / 2)
1525 {
1526 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
1512 - ExitOnRootFailure(hr, "Insufficient buffer to decode string '%ls' len: %u into %u bytes.", wzSource, cchSource, cbDest);
1527 + StrExitOnRootFailure(hr, "Insufficient buffer to decode string '%ls' len: %u into %u bytes.", wzSource, cchSource, cbDest);
1528 }
1529
1530 for (i = 0; i < cchSource / 2; ++i)
@@ -1547,20 +1562,20 @@ extern "C" HRESULT DAPI StrAllocHexDecode(
1562 DWORD cb = 0;
1563
1564 hr = ::StringCchLengthW(wzSource, STRSAFE_MAX_CCH, &cch);
1550 - ExitOnFailure(hr, "Failed to calculate length of source string.");
1565 + StrExitOnFailure(hr, "Failed to calculate length of source string.");
1566
1567 if (cch % 2)
1568 {
1569 hr = E_INVALIDARG;
1555 - ExitOnFailure(hr, "Invalid source parameter, string must be even length or it cannot be decoded.");
1570 + StrExitOnFailure(hr, "Invalid source parameter, string must be even length or it cannot be decoded.");
1571 }
1572
1573 cb = static_cast<DWORD>(cch / 2);
1574 pb = static_cast<BYTE*>(MemAlloc(cb, TRUE));
1560 - ExitOnNull(pb, hr, E_OUTOFMEMORY, "Failed to allocate memory for hex decode.");
1575 + StrExitOnNull(pb, hr, E_OUTOFMEMORY, "Failed to allocate memory for hex decode.");
1576
1577 hr = StrHexDecode(wzSource, pb, cb);
1563 - ExitOnFailure(hr, "Failed to decode source string.");
1578 + StrExitOnFailure(hr, "Failed to decode source string.");
1579
1580 *ppbDest = pb;
1581 pb = NULL;
@@ -1637,7 +1652,7 @@ extern "C" HRESULT DAPI StrAllocBase85Encode(
1652 ++cchDest; // add room for null terminator
1653
1654 hr = StrAlloc(pwzDest, cchDest);
1640 - ExitOnFailure(hr, "failed to allocate destination string");
1655 + StrExitOnFailure(hr, "failed to allocate destination string");
1656
1657 wzDest = *pwzDest;
1658
@@ -1740,7 +1755,7 @@ extern "C" HRESULT DAPI StrAllocBase85Decode(
1755 }
1756
1757 *ppbDest = static_cast<BYTE*>(MemAlloc(cbDest, FALSE));
1743 - ExitOnNull(*ppbDest, hr, E_OUTOFMEMORY, "failed allocate memory to decode the string");
1758 + StrExitOnNull(*ppbDest, hr, E_OUTOFMEMORY, "failed allocate memory to decode the string");
1759
1760 pbDest = *ppbDest;
1761 *pcbDest = cbDest;
@@ -1860,7 +1875,7 @@ extern "C" HRESULT DAPI MultiSzLen(
1875 DWORD_PTR dwMaxSize = 0;
1876
1877 hr = StrMaxLength(pwzMultiSz, &dwMaxSize);
1863 - ExitOnFailure(hr, "failed to get the max size of a string while calculating MULTISZ length");
1878 + StrExitOnFailure(hr, "failed to get the max size of a string while calculating MULTISZ length");
1879
1880 *pcch = 0;
1881 while (*pcch < dwMaxSize)
@@ -1914,7 +1929,7 @@ extern "C" HRESULT DAPI MultiSzPrepend(
1929 else
1930 {
1931 hr = MultiSzLen(*ppwzMultiSz, &cchMultiSz);
1917 - ExitOnFailure(hr, "failed to get length of multisz");
1932 + StrExitOnFailure(hr, "failed to get length of multisz");
1933 }
1934
1935 cchInsert = lstrlenW(pwzInsert);
@@ -1923,11 +1938,11 @@ extern "C" HRESULT DAPI MultiSzPrepend(
1938
1939 // Allocate the result buffer
1940 hr = StrAlloc(&pwzResult, cchResult + 1);
1926 - ExitOnFailure(hr, "failed to allocate result string");
1941 + StrExitOnFailure(hr, "failed to allocate result string");
1942
1943 // Prepend
1944 hr = ::StringCchCopyW(pwzResult, cchResult, pwzInsert);
1930 - ExitOnFailure(hr, "failed to copy prepend string: %ls", pwzInsert);
1945 + StrExitOnFailure(hr, "failed to copy prepend string: %ls", pwzInsert);
1946
1947 // If there was no MULTISZ, double null terminate our result, otherwise, copy the MULTISZ in
1948 if (0 == cchMultiSz)
@@ -1983,7 +1998,7 @@ extern "C" HRESULT DAPI MultiSzFindSubstring(
1998 SIZE_T cchProgress = 0;
1999
2000 hr = MultiSzLen(pwzMultiSz, &cchMultiSz);
1986 - ExitOnFailure(hr, "failed to get the length of a MULTISZ string");
2001 + StrExitOnFailure(hr, "failed to get the length of a MULTISZ string");
2002
2003 // Find the string containing the sub string
2004 hr = S_OK;
@@ -2049,7 +2064,7 @@ extern "C" HRESULT DAPI MultiSzFindString(
2064 SIZE_T cchProgress = 0;
2065
2066 hr = MultiSzLen(pwzMultiSz, &cchMutliSz);
2052 - ExitOnFailure(hr, "failed to get the length of a MULTISZ string");
2067 + StrExitOnFailure(hr, "failed to get the length of a MULTISZ string");
2068
2069 // Find the string
2070 hr = S_OK;
@@ -2116,7 +2131,7 @@ extern "C" HRESULT DAPI MultiSzRemoveString(
2131 SIZE_T cchProgress = 0;
2132
2133 hr = MultiSzLen(*ppwzMultiSz, &cchMultiSz);
2119 - ExitOnFailure(hr, "failed to get the length of a MULTISZ string");
2134 + StrExitOnFailure(hr, "failed to get the length of a MULTISZ string");
2135
2136 // Find the index we want to remove
2137 hr = S_OK;
@@ -2159,7 +2174,7 @@ extern "C" HRESULT DAPI MultiSzRemoveString(
2174 if (cchProgress > cchMultiSz)
2175 {
2176 hr = E_UNEXPECTED;
2162 - ExitOnFailure(hr, "failed to move past the string to be removed from MULTISZ");
2177 + StrExitOnFailure(hr, "failed to move past the string to be removed from MULTISZ");
2178 }
2179
2180 // Move on to the next character
@@ -2181,7 +2196,7 @@ extern "C" HRESULT DAPI MultiSzInsertString(
2196 __deref_inout __nullnullterminated LPWSTR* ppwzMultiSz,
2197 __inout_opt SIZE_T* pcchMultiSz,
2198 __in DWORD_PTR dwIndex,
2184 - __in __nullnullterminated LPCWSTR pwzInsert
2199 + __in_z LPCWSTR pwzInsert
2200 )
2201 {
2202 Assert(ppwzMultiSz && pwzInsert && *pwzInsert);
@@ -2202,7 +2217,7 @@ extern "C" HRESULT DAPI MultiSzInsertString(
2217 else
2218 {
2219 hr = MultiSzLen(*ppwzMultiSz, &cchMultiSz);
2205 - ExitOnFailure(hr, "failed to get the length of a MULTISZ string");
2220 + StrExitOnFailure(hr, "failed to get the length of a MULTISZ string");
2221 }
2222
2223 // Find the index we want to insert at
@@ -2220,7 +2235,7 @@ extern "C" HRESULT DAPI MultiSzInsertString(
2235 if ((dwCurrentIndex + 1 != dwIndex && L'\0' == *(wz + 1)) || cchProgress >= cchMultiSz)
2236 {
2237 hr = HRESULT_FROM_WIN32(ERROR_OBJECT_NOT_FOUND);
2223 - ExitOnRootFailure(hr, "requested to insert into an invalid index: %u in a MULTISZ", dwIndex);
2238 + StrExitOnRootFailure(hr, "requested to insert into an invalid index: %u in a MULTISZ", dwIndex);
2239 }
2240
2241 // Move on to the next string
@@ -2235,7 +2250,7 @@ extern "C" HRESULT DAPI MultiSzInsertString(
2250 cchResult = cchMultiSz + cchString + 1;
2251
2252 hr = StrAlloc(&pwzResult, cchResult);
2238 - ExitOnFailure(hr, "failed to allocate result string for MULTISZ insert");
2253 + StrExitOnFailure(hr, "failed to allocate result string for MULTISZ insert");
2254
2255 // Copy the part before the insert
2256 ::CopyMemory(pwzResult, *ppwzMultiSz, cchProgress * sizeof(WCHAR));
@@ -2273,7 +2288,7 @@ MultiSzReplaceString - replaces string at the specified index with a new one
2288 extern "C" HRESULT DAPI MultiSzReplaceString(
2289 __deref_inout __nullnullterminated LPWSTR* ppwzMultiSz,
2290 __in DWORD_PTR dwIndex,
2276 - __in __nullnullterminated LPCWSTR pwzString
2291 + __in_z LPCWSTR pwzString
2292 )
2293 {
2294 Assert(ppwzMultiSz && pwzString && *pwzString);
@@ -2281,10 +2296,10 @@ extern "C" HRESULT DAPI MultiSzReplaceString(
2296 HRESULT hr = S_OK;
2297
2298 hr = MultiSzRemoveString(ppwzMultiSz, dwIndex);
2284 - ExitOnFailure(hr, "failed to remove string from MULTISZ at the specified index: %u", dwIndex);
2299 + StrExitOnFailure(hr, "failed to remove string from MULTISZ at the specified index: %u", dwIndex);
2300
2301 hr = MultiSzInsertString(ppwzMultiSz, NULL, dwIndex, pwzString);
2287 - ExitOnFailure(hr, "failed to insert string into MULTISZ at the specified index: %u", dwIndex);
2302 + StrExitOnFailure(hr, "failed to insert string into MULTISZ at the specified index: %u", dwIndex);
2303
2304 LExit:
2305 return hr;
@@ -2344,7 +2359,7 @@ extern "C" HRESULT DAPI StrStringToInt16(
2359 LONGLONG ll = 0;
2360
2361 hr = StrStringToInt64(wzIn, cchIn, &ll);
2347 - ExitOnFailure(hr, "Failed to parse int64.");
2362 + StrExitOnFailure(hr, "Failed to parse int64.");
2363
2364 if (SHORT_MAX < ll || SHORT_MIN > ll)
2365 {
@@ -2370,7 +2385,7 @@ extern "C" HRESULT DAPI StrStringToUInt16(
2385 ULONGLONG ull = 0;
2386
2387 hr = StrStringToUInt64(wzIn, cchIn, &ull);
2373 - ExitOnFailure(hr, "Failed to parse uint64.");
2388 + StrExitOnFailure(hr, "Failed to parse uint64.");
2389
2390 if (USHORT_MAX < ull)
2391 {
@@ -2396,7 +2411,7 @@ extern "C" HRESULT DAPI StrStringToInt32(
2411 LONGLONG ll = 0;
2412
2413 hr = StrStringToInt64(wzIn, cchIn, &ll);
2399 - ExitOnFailure(hr, "Failed to parse int64.");
2414 + StrExitOnFailure(hr, "Failed to parse int64.");
2415
2416 if (INT_MAX < ll || INT_MIN > ll)
2417 {
@@ -2422,7 +2437,7 @@ extern "C" HRESULT DAPI StrStringToUInt32(
2437 ULONGLONG ull = 0;
2438
2439 hr = StrStringToUInt64(wzIn, cchIn, &ull);
2425 - ExitOnFailure(hr, "Failed to parse uint64.");
2440 + StrExitOnFailure(hr, "Failed to parse uint64.");
2441
2442 if (UINT_MAX < ull)
2443 {
@@ -2607,13 +2622,13 @@ extern "C" HRESULT DAPI StrArrayAllocString(
2622 UINT cNewStrArray;
2623
2624 hr = ::UIntAdd(*pcStrArray, 1, &cNewStrArray);
2610 - ExitOnFailure(hr, "Failed to increment the string array element count.");
2625 + StrExitOnFailure(hr, "Failed to increment the string array element count.");
2626
2627 hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(prgsczStrArray), cNewStrArray, sizeof(LPWSTR), ARRAY_GROWTH_SIZE);
2613 - ExitOnFailure(hr, "Failed to allocate memory for the string array.");
2628 + StrExitOnFailure(hr, "Failed to allocate memory for the string array.");
2629
2630 hr = StrAllocString(&(*prgsczStrArray)[*pcStrArray], wzSource, cchSource);
2616 - ExitOnFailure(hr, "Failed to allocate and assign the string.");
2631 + StrExitOnFailure(hr, "Failed to allocate and assign the string.");
2632
2633 *pcStrArray = cNewStrArray;
2634
@@ -2639,12 +2654,12 @@ extern "C" HRESULT DAPI StrArrayFree(
2654 if (NULL != rgsczStrArray[i])
2655 {
2656 hr = StrFree(rgsczStrArray[i]);
2642 - ExitOnFailure(hr, "Failed to free the string at index %u.", i);
2657 + StrExitOnFailure(hr, "Failed to free the string at index %u.", i);
2658 }
2659 }
2660
2661 hr = MemFree(rgsczStrArray);
2647 - ExitOnFailure(hr, "Failed to free memory for the string array.");
2662 + StrExitOnFailure(hr, "Failed to free memory for the string array.");
2663
2664 LExit:
2665 return hr;
@@ -2667,12 +2682,12 @@ extern "C" HRESULT DAPI StrSplitAllocArray(
2682
2683 // Copy wzSource so it is not modified.
2684 hr = StrAllocString(&sczCopy, wzSource, 0);
2670 - ExitOnFailure(hr, "Failed to copy the source string.");
2685 + StrExitOnFailure(hr, "Failed to copy the source string.");
2686
2687 for (LPCWSTR wzToken = ::wcstok_s(sczCopy, wzDelim, &wzContext); wzToken; wzToken = ::wcstok_s(NULL, wzDelim, &wzContext))
2688 {
2689 hr = StrArrayAllocString(prgsczStrArray, pcStrArray, wzToken, 0);
2675 - ExitOnFailure(hr, "Failed to add the string to the string array.");
2690 + StrExitOnFailure(hr, "Failed to add the string to the string array.");
2691 }
2692
2693 LExit:
@@ -2696,20 +2711,20 @@ static HRESULT StrAllocStringMapInvariant(
2711 HRESULT hr = S_OK;
2712
2713 hr = StrAllocString(pscz, wzSource, cchSource);
2699 - ExitOnFailure(hr, "Failed to allocate a copy of the source string.");
2714 + StrExitOnFailure(hr, "Failed to allocate a copy of the source string.");
2715
2716 if (0 == cchSource)
2717 {
2718 // Need the actual string size for LCMapString. This includes the null-terminator
2719 // but LCMapString doesn't care either way.
2720 hr = ::StringCchLengthW(*pscz, INT_MAX, reinterpret_cast<size_t*>(&cchSource));
2706 - ExitOnFailure(hr, "Failed to get the length of the string.");
2721 + StrExitOnFailure(hr, "Failed to get the length of the string.");
2722 }
2723
2724 // Convert the copy of the string to upper or lower case in-place.
2725 if (0 == ::LCMapStringW(LOCALE_INVARIANT, dwMapFlags, *pscz, cchSource, *pscz, cchSource))
2726 {
2712 - ExitWithLastError(hr, "Failed to convert the string case.");
2727 + StrExitWithLastError(hr, "Failed to convert the string case.");
2728 }
2729
2730 LExit:
@@ -2734,7 +2749,7 @@ extern "C" DAPI_(HRESULT) StrSecureZeroString(
2749 if (-1 == cch)
2750 {
2751 hr = E_INVALIDARG;
2737 - ExitOnFailure(hr, "Failed to get size of string");
2752 + StrExitOnFailure(hr, "Failed to get size of string");
2753 }
2754 else
2755 {
src/dutil/svcutil.cpp
+18 -3
@@ -2,6 +2,21 @@
2
3 #include "precomp.h"
4
5 +
6 +// Exit macros
7 +#define SvcExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_SVCUTIL, x, s, __VA_ARGS__)
8 +#define SvcExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_SVCUTIL, x, s, __VA_ARGS__)
9 +#define SvcExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_SVCUTIL, x, s, __VA_ARGS__)
10 +#define SvcExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_SVCUTIL, x, s, __VA_ARGS__)
11 +#define SvcExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_SVCUTIL, x, s, __VA_ARGS__)
12 +#define SvcExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_SVCUTIL, x, s, __VA_ARGS__)
13 +#define SvcExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_SVCUTIL, p, x, e, s, __VA_ARGS__)
14 +#define SvcExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_SVCUTIL, p, x, s, __VA_ARGS__)
15 +#define SvcExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_SVCUTIL, p, x, e, s, __VA_ARGS__)
16 +#define SvcExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_SVCUTIL, p, x, s, __VA_ARGS__)
17 +#define SvcExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_SVCUTIL, e, x, s, __VA_ARGS__)
18 +#define SvcExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_SVCUTIL, g, x, s, __VA_ARGS__)
19 +
20 /********************************************************************
21 SvcQueryConfig - queries the configuration of a service
22
@@ -21,16 +36,16 @@ extern "C" HRESULT DAPI SvcQueryConfig(
36 if (ERROR_INSUFFICIENT_BUFFER == er)
37 {
38 pConfig = static_cast<QUERY_SERVICE_CONFIGW*>(MemAlloc(cbConfig, TRUE));
24 - ExitOnNull(pConfig, hr, E_OUTOFMEMORY, "Failed to allocate memory to get configuration.");
39 + SvcExitOnNull(pConfig, hr, E_OUTOFMEMORY, "Failed to allocate memory to get configuration.");
40
41 if (!::QueryServiceConfigW(sch, pConfig, cbConfig, &cbConfig))
42 {
28 - ExitWithLastError(hr, "Failed to read service configuration.");
43 + SvcExitWithLastError(hr, "Failed to read service configuration.");
44 }
45 }
46 else
47 {
33 - ExitOnWin32Error(er, hr, "Failed to query service configuration.");
48 + SvcExitOnWin32Error(er, hr, "Failed to query service configuration.");
49 }
50 }
51
src/dutil/thmutil.cpp
+5 -3
@@ -693,7 +693,7 @@ DAPI_(HRESULT) ThemeCreateParentWindow(
693 }
694
695 LExit:
696 - MemFree(pMonitorContext);
696 + ReleaseMem(pMonitorContext);
697
698 return hr;
699 }
@@ -1514,7 +1514,7 @@ LExit:
1514 DAPI_(HRESULT) ThemeGetTextControl(
1515 __in const THEME* pTheme,
1516 __in DWORD dwControl,
1517 - __out_z LPWSTR* psczText
1517 + __inout_z LPWSTR* psczText
1518 )
1519 {
1520 HRESULT hr = S_OK;
@@ -1729,6 +1729,7 @@ static HRESULT ParseImage(
1729 LPWSTR sczImageFile = NULL;
1730 int iResourceId = 0;
1731 Gdiplus::Bitmap* pBitmap = NULL;
1732 + *phImage = NULL;
1733
1734 hr = XmlGetAttribute(pElement, L"ImageResource", &bstr);
1735 ThmExitOnFailure(hr, "Failed to get image resource attribute.");
@@ -1801,6 +1802,7 @@ static HRESULT ParseIcon(
1802 BSTR bstr = NULL;
1803 LPWSTR sczImageFile = NULL;
1804 int iResourceId = 0;
1805 + *phIcon = NULL;
1806
1807 hr = XmlGetAttribute(pElement, L"IconResource", &bstr);
1808 ThmExitOnFailure(hr, "Failed to get icon resource attribute.");
@@ -4720,7 +4722,7 @@ static HRESULT ShowControl(
4722
4723 hr = S_OK;
4724
4723 - Button_SetCheck(hWnd, (!sczText && !pControl->sczValue) || CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, sczText, -1, pControl->sczValue, -1));
4725 + Button_SetCheck(hWnd, (!sczText && !pControl->sczValue) || (sczText && CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, sczText, -1, pControl->sczValue, -1)));
4726 }
4727 }
4728
src/dutil/timeutil.cpp
+26 -11
@@ -2,6 +2,21 @@
2
3 #include "precomp.h"
4
5 +
6 +// Exit macros
7 +#define TimeExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_TIMEUTIL, x, s, __VA_ARGS__)
8 +#define TimeExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_TIMEUTIL, x, s, __VA_ARGS__)
9 +#define TimeExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_TIMEUTIL, x, s, __VA_ARGS__)
10 +#define TimeExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_TIMEUTIL, x, s, __VA_ARGS__)
11 +#define TimeExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_TIMEUTIL, x, s, __VA_ARGS__)
12 +#define TimeExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_TIMEUTIL, x, s, __VA_ARGS__)
13 +#define TimeExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_TIMEUTIL, p, x, e, s, __VA_ARGS__)
14 +#define TimeExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_TIMEUTIL, p, x, s, __VA_ARGS__)
15 +#define TimeExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_TIMEUTIL, p, x, e, s, __VA_ARGS__)
16 +#define TimeExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_TIMEUTIL, p, x, s, __VA_ARGS__)
17 +#define TimeExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_TIMEUTIL, e, x, s, __VA_ARGS__)
18 +#define TimeExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_TIMEUTIL, g, x, s, __VA_ARGS__)
19 +
20 const LPCWSTR DAY_OF_WEEK[] = { L"Sun", L"Mon", L"Tue", L"Wed", L"Thu", L"Fri", L"Sat" };
21 const LPCWSTR MONTH_OF_YEAR[] = { L"None", L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun", L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec" };
22 enum TIME_PARSER { DayOfWeek, DayOfMonth, MonthOfYear, Year, Hours, Minutes, Seconds, TimeZone };
@@ -39,7 +54,7 @@ extern "C" HRESULT DAPI TimeFromString(
54 LPWSTR pwzEnd = NULL;
55
56 hr = StrAllocString(&pwzTime, wzTime, 0);
42 - ExitOnFailure(hr, "Failed to copy time.");
57 + TimeExitOnFailure(hr, "Failed to copy time.");
58
59 pwzStart = pwzEnd = pwzTime;
60 while (pwzEnd && *pwzEnd)
@@ -58,7 +73,7 @@ extern "C" HRESULT DAPI TimeFromString(
73 {
74 case DayOfWeek:
75 hr = DayFromString(pwzStart, &sysTime.wDayOfWeek);
61 - ExitOnFailure(hr, "Failed to convert string to day: %ls", pwzStart);
76 + TimeExitOnFailure(hr, "Failed to convert string to day: %ls", pwzStart);
77 break;
78
79 case DayOfMonth:
@@ -67,7 +82,7 @@ extern "C" HRESULT DAPI TimeFromString(
82
83 case MonthOfYear:
84 hr = MonthFromString(pwzStart, &sysTime.wMonth);
70 - ExitOnFailure(hr, "Failed to convert to month: %ls", pwzStart);
85 + TimeExitOnFailure(hr, "Failed to convert to month: %ls", pwzStart);
86 break;
87
88 case Year:
@@ -104,7 +119,7 @@ extern "C" HRESULT DAPI TimeFromString(
119
120 if (!::SystemTimeToFileTime(&sysTime, pFileTime))
121 {
107 - ExitWithLastError(hr, "Failed to convert system time to file time.");
122 + TimeExitWithLastError(hr, "Failed to convert system time to file time.");
123 }
124
125 LExit:
@@ -134,7 +149,7 @@ extern "C" HRESULT DAPI TimeFromString3339(
149 LPWSTR pwzEnd = NULL;
150
151 hr = StrAllocString(&pwzTime, wzTime, 0);
137 - ExitOnFailure(hr, "Failed to copy time.");
152 + TimeExitOnFailure(hr, "Failed to copy time.");
153
154 pwzStart = pwzEnd = pwzTime;
155 while (pwzEnd && *pwzEnd)
@@ -188,7 +203,7 @@ extern "C" HRESULT DAPI TimeFromString3339(
203
204 if (!::SystemTimeToFileTime(&sysTime, pFileTime))
205 {
191 - ExitWithLastError(hr, "Failed to convert system time to file time.");
206 + TimeExitWithLastError(hr, "Failed to convert system time to file time.");
207 }
208
209 LExit:
@@ -291,29 +306,29 @@ HRESULT DAPI TimeSystemToDateTimeString(
306 iLenDate = ::GetDateFormatW(locale, 0, pst, DATE_FORMAT, NULL, 0);
307 if (0 >= iLenDate)
308 {
294 - ExitWithLastError(hr, "Failed to get date format with NULL");
309 + TimeExitWithLastError(hr, "Failed to get date format with NULL");
310 }
311
312 iLenTime = ::GetTimeFormatW(locale, 0, pst, TIME_FORMAT, NULL, 0);
313 if (0 >= iLenTime)
314 {
300 - ExitWithLastError(hr, "Failed to get time format with NULL");
315 + TimeExitWithLastError(hr, "Failed to get time format with NULL");
316 }
317
318 // Between both lengths we account for 2 null terminators, and only need one, so we subtract one
319 hr = StrAlloc(ppwz, iLenDate + iLenTime - 1);
305 - ExitOnFailure(hr, "Failed to allocate string");
320 + TimeExitOnFailure(hr, "Failed to allocate string");
321
322 if (!::GetDateFormatW(locale, 0, pst, DATE_FORMAT, *ppwz, iLenDate))
323 {
309 - ExitWithLastError(hr, "Failed to get date format with buffer");
324 + TimeExitWithLastError(hr, "Failed to get date format with buffer");
325 }
326 // Space to separate them
327 (*ppwz)[iLenDate - 1] = ' ';
328
329 if (!::GetTimeFormatW(locale, 0, pst, TIME_FORMAT, (*ppwz) + iLenDate - 1, iLenTime))
330 {
316 - ExitWithLastError(hr, "Failed to get time format with buffer");
331 + TimeExitWithLastError(hr, "Failed to get time format with buffer");
332 }
333
334 LExit:
src/dutil/uncutil.cpp
+20 -5
@@ -2,6 +2,21 @@
2
3 #include "precomp.h"
4
5 +
6 +// Exit macros
7 +#define UncExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_UNCUTIL, x, s, __VA_ARGS__)
8 +#define UncExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_UNCUTIL, x, s, __VA_ARGS__)
9 +#define UncExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_UNCUTIL, x, s, __VA_ARGS__)
10 +#define UncExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_UNCUTIL, x, s, __VA_ARGS__)
11 +#define UncExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_UNCUTIL, x, s, __VA_ARGS__)
12 +#define UncExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_UNCUTIL, x, s, __VA_ARGS__)
13 +#define UncExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_UNCUTIL, p, x, e, s, __VA_ARGS__)
14 +#define UncExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_UNCUTIL, p, x, s, __VA_ARGS__)
15 +#define UncExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_UNCUTIL, p, x, e, s, __VA_ARGS__)
16 +#define UncExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_UNCUTIL, p, x, s, __VA_ARGS__)
17 +#define UncExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_UNCUTIL, e, x, s, __VA_ARGS__)
18 +#define UncExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_UNCUTIL, g, x, s, __VA_ARGS__)
19 +
20 DAPI_(HRESULT) UncConvertFromMountedDrive(
21 __inout LPWSTR *psczUNCPath,
22 __in LPCWSTR sczMountedDrivePath
@@ -14,7 +29,7 @@ DAPI_(HRESULT) UncConvertFromMountedDrive(
29
30 // Only copy drive letter and colon
31 hr = StrAllocString(&sczDrive, sczMountedDrivePath, 2);
17 - ExitOnFailure(hr, "Failed to copy drive");
32 + UncExitOnFailure(hr, "Failed to copy drive");
33
34 // ERROR_NOT_CONNECTED means it's not a mapped drive
35 er = ::WNetGetConnectionW(sczDrive, NULL, &dwLength);
@@ -23,7 +38,7 @@ DAPI_(HRESULT) UncConvertFromMountedDrive(
38 er = ERROR_SUCCESS;
39
40 hr = StrAlloc(psczUNCPath, dwLength);
26 - ExitOnFailure(hr, "Failed to allocate string to get raw UNC path of length %u", dwLength);
41 + UncExitOnFailure(hr, "Failed to allocate string to get raw UNC path of length %u", dwLength);
42
43 er = ::WNetGetConnectionW(sczDrive, *psczUNCPath, &dwLength);
44 if (ERROR_CONNECTION_UNAVAIL == er)
@@ -31,11 +46,11 @@ DAPI_(HRESULT) UncConvertFromMountedDrive(
46 // This means the drive is remembered but not currently connected, this can mean the location is accessible via UNC path but not via mounted drive path
47 er = ERROR_SUCCESS;
48 }
34 - ExitOnWin32Error(er, hr, "::WNetGetConnectionW() failed with buffer provided on drive %ls", sczDrive);
49 + UncExitOnWin32Error(er, hr, "::WNetGetConnectionW() failed with buffer provided on drive %ls", sczDrive);
50
51 // Skip drive letter and colon
52 hr = StrAllocConcat(psczUNCPath, sczMountedDrivePath + 2, 0);
38 - ExitOnFailure(hr, "Failed to copy rest of database path");
53 + UncExitOnFailure(hr, "Failed to copy rest of database path");
54 }
55 else
56 {
@@ -44,7 +59,7 @@ DAPI_(HRESULT) UncConvertFromMountedDrive(
59 er = ERROR_NO_DATA;
60 }
61
47 - ExitOnWin32Error(er, hr, "::WNetGetConnectionW() failed on drive %ls", sczDrive);
62 + UncExitOnWin32Error(er, hr, "::WNetGetConnectionW() failed on drive %ls", sczDrive);
63 }
64
65 LExit:
src/dutil/uriutil.cpp
+54 -39
@@ -3,6 +3,21 @@
3 #include "precomp.h"
4
5
6 +// Exit macros
7 +#define UriExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_URIUTIL, x, s, __VA_ARGS__)
8 +#define UriExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_URIUTIL, x, s, __VA_ARGS__)
9 +#define UriExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_URIUTIL, x, s, __VA_ARGS__)
10 +#define UriExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_URIUTIL, x, s, __VA_ARGS__)
11 +#define UriExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_URIUTIL, x, s, __VA_ARGS__)
12 +#define UriExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_URIUTIL, x, s, __VA_ARGS__)
13 +#define UriExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_URIUTIL, p, x, e, s, __VA_ARGS__)
14 +#define UriExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_URIUTIL, p, x, s, __VA_ARGS__)
15 +#define UriExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_URIUTIL, p, x, e, s, __VA_ARGS__)
16 +#define UriExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_URIUTIL, p, x, s, __VA_ARGS__)
17 +#define UriExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_URIUTIL, e, x, s, __VA_ARGS__)
18 +#define UriExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_URIUTIL, g, x, s, __VA_ARGS__)
19 +
20 +
21 //
22 // UriCanonicalize - canonicalizes a URI.
23 //
@@ -16,11 +31,11 @@ extern "C" HRESULT DAPI UriCanonicalize(
31
32 if (!::InternetCanonicalizeUrlW(*psczUri, wz, &cch, ICU_DECODE))
33 {
19 - ExitWithLastError(hr, "Failed to canonicalize URI.");
34 + UriExitWithLastError(hr, "Failed to canonicalize URI.");
35 }
36
37 hr = StrAllocString(psczUri, wz, cch);
23 - ExitOnFailure(hr, "Failed copy canonicalized URI.");
38 + UriExitOnFailure(hr, "Failed copy canonicalized URI.");
39
40 LExit:
41 return hr;
@@ -83,7 +98,7 @@ extern "C" HRESULT DAPI UriCrack(
98
99 if (!::InternetCrackUrlW(wzUri, 0, ICU_DECODE | ICU_ESCAPE, &components))
100 {
86 - ExitWithLastError(hr, "Failed to crack URI.");
101 + UriExitWithLastError(hr, "Failed to crack URI.");
102 }
103
104 if (pScheme)
@@ -94,7 +109,7 @@ extern "C" HRESULT DAPI UriCrack(
109 if (psczHostName)
110 {
111 hr = StrAllocString(psczHostName, components.lpszHostName, components.dwHostNameLength);
97 - ExitOnFailure(hr, "Failed to copy host name.");
112 + UriExitOnFailure(hr, "Failed to copy host name.");
113 }
114
115 if (pPort)
@@ -105,25 +120,25 @@ extern "C" HRESULT DAPI UriCrack(
120 if (psczUser)
121 {
122 hr = StrAllocString(psczUser, components.lpszUserName, components.dwUserNameLength);
108 - ExitOnFailure(hr, "Failed to copy user name.");
123 + UriExitOnFailure(hr, "Failed to copy user name.");
124 }
125
126 if (psczPassword)
127 {
128 hr = StrAllocString(psczPassword, components.lpszPassword, components.dwPasswordLength);
114 - ExitOnFailure(hr, "Failed to copy password.");
129 + UriExitOnFailure(hr, "Failed to copy password.");
130 }
131
132 if (psczPath)
133 {
134 hr = StrAllocString(psczPath, components.lpszUrlPath, components.dwUrlPathLength);
120 - ExitOnFailure(hr, "Failed to copy path.");
135 + UriExitOnFailure(hr, "Failed to copy path.");
136 }
137
138 if (psczQueryString)
139 {
140 hr = StrAllocString(psczQueryString, components.lpszExtraInfo, components.dwExtraInfoLength);
126 - ExitOnFailure(hr, "Failed to copy query string.");
141 + UriExitOnFailure(hr, "Failed to copy query string.");
142 }
143
144 LExit:
@@ -142,7 +157,7 @@ extern "C" HRESULT DAPI UriCrackEx(
157 HRESULT hr = S_OK;
158
159 hr = UriCrack(wzUri, &pUriInfo->scheme, &pUriInfo->sczHostName, &pUriInfo->port, &pUriInfo->sczUser, &pUriInfo->sczPassword, &pUriInfo->sczPath, &pUriInfo->sczQueryString);
145 - ExitOnFailure(hr, "Failed to crack URI.");
160 + UriExitOnFailure(hr, "Failed to crack URI.");
161
162 LExit:
163 return hr;
@@ -195,11 +210,11 @@ extern "C" HRESULT DAPI UriCreate(
210
211 if (!::InternetCreateUrlW(&components, ICU_ESCAPE, wz, &cch))
212 {
198 - ExitWithLastError(hr, "Failed to create URI.");
213 + UriExitWithLastError(hr, "Failed to create URI.");
214 }
215
216 hr = StrAllocString(psczUri, wz, cch);
202 - ExitOnFailure(hr, "Failed copy created URI.");
217 + UriExitOnFailure(hr, "Failed copy created URI.");
218
219 LExit:
220 return hr;
@@ -227,13 +242,13 @@ extern "C" HRESULT DAPI UriGetServerAndResource(
242 LPWSTR sczQueryString = NULL;
243
244 hr = UriCrack(wzUri, &scheme, &sczHostName, &port, &sczUser, &sczPassword, &sczPath, &sczQueryString);
230 - ExitOnFailure(hr, "Failed to crack URI.");
245 + UriExitOnFailure(hr, "Failed to crack URI.");
246
247 hr = UriCreate(psczServer, scheme, sczHostName, port, sczUser, sczPassword, NULL, NULL);
233 - ExitOnFailure(hr, "Failed to allocate server URI.");
248 + UriExitOnFailure(hr, "Failed to allocate server URI.");
249
250 hr = UriCreate(psczResource, INTERNET_SCHEME_UNKNOWN, NULL, INTERNET_INVALID_PORT_NUMBER, NULL, NULL, sczPath, sczQueryString);
236 - ExitOnFailure(hr, "Failed to allocate resource URI.");
251 + UriExitOnFailure(hr, "Failed to allocate resource URI.");
252
253 LExit:
254 ReleaseStr(sczQueryString);
@@ -265,13 +280,13 @@ extern "C" HRESULT DAPI UriFile(
280
281 if (!::InternetCrackUrlW(wzUri, 0, ICU_DECODE | ICU_ESCAPE, &uc))
282 {
268 - ExitWithLastError(hr, "Failed to crack URI.");
283 + UriExitWithLastError(hr, "Failed to crack URI.");
284 }
285
286 // Copy only the file name. Fortunately, PathFile() understands that
287 // forward slashes can be directory separators like backslashes.
288 hr = StrAllocString(psczFile, PathFile(wz), 0);
274 - ExitOnFailure(hr, "Failed to copy file name");
289 + UriExitOnFailure(hr, "Failed to copy file name");
290
291 LExit:
292 return hr;
@@ -367,7 +382,7 @@ extern "C" HRESULT DAPI UriRoot(
382 LPCWSTR pwcSlash = NULL;
383
384 hr = UriProtocol(wzUri, &protocol);
370 - ExitOnFailure(hr, "Invalid URI.");
385 + UriExitOnFailure(hr, "Invalid URI.");
386
387 switch (protocol)
388 {
@@ -377,7 +392,7 @@ extern "C" HRESULT DAPI UriRoot(
392 if (((L'a' <= wzUri[8] && L'z' >= wzUri[8]) || (L'A' <= wzUri[8] && L'Z' >= wzUri[8])) && L':' == wzUri[9])
393 {
394 hr = StrAlloc(ppwzRoot, 4);
380 - ExitOnFailure(hr, "Failed to allocate string for root of URI.");
395 + UriExitOnFailure(hr, "Failed to allocate string for root of URI.");
396 *ppwzRoot[0] = wzUri[8];
397 *ppwzRoot[1] = L':';
398 *ppwzRoot[2] = L'\\';
@@ -386,7 +401,7 @@ extern "C" HRESULT DAPI UriRoot(
401 else
402 {
403 hr = E_INVALIDARG;
389 - ExitOnFailure(hr, "Invalid file path in URI.");
404 + UriExitOnFailure(hr, "Invalid file path in URI.");
405 }
406 }
407 else // UNC share
@@ -395,23 +410,23 @@ extern "C" HRESULT DAPI UriRoot(
410 if (!pwcSlash)
411 {
412 hr = E_INVALIDARG;
398 - ExitOnFailure(hr, "Invalid server name in URI.");
413 + UriExitOnFailure(hr, "Invalid server name in URI.");
414 }
415 else
416 {
417 hr = StrAllocString(ppwzRoot, L"\\\\", 64);
403 - ExitOnFailure(hr, "Failed to allocate string for root of URI.");
418 + UriExitOnFailure(hr, "Failed to allocate string for root of URI.");
419
420 pwcSlash = wcschr(pwcSlash + 1, L'/');
421 if (pwcSlash)
422 {
423 hr = StrAllocConcat(ppwzRoot, wzUri + 8, pwcSlash - wzUri - 8);
409 - ExitOnFailure(hr, "Failed to add server/share to root of URI.");
424 + UriExitOnFailure(hr, "Failed to add server/share to root of URI.");
425 }
426 else
427 {
428 hr = StrAllocConcat(ppwzRoot, wzUri + 8, 0);
414 - ExitOnFailure(hr, "Failed to add server/share to root of URI.");
429 + UriExitOnFailure(hr, "Failed to add server/share to root of URI.");
430 }
431
432 // replace all slashes with backslashes to be truly UNC.
@@ -431,12 +446,12 @@ extern "C" HRESULT DAPI UriRoot(
446 if (pwcSlash)
447 {
448 hr = StrAllocString(ppwzRoot, wzUri, pwcSlash - wzUri);
434 - ExitOnFailure(hr, "Failed allocate root from URI.");
449 + UriExitOnFailure(hr, "Failed allocate root from URI.");
450 }
451 else
452 {
453 hr = StrAllocString(ppwzRoot, wzUri, 0);
439 - ExitOnFailure(hr, "Failed allocate root from URI.");
454 + UriExitOnFailure(hr, "Failed allocate root from URI.");
455 }
456 break;
457
@@ -445,18 +460,18 @@ extern "C" HRESULT DAPI UriRoot(
460 if (pwcSlash)
461 {
462 hr = StrAllocString(ppwzRoot, wzUri, pwcSlash - wzUri);
448 - ExitOnFailure(hr, "Failed allocate root from URI.");
463 + UriExitOnFailure(hr, "Failed allocate root from URI.");
464 }
465 else
466 {
467 hr = StrAllocString(ppwzRoot, wzUri, 0);
453 - ExitOnFailure(hr, "Failed allocate root from URI.");
468 + UriExitOnFailure(hr, "Failed allocate root from URI.");
469 }
470 break;
471
472 default:
473 hr = E_INVALIDARG;
459 - ExitOnFailure(hr, "Unknown URI protocol.");
474 + UriExitOnFailure(hr, "Unknown URI protocol.");
475 }
476
477 if (pProtocol)
@@ -473,7 +488,7 @@ extern "C" HRESULT DAPI UriResolve(
488 __in_z LPCWSTR wzUri,
489 __in_opt LPCWSTR wzBaseUri,
490 __out LPWSTR* ppwzResolvedUri,
476 - __out_opt const URI_PROTOCOL* pResolvedProtocol
491 + __out_opt URI_PROTOCOL* pResolvedProtocol
492 )
493 {
494 UNREFERENCED_PARAMETER(wzUri);
@@ -486,45 +501,45 @@ extern "C" HRESULT DAPI UriResolve(
501 URI_PROTOCOL protocol = URI_PROTOCOL_UNKNOWN;
502
503 hr = UriProtocol(wzUri, &protocol);
489 - ExitOnFailure(hr, "Failed to determine protocol for URL: %ls", wzUri);
504 + UriExitOnFailure(hr, "Failed to determine protocol for URL: %ls", wzUri);
505
491 - ExitOnNull(ppwzResolvedUri, hr, E_INVALIDARG, "Failed to resolve URI, because no method of output was provided");
506 + UriExitOnNull(ppwzResolvedUri, hr, E_INVALIDARG, "Failed to resolve URI, because no method of output was provided");
507
508 if (URI_PROTOCOL_UNKNOWN == protocol)
509 {
495 - ExitOnNull(wzBaseUri, hr, E_INVALIDARG, "Failed to resolve URI - base URI provided was NULL");
510 + UriExitOnNull(wzBaseUri, hr, E_INVALIDARG, "Failed to resolve URI - base URI provided was NULL");
511
512 if (L'/' == *wzUri || L'\\' == *wzUri)
513 {
514 hr = UriRoot(wzBaseUri, ppwzResolvedUri, &protocol);
500 - ExitOnFailure(hr, "Failed to get root from URI: %ls", wzBaseUri);
515 + UriExitOnFailure(hr, "Failed to get root from URI: %ls", wzBaseUri);
516
517 hr = StrAllocConcat(ppwzResolvedUri, wzUri, 0);
503 - ExitOnFailure(hr, "Failed to concat file to base URI.");
518 + UriExitOnFailure(hr, "Failed to concat file to base URI.");
519 }
520 else
521 {
522 hr = UriProtocol(wzBaseUri, &protocol);
508 - ExitOnFailure(hr, "Failed to get protocol of base URI: %ls", wzBaseUri);
523 + UriExitOnFailure(hr, "Failed to get protocol of base URI: %ls", wzBaseUri);
524
525 LPCWSTR pwcFile = const_cast<LPCWSTR> (UriFile(wzBaseUri));
526 if (!pwcFile)
527 {
528 hr = E_INVALIDARG;
514 - ExitOnFailure(hr, "Failed to get file from base URI: %ls", wzBaseUri);
529 + UriExitOnFailure(hr, "Failed to get file from base URI: %ls", wzBaseUri);
530 }
531
532 hr = StrAllocString(ppwzResolvedUri, wzBaseUri, pwcFile - wzBaseUri);
518 - ExitOnFailure(hr, "Failed to allocate string for resolved URI.");
533 + UriExitOnFailure(hr, "Failed to allocate string for resolved URI.");
534
535 hr = StrAllocConcat(ppwzResolvedUri, wzUri, 0);
521 - ExitOnFailure(hr, "Failed to concat file to resolved URI.");
536 + UriExitOnFailure(hr, "Failed to concat file to resolved URI.");
537 }
538 }
539 else
540 {
541 hr = StrAllocString(ppwzResolvedUri, wzUri, 0);
527 - ExitOnFailure(hr, "Failed to copy resolved URI.");
542 + UriExitOnFailure(hr, "Failed to copy resolved URI.");
543 }
544
545 if (pResolvedProtocol)
src/dutil/userutil.cpp
+38 -23
@@ -2,6 +2,21 @@
2
3 #include "precomp.h"
4
5 +
6 +// UserExit macros
7 +#define UserExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_USERUTIL, x, s, __VA_ARGS__)
8 +#define UserExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_USERUTIL, x, s, __VA_ARGS__)
9 +#define UserExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_USERUTIL, x, s, __VA_ARGS__)
10 +#define UserExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_USERUTIL, x, s, __VA_ARGS__)
11 +#define UserExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_USERUTIL, x, s, __VA_ARGS__)
12 +#define UserExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_USERUTIL, x, s, __VA_ARGS__)
13 +#define UserExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_USERUTIL, p, x, e, s, __VA_ARGS__)
14 +#define UserExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_USERUTIL, p, x, s, __VA_ARGS__)
15 +#define UserExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_USERUTIL, p, x, e, s, __VA_ARGS__)
16 +#define UserExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_USERUTIL, p, x, s, __VA_ARGS__)
17 +#define UserExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_USERUTIL, e, x, s, __VA_ARGS__)
18 +#define UserExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_USERUTIL, g, x, s, __VA_ARGS__)
19 +
20 static BOOL CheckIsMemberHelper(
21 __in_z LPCWSTR pwzGroupUserDomain,
22 __in_ecount(cguiGroupData) const GROUP_USERS_INFO_0 *pguiGroupData,
@@ -29,14 +44,14 @@ extern "C" HRESULT DAPI UserBuildDomainUserName(
44 if (cch >= cchLeft)
45 {
46 hr = ERROR_MORE_DATA;
32 - ExitOnFailure(hr, "Buffer size is not big enough to hold domain name: %ls", pwzDomain);
47 + UserExitOnFailure(hr, "Buffer size is not big enough to hold domain name: %ls", pwzDomain);
48 }
49 else if (cch > 0)
50 {
51 // handle the domain case
52
53 hr = ::StringCchCopyNW(pwz, cchWz, pwzDomain, cchLeft - 1); // last parameter does not include '\0'
39 - ExitOnFailure(hr, "Failed to copy Domain onto string.");
54 + UserExitOnFailure(hr, "Failed to copy Domain onto string.");
55
56 cchLeft -= cch;
57 pwz += cch;
@@ -45,11 +60,11 @@ extern "C" HRESULT DAPI UserBuildDomainUserName(
60 if (1 >= cchLeft)
61 {
62 hr = ERROR_MORE_DATA;
48 - ExitOnFailure(hr, "Insufficient buffer size while building domain user name");
63 + UserExitOnFailure(hr, "Insufficient buffer size while building domain user name");
64 }
65
66 hr = ::StringCchCopyNW(pwz, cchWz, L"\\", cchLeft - 1); // last parameter does not include '\0'
52 - ExitOnFailure(hr, "Failed to copy backslash onto string.");
67 + UserExitOnFailure(hr, "Failed to copy backslash onto string.");
68
69 --cchLeft;
70 ++pwz;
@@ -60,11 +75,11 @@ extern "C" HRESULT DAPI UserBuildDomainUserName(
75 if (cch >= cchLeft)
76 {
77 hr = ERROR_MORE_DATA;
63 - ExitOnFailure(hr, "Buffer size is not big enough to hold user name: %ls", pwzName);
78 + UserExitOnFailure(hr, "Buffer size is not big enough to hold user name: %ls", pwzName);
79 }
80
81 hr = ::StringCchCopyNW(pwz, cchWz, pwzName, cchLeft - 1); // last parameter does not include '\0'
67 - ExitOnFailure(hr, "Failed to copy User name onto string.");
82 + UserExitOnFailure(hr, "Failed to copy User name onto string.");
83
84 LExit:
85 return hr;
@@ -98,10 +113,10 @@ extern "C" HRESULT DAPI UserCheckIsMember(
113 VARIANT_BOOL vtBoolResult = VARIANT_FALSE;
114
115 hr = UserBuildDomainUserName(wzGroupUserDomain, countof(wzGroupUserDomain), pwzGroupName, pwzGroupDomain);
101 - ExitOnFailure(hr, "Failed to build group name from group domain %ls, group name %ls", pwzGroupDomain, pwzGroupName);
116 + UserExitOnFailure(hr, "Failed to build group name from group domain %ls, group name %ls", pwzGroupDomain, pwzGroupName);
117
118 hr = UserBuildDomainUserName(wzUserDomain, countof(wzUserDomain), pwzName, pwzDomain);
104 - ExitOnFailure(hr, "Failed to build group name from group domain %ls, group name %ls", pwzGroupDomain, pwzGroupName);
119 + UserExitOnFailure(hr, "Failed to build group name from group domain %ls, group name %ls", pwzGroupDomain, pwzGroupName);
120
121 if (pwzDomain && *pwzDomain)
122 {
@@ -115,12 +130,12 @@ extern "C" HRESULT DAPI UserCheckIsMember(
130 Trace(REPORT_VERBOSE, "failed to get groups for user %ls from domain %ls with error code 0x%x - continuing", pwzName, (wz != NULL) ? wz : L"", HRESULT_FROM_WIN32(er));
131 er = ERROR_SUCCESS;
132 }
118 - ExitOnWin32Error(er, hr, "Failed to get list of global groups for user while checking group membership information for user: %ls", pwzName);
133 + UserExitOnWin32Error(er, hr, "Failed to get list of global groups for user while checking group membership information for user: %ls", pwzName);
134
135 if (dwRead != dwTotal)
136 {
137 hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA);
123 - ExitOnRootFailure(hr, "Failed to get entire list of groups (global) for user while checking group membership information for user: %ls", pwzName);
138 + UserExitOnRootFailure(hr, "Failed to get entire list of groups (global) for user while checking group membership information for user: %ls", pwzName);
139 }
140
141 if (CheckIsMemberHelper(wzGroupUserDomain, pguiGroupData, dwRead))
@@ -143,12 +158,12 @@ extern "C" HRESULT DAPI UserCheckIsMember(
158 Trace(REPORT_VERBOSE, "failed to get local groups for user %ls from domain %ls with error code 0x%x - continuing", pwzName, (wz != NULL) ? wz : L"", HRESULT_FROM_WIN32(er));
159 er = ERROR_SUCCESS;
160 }
146 - ExitOnWin32Error(er, hr, "Failed to get list of groups for user while checking group membership information for user: %ls", pwzName);
161 + UserExitOnWin32Error(er, hr, "Failed to get list of groups for user while checking group membership information for user: %ls", pwzName);
162
163 if (dwRead != dwTotal)
164 {
165 hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA);
151 - ExitOnRootFailure(hr, "Failed to get entire list of groups (local) for user while checking group membership information for user: %ls", pwzName);
166 + UserExitOnRootFailure(hr, "Failed to get entire list of groups (local) for user while checking group membership information for user: %ls", pwzName);
167 }
168
169 if (CheckIsMemberHelper(wzGroupUserDomain, pguiGroupData, dwRead))
@@ -159,18 +174,18 @@ extern "C" HRESULT DAPI UserCheckIsMember(
174
175 // If the above methods failed, let's try active directory
176 hr = UserCreateADsPath(pwzDomain, pwzName, &bstrUser);
162 - ExitOnFailure(hr, "failed to create user ADsPath in order to check group membership for group: %ls domain: %ls", pwzName, pwzDomain);
177 + UserExitOnFailure(hr, "failed to create user ADsPath in order to check group membership for group: %ls domain: %ls", pwzName, pwzDomain);
178
179 hr = UserCreateADsPath(pwzGroupDomain, pwzGroupName, &bstrGroup);
165 - ExitOnFailure(hr, "failed to create group ADsPath in order to check group membership for group: %ls domain: %ls", pwzGroupName, pwzGroupDomain);
180 + UserExitOnFailure(hr, "failed to create group ADsPath in order to check group membership for group: %ls domain: %ls", pwzGroupName, pwzGroupDomain);
181
182 if (lstrlenW(pwzGroupDomain) > 0)
183 {
184 hr = ::ADsGetObject(bstrGroup, IID_IADsGroup, reinterpret_cast<void**>(&pGroup));
170 - ExitOnFailure(hr, "Failed to get group '%ls' from active directory.", reinterpret_cast<WCHAR*>(bstrGroup) );
185 + UserExitOnFailure(hr, "Failed to get group '%ls' from active directory.", reinterpret_cast<WCHAR*>(bstrGroup) );
186
187 hr = pGroup->IsMember(bstrUser, &vtBoolResult);
173 - ExitOnFailure(hr, "Failed to check if user %ls is a member of group '%ls' using active directory.", reinterpret_cast<WCHAR*>(bstrUser), reinterpret_cast<WCHAR*>(bstrGroup) );
188 + UserExitOnFailure(hr, "Failed to check if user %ls is a member of group '%ls' using active directory.", reinterpret_cast<WCHAR*>(bstrUser), reinterpret_cast<WCHAR*>(bstrGroup) );
189 }
190
191 if (vtBoolResult)
@@ -180,10 +195,10 @@ extern "C" HRESULT DAPI UserCheckIsMember(
195 }
196
197 hr = ::ADsGetObject(bstrGroup, IID_IADsGroup, reinterpret_cast<void**>(&pGroup));
183 - ExitOnFailure(hr, "Failed to get group '%ls' from active directory.", reinterpret_cast<WCHAR*>(bstrGroup) );
198 + UserExitOnFailure(hr, "Failed to get group '%ls' from active directory.", reinterpret_cast<WCHAR*>(bstrGroup) );
199
200 hr = pGroup->IsMember(bstrUser, &vtBoolResult);
186 - ExitOnFailure(hr, "Failed to check if user %ls is a member of group '%ls' using active directory.", reinterpret_cast<WCHAR*>(bstrUser), reinterpret_cast<WCHAR*>(bstrGroup) );
201 + UserExitOnFailure(hr, "Failed to check if user %ls is a member of group '%ls' using active directory.", reinterpret_cast<WCHAR*>(bstrUser), reinterpret_cast<WCHAR*>(bstrGroup) );
202
203 if (vtBoolResult)
204 {
@@ -222,25 +237,25 @@ extern "C" HRESULT DAPI UserCreateADsPath(
237 LPWSTR pwzAdsPath = NULL;
238
239 hr = StrAllocString(&pwzAdsPath, L"WinNT://", 0);
225 - ExitOnFailure(hr, "failed to allocate AdsPath string");
240 + UserExitOnFailure(hr, "failed to allocate AdsPath string");
241
242 if (*wzObjectDomain)
243 {
244 hr = StrAllocFormatted(&pwzAdsPath, L"%s/%s", wzObjectDomain, wzObjectName);
230 - ExitOnFailure(hr, "failed to allocate AdsPath string");
245 + UserExitOnFailure(hr, "failed to allocate AdsPath string");
246 }
247 else if (NULL != wcsstr(wzObjectName, L"\\") || NULL != wcsstr(wzObjectName, L"/"))
248 {
249 hr = StrAllocConcat(&pwzAdsPath, wzObjectName, 0);
235 - ExitOnFailure(hr, "failed to concat objectname: %ls", wzObjectName);
250 + UserExitOnFailure(hr, "failed to concat objectname: %ls", wzObjectName);
251 }
252 else
253 {
254 hr = StrAllocConcat(&pwzAdsPath, L"Localhost/", 0);
240 - ExitOnFailure(hr, "failed to concat LocalHost/");
255 + UserExitOnFailure(hr, "failed to concat LocalHost/");
256
257 hr = StrAllocConcat(&pwzAdsPath, wzObjectName, 0);
243 - ExitOnFailure(hr, "failed to concat object name: %ls", wzObjectName);
258 + UserExitOnFailure(hr, "failed to concat object name: %ls", wzObjectName);
259 }
260
261 *pbstrAdsPath = ::SysAllocString(pwzAdsPath);
src/dutil/wiutil.cpp
+68 -53
@@ -3,6 +3,21 @@
3 #include "precomp.h"
4
5
6 +// Exit macros
7 +#define WiuExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_WIUTIL, x, s, __VA_ARGS__)
8 +#define WiuExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_WIUTIL, x, s, __VA_ARGS__)
9 +#define WiuExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_WIUTIL, x, s, __VA_ARGS__)
10 +#define WiuExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_WIUTIL, x, s, __VA_ARGS__)
11 +#define WiuExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_WIUTIL, x, s, __VA_ARGS__)
12 +#define WiuExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_WIUTIL, x, s, __VA_ARGS__)
13 +#define WiuExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_WIUTIL, p, x, e, s, __VA_ARGS__)
14 +#define WiuExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_WIUTIL, p, x, s, __VA_ARGS__)
15 +#define WiuExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_WIUTIL, p, x, e, s, __VA_ARGS__)
16 +#define WiuExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_WIUTIL, p, x, s, __VA_ARGS__)
17 +#define WiuExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_WIUTIL, e, x, s, __VA_ARGS__)
18 +#define WiuExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_WIUTIL, g, x, s, __VA_ARGS__)
19 +
20 +
21 // constants
22
23 const DWORD WIU_MSI_PROGRESS_INVALID = 0xFFFFFFFF;
@@ -112,8 +127,8 @@ static DWORD CalculatePhaseProgress(
127 __in DWORD dwWeightPercentage
128 );
129 void InitializeMessageData(
115 - __in MSIHANDLE hRecord,
116 - __out LPWSTR** prgsczData,
130 + __in_opt MSIHANDLE hRecord,
131 + __deref_out_ecount(*pcData) LPWSTR** prgsczData,
132 __out DWORD* pcData
133 );
134 void UninitializeMessageData(
@@ -133,7 +148,7 @@ extern "C" HRESULT DAPI WiuInitialize(
148 LPWSTR sczMsiDllPath = NULL;
149
150 hr = LoadSystemLibraryWithPath(L"Msi.dll", &vhMsiDll, &sczMsiDllPath);
136 - ExitOnFailure(hr, "Failed to load Msi.DLL");
151 + WiuExitOnFailure(hr, "Failed to load Msi.DLL");
152
153 // Ignore failures
154 FileVersion(sczMsiDllPath, &vdwMsiDllMajorMinor, &vdwMsiDllBuildRevision);
@@ -275,7 +290,7 @@ extern "C" HRESULT DAPI WiuGetComponentPath(
290 DWORD cchCompare;
291
292 hr = StrAlloc(psczValue, cch);
278 - ExitOnFailure(hr, "Failed to allocate string for component path.");
293 + WiuExitOnFailure(hr, "Failed to allocate string for component path.");
294
295 cchCompare = cch;
296 *pInstallState = vpfnMsiGetComponentPathW(wzProductCode, wzComponentId, *psczValue, &cch);
@@ -283,7 +298,7 @@ extern "C" HRESULT DAPI WiuGetComponentPath(
298 {
299 ++cch;
300 hr = StrAlloc(psczValue, cch);
286 - ExitOnFailure(hr, "Failed to reallocate string for component path.");
301 + WiuExitOnFailure(hr, "Failed to reallocate string for component path.");
302
303 cchCompare = cch;
304 *pInstallState = vpfnMsiGetComponentPathW(wzProductCode, wzComponentId, *psczValue, &cch);
@@ -292,7 +307,7 @@ extern "C" HRESULT DAPI WiuGetComponentPath(
307 if (INSTALLSTATE_INVALIDARG == *pInstallState)
308 {
309 hr = E_INVALIDARG;
295 - ExitOnRootFailure(hr, "Invalid argument when getting component path.");
310 + WiuExitOnRootFailure(hr, "Invalid argument when getting component path.");
311 }
312 else if (INSTALLSTATE_UNKNOWN == *pInstallState)
313 {
@@ -306,7 +321,7 @@ extern "C" HRESULT DAPI WiuGetComponentPath(
321 {
322 ++cch;
323 hr = StrAlloc(psczValue, cch);
309 - ExitOnFailure(hr, "Failed to reallocate string for component path.");
324 + WiuExitOnFailure(hr, "Failed to reallocate string for component path.");
325
326 *pInstallState = vpfnMsiGetComponentPathW(wzProductCode, wzComponentId, *psczValue, &cch);
327 }
@@ -327,7 +342,7 @@ extern "C" HRESULT DAPI WiuLocateComponent(
342 DWORD cchCompare;
343
344 hr = StrAlloc(psczValue, cch);
330 - ExitOnFailure(hr, "Failed to allocate string for component path.");
345 + WiuExitOnFailure(hr, "Failed to allocate string for component path.");
346
347 cchCompare = cch;
348 *pInstallState = vpfnMsiLocateComponentW(wzComponentId, *psczValue, &cch);
@@ -335,7 +350,7 @@ extern "C" HRESULT DAPI WiuLocateComponent(
350 {
351 ++cch;
352 hr = StrAlloc(psczValue, cch);
338 - ExitOnFailure(hr, "Failed to reallocate string for component path.");
353 + WiuExitOnFailure(hr, "Failed to reallocate string for component path.");
354
355 cchCompare = cch;
356 *pInstallState = vpfnMsiLocateComponentW(wzComponentId, *psczValue, &cch);
@@ -344,7 +359,7 @@ extern "C" HRESULT DAPI WiuLocateComponent(
359 if (INSTALLSTATE_INVALIDARG == *pInstallState)
360 {
361 hr = E_INVALIDARG;
347 - ExitOnRootFailure(hr, "Invalid argument when locating component.");
362 + WiuExitOnRootFailure(hr, "Invalid argument when locating component.");
363 }
364 else if (INSTALLSTATE_UNKNOWN == *pInstallState)
365 {
@@ -358,7 +373,7 @@ extern "C" HRESULT DAPI WiuLocateComponent(
373 {
374 ++cch;
375 hr = StrAlloc(psczValue, cch);
361 - ExitOnFailure(hr, "Failed to reallocate string for component path.");
376 + WiuExitOnFailure(hr, "Failed to reallocate string for component path.");
377
378 *pInstallState = vpfnMsiLocateComponentW(wzComponentId, *psczValue, &cch);
379 }
@@ -380,7 +395,7 @@ extern "C" HRESULT DAPI WiuQueryFeatureState(
395 if (INSTALLSTATE_INVALIDARG == *pInstallState)
396 {
397 hr = E_INVALIDARG;
383 - ExitOnRootFailure(hr, "Failed to query state of feature: %ls in product: %ls", wzFeature, wzProduct);
398 + WiuExitOnRootFailure(hr, "Failed to query state of feature: %ls in product: %ls", wzFeature, wzProduct);
399 }
400
401 LExit:
@@ -399,18 +414,18 @@ extern "C" HRESULT DAPI WiuGetProductInfo(
414 DWORD cch = WIU_GOOD_ENOUGH_PROPERTY_LENGTH;
415
416 hr = StrAlloc(psczValue, cch);
402 - ExitOnFailure(hr, "Failed to allocate string for product info.");
417 + WiuExitOnFailure(hr, "Failed to allocate string for product info.");
418
419 er = vpfnMsiGetProductInfoW(wzProductCode, wzProperty, *psczValue, &cch);
420 if (ERROR_MORE_DATA == er)
421 {
422 ++cch;
423 hr = StrAlloc(psczValue, cch);
409 - ExitOnFailure(hr, "Failed to reallocate string for product info.");
424 + WiuExitOnFailure(hr, "Failed to reallocate string for product info.");
425
426 er = vpfnMsiGetProductInfoW(wzProductCode, wzProperty, *psczValue, &cch);
427 }
413 - ExitOnWin32Error(er, hr, "Failed to get product info.");
428 + WiuExitOnWin32Error(er, hr, "Failed to get product info.");
429
430 LExit:
431 return hr;
@@ -432,24 +447,24 @@ extern "C" HRESULT DAPI WiuGetProductInfoEx(
447 if (!vpfnMsiGetProductInfoExW)
448 {
449 hr = WiuGetProductInfo(wzProductCode, wzProperty, psczValue);
435 - ExitOnFailure(hr, "Failed to get product info when extended info was not available.");
450 + WiuExitOnFailure(hr, "Failed to get product info when extended info was not available.");
451
452 ExitFunction();
453 }
454
455 hr = StrAlloc(psczValue, cch);
441 - ExitOnFailure(hr, "Failed to allocate string for extended product info.");
456 + WiuExitOnFailure(hr, "Failed to allocate string for extended product info.");
457
458 er = vpfnMsiGetProductInfoExW(wzProductCode, wzUserSid, dwContext, wzProperty, *psczValue, &cch);
459 if (ERROR_MORE_DATA == er)
460 {
461 ++cch;
462 hr = StrAlloc(psczValue, cch);
448 - ExitOnFailure(hr, "Failed to reallocate string for extended product info.");
463 + WiuExitOnFailure(hr, "Failed to reallocate string for extended product info.");
464
465 er = vpfnMsiGetProductInfoExW(wzProductCode, wzUserSid, dwContext, wzProperty, *psczValue, &cch);
466 }
452 - ExitOnWin32Error(er, hr, "Failed to get extended product info.");
467 + WiuExitOnWin32Error(er, hr, "Failed to get extended product info.");
468
469 LExit:
470 return hr;
@@ -467,18 +482,18 @@ extern "C" HRESULT DAPI WiuGetProductProperty(
482 DWORD cch = WIU_GOOD_ENOUGH_PROPERTY_LENGTH;
483
484 hr = StrAlloc(psczValue, cch);
470 - ExitOnFailure(hr, "Failed to allocate string for product property.");
485 + WiuExitOnFailure(hr, "Failed to allocate string for product property.");
486
487 er = ::MsiGetProductPropertyW(hProduct, wzProperty, *psczValue, &cch);
488 if (ERROR_MORE_DATA == er)
489 {
490 ++cch;
491 hr = StrAlloc(psczValue, cch);
477 - ExitOnFailure(hr, "Failed to reallocate string for product property.");
492 + WiuExitOnFailure(hr, "Failed to reallocate string for product property.");
493
494 er = ::MsiGetProductPropertyW(hProduct, wzProperty, *psczValue, &cch);
495 }
481 - ExitOnWin32Error(er, hr, "Failed to get product property.");
496 + WiuExitOnWin32Error(er, hr, "Failed to get product property.");
497
498 LExit:
499 return hr;
@@ -504,18 +519,18 @@ extern "C" HRESULT DAPI WiuGetPatchInfoEx(
519 }
520
521 hr = StrAlloc(psczValue, cch);
507 - ExitOnFailure(hr, "Failed to allocate string for extended patch info.");
522 + WiuExitOnFailure(hr, "Failed to allocate string for extended patch info.");
523
524 er = vpfnMsiGetPatchInfoExW(wzPatchCode, wzProductCode, wzUserSid, dwContext, wzProperty, *psczValue, &cch);
525 if (ERROR_MORE_DATA == er)
526 {
527 ++cch;
528 hr = StrAlloc(psczValue, cch);
514 - ExitOnFailure(hr, "Failed to reallocate string for extended patch info.");
529 + WiuExitOnFailure(hr, "Failed to reallocate string for extended patch info.");
530
531 er = vpfnMsiGetPatchInfoExW(wzPatchCode, wzProductCode, wzUserSid, dwContext, wzProperty, *psczValue, &cch);
532 }
518 - ExitOnWin32Error(er, hr, "Failed to get extended patch info.");
533 + WiuExitOnWin32Error(er, hr, "Failed to get extended patch info.");
534
535 LExit:
536 return hr;
@@ -539,7 +554,7 @@ extern "C" HRESULT DAPI WiuDeterminePatchSequence(
554 }
555
556 er = vpfnMsiDeterminePatchSequenceW(wzProductCode, wzUserSid, context, cPatchInfo, pPatchInfo);
542 - ExitOnWin32Error(er, hr, "Failed to determine patch sequence for product code.");
557 + WiuExitOnWin32Error(er, hr, "Failed to determine patch sequence for product code.");
558
559 LExit:
560 return hr;
@@ -561,7 +576,7 @@ extern "C" HRESULT DAPI WiuDetermineApplicablePatches(
576 }
577
578 er = vpfnMsiDetermineApplicablePatchesW(wzProductPackagePath, cPatchInfo, pPatchInfo);
564 - ExitOnWin32Error(er, hr, "Failed to determine applicable patches for product package.");
579 + WiuExitOnWin32Error(er, hr, "Failed to determine applicable patches for product package.");
580
581 LExit:
582 return hr;
@@ -581,7 +596,7 @@ extern "C" HRESULT DAPI WiuEnumProducts(
596 {
597 ExitFunction1(hr = HRESULT_FROM_WIN32(er));
598 }
584 - ExitOnWin32Error(er, hr, "Failed to enumerate products.");
599 + WiuExitOnWin32Error(er, hr, "Failed to enumerate products.");
600
601 LExit:
602 return hr;
@@ -612,7 +627,7 @@ extern "C" HRESULT DAPI WiuEnumProductsEx(
627 {
628 ExitFunction1(hr = HRESULT_FROM_WIN32(er));
629 }
615 - ExitOnWin32Error(er, hr, "Failed to enumerate products.");
630 + WiuExitOnWin32Error(er, hr, "Failed to enumerate products.");
631
632 LExit:
633 return hr;
@@ -633,7 +648,7 @@ extern "C" HRESULT DAPI WiuEnumRelatedProducts(
648 {
649 ExitFunction1(hr = HRESULT_FROM_WIN32(er));
650 }
636 - ExitOnWin32Error(er, hr, "Failed to enumerate related products for updgrade code: %ls", wzUpgradeCode);
651 + WiuExitOnWin32Error(er, hr, "Failed to enumerate related products for updgrade code: %ls", wzUpgradeCode);
652
653 LExit:
654 return hr;
@@ -650,7 +665,7 @@ LExit:
665 ********************************************************************/
666 extern "C" HRESULT DAPI WiuEnumRelatedProductCodes(
667 __in_z LPCWSTR wzUpgradeCode,
653 - __deref_out_ecount_opt(pcRelatedProducts) LPWSTR** prgsczProductCodes,
668 + __deref_out_ecount_opt(*pcRelatedProducts) LPWSTR** prgsczProductCodes,
669 __out DWORD* pcRelatedProducts,
670 __in BOOL fReturnHighestVersionOnly
671 )
@@ -673,16 +688,16 @@ extern "C" HRESULT DAPI WiuEnumRelatedProductCodes(
688 hr = S_OK;
689 break;
690 }
676 - ExitOnFailure(hr, "Failed to enumerate related products for upgrade code: %ls", wzUpgradeCode);
691 + WiuExitOnFailure(hr, "Failed to enumerate related products for upgrade code: %ls", wzUpgradeCode);
692
693 if (fReturnHighestVersionOnly)
694 {
695 // get the version
696 hr = WiuGetProductInfo(wzCurrentProductCode, L"VersionString", &sczInstalledVersion);
682 - ExitOnFailure(hr, "Failed to get version for product code: %ls", wzCurrentProductCode);
697 + WiuExitOnFailure(hr, "Failed to get version for product code: %ls", wzCurrentProductCode);
698
699 hr = FileVersionFromStringEx(sczInstalledVersion, 0, &qwCurrentVersion);
685 - ExitOnFailure(hr, "Failed to convert version: %ls to DWORD64 for product code: %ls", sczInstalledVersion, wzCurrentProductCode);
700 + WiuExitOnFailure(hr, "Failed to convert version: %ls to DWORD64 for product code: %ls", sczInstalledVersion, wzCurrentProductCode);
701
702 // if this is the first product found then it is the highest version (for now)
703 if (0 == *pcRelatedProducts)
@@ -698,7 +713,7 @@ extern "C" HRESULT DAPI WiuEnumRelatedProductCodes(
713 qwHighestVersion = qwCurrentVersion;
714
715 hr = StrAllocString(prgsczProductCodes[0], wzCurrentProductCode, 0);
701 - ExitOnFailure(hr, "Failed to update array with higher versioned product code.");
716 + WiuExitOnFailure(hr, "Failed to update array with higher versioned product code.");
717 }
718
719 // continue here as we don't want anything else added to the list
@@ -707,7 +722,7 @@ extern "C" HRESULT DAPI WiuEnumRelatedProductCodes(
722 }
723
724 hr = StrArrayAllocString(prgsczProductCodes, (LPUINT)(pcRelatedProducts), wzCurrentProductCode, 0);
710 - ExitOnFailure(hr, "Failed to add product code to array.");
725 + WiuExitOnFailure(hr, "Failed to add product code to array.");
726 }
727
728 LExit:
@@ -726,7 +741,7 @@ extern "C" HRESULT DAPI WiuEnableLog(
741 DWORD er = ERROR_SUCCESS;
742
743 er = vpfnMsiEnableLogW(dwLogMode, wzLogFile, dwLogAttributes);
729 - ExitOnWin32Error(er, hr, "Failed to enable MSI internal logging.");
744 + WiuExitOnWin32Error(er, hr, "Failed to enable MSI internal logging.");
745
746 LExit:
747 return hr;
@@ -780,7 +795,7 @@ extern "C" HRESULT DAPI WiuInitializeExternalUI(
795
796 // Wire the internal and external UI handler.
797 hr = WiuInitializeInternalUI(internalUILevel, hwndParent, pExecuteContext);
783 - ExitOnFailure(hr, "Failed to set internal UI level and window.");
798 + WiuExitOnFailure(hr, "Failed to set internal UI level and window.");
799
800 pExecuteContext->fRollback = fRollback;
801 pExecuteContext->pfnMessageHandler = pfnMessageHandler;
@@ -791,7 +806,7 @@ extern "C" HRESULT DAPI WiuInitializeExternalUI(
806 if (vpfnMsiSetExternalUIRecord)
807 {
808 er = vpfnMsiSetExternalUIRecord(InstallEngineRecordCallback, dwMessageFilter, pExecuteContext, &pExecuteContext->pfnPreviousExternalUIRecord);
794 - ExitOnWin32Error(er, hr, "Failed to wire up external UI record handler.");
809 + WiuExitOnWin32Error(er, hr, "Failed to wire up external UI record handler.");
810 pExecuteContext->fSetPreviousExternalUIRecord = TRUE;
811 }
812 else
@@ -841,7 +856,7 @@ extern "C" HRESULT DAPI WiuConfigureProductEx(
856
857 er = vpfnMsiConfigureProductExW(wzProduct, iInstallLevel, eInstallState, wzCommandLine);
858 er = CheckForRestartErrorCode(er, pRestart);
844 - ExitOnWin32Error(er, hr, "Failed to configure product: %ls", wzProduct);
859 + WiuExitOnWin32Error(er, hr, "Failed to configure product: %ls", wzProduct);
860
861 LExit:
862 return hr;
@@ -859,7 +874,7 @@ extern "C" HRESULT DAPI WiuInstallProduct(
874
875 er = vpfnMsiInstallProductW(wzPackagePath, wzCommandLine);
876 er = CheckForRestartErrorCode(er, pRestart);
862 - ExitOnWin32Error(er, hr, "Failed to install product: %ls", wzPackagePath);
877 + WiuExitOnWin32Error(er, hr, "Failed to install product: %ls", wzPackagePath);
878
879 LExit:
880 return hr;
@@ -878,7 +893,7 @@ extern "C" HRESULT DAPI WiuRemovePatches(
893
894 er = vpfnMsiRemovePatchesW(wzPatchList, wzProductCode, INSTALLTYPE_SINGLE_INSTANCE, wzPropertyList);
895 er = CheckForRestartErrorCode(er, pRestart);
881 - ExitOnWin32Error(er, hr, "Failed to remove patches.");
896 + WiuExitOnWin32Error(er, hr, "Failed to remove patches.");
897
898 LExit:
899 return hr;
@@ -898,7 +913,7 @@ extern "C" HRESULT DAPI WiuSourceListAddSourceEx(
913 DWORD er = ERROR_SUCCESS;
914
915 er = vpfnMsiSourceListAddSourceExW(wzProductCodeOrPatchCode, wzUserSid, dwContext, MSISOURCETYPE_NETWORK | dwCode, wzSource, dwIndex);
901 - ExitOnWin32Error(er, hr, "Failed to add source.");
916 + WiuExitOnWin32Error(er, hr, "Failed to add source.");
917
918 LExit:
919 return hr;
@@ -924,14 +939,14 @@ extern "C" HRESULT DAPI WiuBeginTransaction(
939
940 if (!WiuIsMsiTransactionSupported())
941 {
927 - ExitOnFailure(hr = E_NOTIMPL, "Msi transactions are not supported");
942 + WiuExitOnFailure(hr = E_NOTIMPL, "Msi transactions are not supported");
943 }
944
945 hr = WiuEnableLog(dwLogMode, szLogPath, INSTALLLOGATTRIBUTES_APPEND);
931 - ExitOnFailure(hr, "Failed to enable logging for MSI transaction");
946 + WiuExitOnFailure(hr, "Failed to enable logging for MSI transaction");
947
948 er = vpfnMsiBeginTransaction(szName, dwTransactionAttributes, phTransactionHandle, phChangeOfOwnerEvent);
934 - ExitOnWin32Error(er, hr, "Failed to begin transaction.");
949 + WiuExitOnWin32Error(er, hr, "Failed to begin transaction.");
950
951 LExit:
952 return hr;
@@ -948,14 +963,14 @@ extern "C" HRESULT DAPI WiuEndTransaction(
963
964 if (!WiuIsMsiTransactionSupported())
965 {
951 - ExitOnFailure(hr = E_NOTIMPL, "Msi transactions are not supported");
966 + WiuExitOnFailure(hr = E_NOTIMPL, "Msi transactions are not supported");
967 }
968
969 hr = WiuEnableLog(dwLogMode, szLogPath, INSTALLLOGATTRIBUTES_APPEND);
955 - ExitOnFailure(hr, "Failed to enable logging for MSI transaction");
970 + WiuExitOnFailure(hr, "Failed to enable logging for MSI transaction");
971
972 er = vpfnMsiEndTransaction(dwTransactionState);
958 - ExitOnWin32Error(er, hr, "Failed to end transaction.");
973 + WiuExitOnWin32Error(er, hr, "Failed to end transaction.");
974
975 LExit:
976 return hr;
@@ -1048,10 +1063,10 @@ static INT CALLBACK InstallEngineRecordCallback(
1063 {
1064 hr = HRESULT_FROM_WIN32(er);
1065 }
1051 - ExitOnFailure(hr, "Failed to allocate string for formated message.");
1066 + WiuExitOnFailure(hr, "Failed to allocate string for formated message.");
1067
1068 er = ::MsiFormatRecordW(NULL, hRecord, sczMessage, &cchMessage);
1054 - ExitOnWin32Error(er, hr, "Failed to format message record.");
1069 + WiuExitOnWin32Error(er, hr, "Failed to format message record.");
1070
1071 // Pass to handler including both the formated message and the original record.
1072 nResult = HandleInstallMessage(pContext, mt, uiFlags, sczMessage, hRecord);
@@ -1213,7 +1228,7 @@ static INT HandleInstallProgress(
1228
1229 // parse number
1230 hr = StrStringToInt32(pwz, cch, &iFields[cFields]);
1216 - ExitOnFailure(hr, "Failed to parse MSI message part.");
1231 + WiuExitOnFailure(hr, "Failed to parse MSI message part.");
1232
1233 // increment field count
1234 ++cFields;
@@ -1255,7 +1270,7 @@ static INT HandleInstallProgress(
1270 else
1271 {
1272 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
1258 - ExitOnRootFailure(hr, "Insufficient space to hold progress information.");
1273 + WiuExitOnRootFailure(hr, "Insufficient space to hold progress information.");
1274 }
1275
1276 // we only care about the first stage after script execution has started
src/dutil/wuautil.cpp
+23 -8
@@ -3,6 +3,21 @@
3 #include "precomp.h"
4
5
6 +// Exit macros
7 +#define WuaExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_WUAUTIL, x, s, __VA_ARGS__)
8 +#define WuaExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_WUAUTIL, x, s, __VA_ARGS__)
9 +#define WuaExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_WUAUTIL, x, s, __VA_ARGS__)
10 +#define WuaExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_WUAUTIL, x, s, __VA_ARGS__)
11 +#define WuaExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_WUAUTIL, x, s, __VA_ARGS__)
12 +#define WuaExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_WUAUTIL, x, s, __VA_ARGS__)
13 +#define WuaExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_WUAUTIL, p, x, e, s, __VA_ARGS__)
14 +#define WuaExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_WUAUTIL, p, x, s, __VA_ARGS__)
15 +#define WuaExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_WUAUTIL, p, x, e, s, __VA_ARGS__)
16 +#define WuaExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_WUAUTIL, p, x, s, __VA_ARGS__)
17 +#define WuaExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_WUAUTIL, e, x, s, __VA_ARGS__)
18 +#define WuaExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_WUAUTIL, g, x, s, __VA_ARGS__)
19 +
20 +
21 // internal function declarations
22
23 static HRESULT GetAutomaticUpdatesService(
@@ -18,10 +33,10 @@ extern "C" HRESULT DAPI WuaPauseAutomaticUpdates()
33 IAutomaticUpdates *pAutomaticUpdates = NULL;
34
35 hr = GetAutomaticUpdatesService(&pAutomaticUpdates);
21 - ExitOnFailure(hr, "Failed to get the Automatic Updates service.");
36 + WuaExitOnFailure(hr, "Failed to get the Automatic Updates service.");
37
38 hr = pAutomaticUpdates->Pause();
24 - ExitOnFailure(hr, "Failed to pause the Automatic Updates service.");
39 + WuaExitOnFailure(hr, "Failed to pause the Automatic Updates service.");
40
41 LExit:
42 ReleaseObject(pAutomaticUpdates);
@@ -35,10 +50,10 @@ extern "C" HRESULT DAPI WuaResumeAutomaticUpdates()
50 IAutomaticUpdates *pAutomaticUpdates = NULL;
51
52 hr = GetAutomaticUpdatesService(&pAutomaticUpdates);
38 - ExitOnFailure(hr, "Failed to get the Automatic Updates service.");
53 + WuaExitOnFailure(hr, "Failed to get the Automatic Updates service.");
54
55 hr = pAutomaticUpdates->Resume();
41 - ExitOnFailure(hr, "Failed to resume the Automatic Updates service.");
56 + WuaExitOnFailure(hr, "Failed to resume the Automatic Updates service.");
57
58 LExit:
59 ReleaseObject(pAutomaticUpdates);
@@ -55,10 +70,10 @@ extern "C" HRESULT DAPI WuaRestartRequired(
70 VARIANT_BOOL bRestartRequired;
71
72 hr = ::CoCreateInstance(__uuidof(SystemInformation), NULL, CLSCTX_INPROC_SERVER, __uuidof(ISystemInformation), reinterpret_cast<LPVOID*>(&pSystemInformation));
58 - ExitOnRootFailure(hr, "Failed to get WUA system information interface.");
73 + WuaExitOnRootFailure(hr, "Failed to get WUA system information interface.");
74
75 hr = pSystemInformation->get_RebootRequired(&bRestartRequired);
61 - ExitOnRootFailure(hr, "Failed to determine if restart is required from WUA.");
76 + WuaExitOnRootFailure(hr, "Failed to determine if restart is required from WUA.");
77
78 *pfRestartRequired = (VARIANT_FALSE != bRestartRequired);
79
@@ -79,10 +94,10 @@ static HRESULT GetAutomaticUpdatesService(
94 CLSID clsidAutomaticUpdates = { };
95
96 hr = ::CLSIDFromProgID(L"Microsoft.Update.AutoUpdate", &clsidAutomaticUpdates);
82 - ExitOnFailure(hr, "Failed to get CLSID for Microsoft.Update.AutoUpdate.");
97 + WuaExitOnFailure(hr, "Failed to get CLSID for Microsoft.Update.AutoUpdate.");
98
99 hr = ::CoCreateInstance(clsidAutomaticUpdates, NULL, CLSCTX_INPROC_SERVER, IID_IAutomaticUpdates, reinterpret_cast<LPVOID*>(ppAutomaticUpdates));
85 - ExitOnFailure(hr, "Failed to create instance of Microsoft.Update.AutoUpdate.");
100 + WuaExitOnFailure(hr, "Failed to create instance of Microsoft.Update.AutoUpdate.");
101
102 LExit:
103 return hr;
src/dutil/xmlutil.cpp
+104 -89
@@ -2,6 +2,21 @@
2
3 #include "precomp.h"
4
5 +
6 +// Exit macros
7 +#define XmlExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_XMLUTIL, x, s, __VA_ARGS__)
8 +#define XmlExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_XMLUTIL, x, s, __VA_ARGS__)
9 +#define XmlExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_XMLUTIL, x, s, __VA_ARGS__)
10 +#define XmlExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_XMLUTIL, x, s, __VA_ARGS__)
11 +#define XmlExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_XMLUTIL, x, s, __VA_ARGS__)
12 +#define XmlExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_XMLUTIL, x, s, __VA_ARGS__)
13 +#define XmlExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_XMLUTIL, p, x, e, s, __VA_ARGS__)
14 +#define XmlExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_XMLUTIL, p, x, s, __VA_ARGS__)
15 +#define XmlExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_XMLUTIL, p, x, e, s, __VA_ARGS__)
16 +#define XmlExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_XMLUTIL, p, x, s, __VA_ARGS__)
17 +#define XmlExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_XMLUTIL, e, x, s, __VA_ARGS__)
18 +#define XmlExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_XMLUTIL, g, x, s, __VA_ARGS__)
19 +
20 // intialization globals
21 CLSID vclsidXMLDOM = { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0} };
22 static volatile LONG vcXmlInitialized = 0;
@@ -23,7 +38,7 @@ extern "C" HRESULT DAPI XmlInitialize(
38 hr = ::CoInitialize(0);
39 if (RPC_E_CHANGED_MODE != hr)
40 {
26 - ExitOnFailure(hr, "failed to initialize COM");
41 + XmlExitOnFailure(hr, "failed to initialize COM");
42 fComInitialized = TRUE;
43 }
44 }
@@ -47,7 +62,7 @@ extern "C" HRESULT DAPI XmlInitialize(
62 // try to fall back to old MSXML
63 hr = ::CLSIDFromProgID(L"MSXML.DOMDocument", &vclsidXMLDOM);
64 }
50 - ExitOnFailure(hr, "failed to get CLSID for XML DOM");
65 + XmlExitOnFailure(hr, "failed to get CLSID for XML DOM");
66
67 Assert(IsEqualCLSID(vclsidXMLDOM, XmlUtil_CLSID_DOMDocument) ||
68 IsEqualCLSID(vclsidXMLDOM, XmlUtil_CLSID_DOMDocument20) ||
@@ -99,7 +114,7 @@ extern "C" HRESULT DAPI XmlCreateElement(
114
115 HRESULT hr = S_OK;
116 BSTR bstrElementName = ::SysAllocString(wzElementName);
102 - ExitOnNull(bstrElementName, hr, E_OUTOFMEMORY, "failed SysAllocString");
117 + XmlExitOnNull(bstrElementName, hr, E_OUTOFMEMORY, "failed SysAllocString");
118 hr = pixdDocument->createElement(bstrElementName, ppixnElement);
119 LExit:
120 ReleaseBSTR(bstrElementName);
@@ -130,7 +145,7 @@ extern "C" HRESULT DAPI XmlCreateDocument(
145
146 // Test if we have access to the Wow64 API, and store the result in fWow64Available
147 HMODULE hKernel32 = ::GetModuleHandleA("kernel32.dll");
133 - ExitOnNullWithLastError(hKernel32, hr, "failed to get handle to kernel32.dll");
148 + XmlExitOnNullWithLastError(hKernel32, hr, "failed to get handle to kernel32.dll");
149
150 // This will test if we have access to the Wow64 API
151 if (NULL != GetProcAddress(hKernel32, "IsWow64Process"))
@@ -155,7 +170,7 @@ extern "C" HRESULT DAPI XmlCreateDocument(
170 }
171
172 hr = ::CoCreateInstance(vclsidXMLDOM, NULL, CLSCTX_INPROC_SERVER, XmlUtil_IID_IXMLDOMDocument, (void**)&pixdDocument);
158 - ExitOnFailure(hr, "failed to create XML DOM Document");
173 + XmlExitOnFailure(hr, "failed to create XML DOM Document");
174 Assert(pixdDocument);
175
176 if (IsEqualCLSID(vclsidXMLDOM, XmlUtil_CLSID_DOMDocument30) || IsEqualCLSID(vclsidXMLDOM, XmlUtil_CLSID_DOMDocument20))
@@ -166,9 +181,9 @@ extern "C" HRESULT DAPI XmlCreateDocument(
181 if (pwzElementName)
182 {
183 hr = XmlCreateElement(pixdDocument, pwzElementName, &pixeRootElement);
169 - ExitOnFailure(hr, "failed XmlCreateElement");
184 + XmlExitOnFailure(hr, "failed XmlCreateElement");
185 hr = pixdDocument->appendChild(pixeRootElement, NULL);
171 - ExitOnFailure(hr, "failed appendChild");
186 + XmlExitOnFailure(hr, "failed appendChild");
187 }
188
189 *ppixdDocument = pixdDocument;
@@ -222,28 +237,28 @@ static void XmlReportParseError(
237 Trace(REPORT_STANDARD, "Failed to parse XML. IXMLDOMParseError reports:");
238
239 hr = pixpe->get_errorCode(&lNumber);
225 - ExitOnFailure(hr, "Failed to query IXMLDOMParseError.errorCode.");
240 + XmlExitOnFailure(hr, "Failed to query IXMLDOMParseError.errorCode.");
241 Trace(REPORT_STANDARD, "errorCode = 0x%x", lNumber);
242
243 hr = pixpe->get_filepos(&lNumber);
229 - ExitOnFailure(hr, "Failed to query IXMLDOMParseError.filepos.");
244 + XmlExitOnFailure(hr, "Failed to query IXMLDOMParseError.filepos.");
245 Trace(REPORT_STANDARD, "filepos = %d", lNumber);
246
247 hr = pixpe->get_line(&lNumber);
233 - ExitOnFailure(hr, "Failed to query IXMLDOMParseError.line.");
248 + XmlExitOnFailure(hr, "Failed to query IXMLDOMParseError.line.");
249 Trace(REPORT_STANDARD, "line = %d", lNumber);
250
251 hr = pixpe->get_linepos(&lNumber);
237 - ExitOnFailure(hr, "Failed to query IXMLDOMParseError.linepos.");
252 + XmlExitOnFailure(hr, "Failed to query IXMLDOMParseError.linepos.");
253 Trace(REPORT_STANDARD, "linepos = %d", lNumber);
254
255 hr = pixpe->get_reason(&bstr);
241 - ExitOnFailure(hr, "Failed to query IXMLDOMParseError.reason.");
256 + XmlExitOnFailure(hr, "Failed to query IXMLDOMParseError.reason.");
257 Trace(REPORT_STANDARD, "reason = %ls", bstr);
258 ReleaseNullBSTR(bstr);
259
260 hr = pixpe->get_srcText (&bstr);
246 - ExitOnFailure(hr, "Failed to query IXMLDOMParseError.srcText .");
261 + XmlExitOnFailure(hr, "Failed to query IXMLDOMParseError.srcText .");
262 Trace(REPORT_STANDARD, "srcText = %ls", bstr);
263 ReleaseNullBSTR(bstr);
264
@@ -272,7 +287,7 @@ extern "C" HRESULT DAPI XmlLoadDocumentEx(
287 if (!wzDocument || !*wzDocument)
288 {
289 hr = E_UNEXPECTED;
275 - ExitOnFailure(hr, "string must be non-null");
290 + XmlExitOnFailure(hr, "string must be non-null");
291 }
292
293 hr = XmlCreateDocument(NULL, &pixd);
@@ -280,22 +295,22 @@ extern "C" HRESULT DAPI XmlLoadDocumentEx(
295 {
296 hr = E_FAIL;
297 }
283 - ExitOnFailure(hr, "failed XmlCreateDocument");
298 + XmlExitOnFailure(hr, "failed XmlCreateDocument");
299
300 if (dwAttributes & XML_LOAD_PRESERVE_WHITESPACE)
301 {
302 hr = pixd->put_preserveWhiteSpace(VARIANT_TRUE);
288 - ExitOnFailure(hr, "failed put_preserveWhiteSpace");
303 + XmlExitOnFailure(hr, "failed put_preserveWhiteSpace");
304 }
305
306 // Security issue. Avoid triggering anything external.
307 hr = pixd->put_validateOnParse(VARIANT_FALSE);
293 - ExitOnFailure(hr, "failed put_validateOnParse");
308 + XmlExitOnFailure(hr, "failed put_validateOnParse");
309 hr = pixd->put_resolveExternals(VARIANT_FALSE);
295 - ExitOnFailure(hr, "failed put_resolveExternals");
310 + XmlExitOnFailure(hr, "failed put_resolveExternals");
311
312 bstrLoad = ::SysAllocString(wzDocument);
298 - ExitOnNull(bstrLoad, hr, E_OUTOFMEMORY, "failed to allocate bstr for Load in XmlLoadDocumentEx");
313 + XmlExitOnNull(bstrLoad, hr, E_OUTOFMEMORY, "failed to allocate bstr for Load in XmlLoadDocumentEx");
314
315 hr = pixd->loadXML(bstrLoad, &vbSuccess);
316 if (S_FALSE == hr)
@@ -308,7 +323,7 @@ extern "C" HRESULT DAPI XmlLoadDocumentEx(
323 XmlReportParseError(pixpe);
324 }
325
311 - ExitOnFailure(hr, "failed loadXML");
326 + XmlExitOnFailure(hr, "failed loadXML");
327
328
329 hr = S_OK;
@@ -359,26 +374,26 @@ extern "C" HRESULT DAPI XmlLoadDocumentFromFileEx(
374 ::VariantInit(&varPath);
375 varPath.vt = VT_BSTR;
376 varPath.bstrVal = ::SysAllocString(wzPath);
362 - ExitOnNull(varPath.bstrVal, hr, E_OUTOFMEMORY, "failed to allocate bstr for Path in XmlLoadDocumentFromFileEx");
377 + XmlExitOnNull(varPath.bstrVal, hr, E_OUTOFMEMORY, "failed to allocate bstr for Path in XmlLoadDocumentFromFileEx");
378
379 hr = XmlCreateDocument(NULL, &pixd);
380 if (hr == S_FALSE)
381 {
382 hr = E_FAIL;
383 }
369 - ExitOnFailure(hr, "failed XmlCreateDocument");
384 + XmlExitOnFailure(hr, "failed XmlCreateDocument");
385
386 if (dwAttributes & XML_LOAD_PRESERVE_WHITESPACE)
387 {
388 hr = pixd->put_preserveWhiteSpace(VARIANT_TRUE);
374 - ExitOnFailure(hr, "failed put_preserveWhiteSpace");
389 + XmlExitOnFailure(hr, "failed put_preserveWhiteSpace");
390 }
391
392 // Avoid triggering anything external.
393 hr = pixd->put_validateOnParse(VARIANT_FALSE);
379 - ExitOnFailure(hr, "failed put_validateOnParse");
394 + XmlExitOnFailure(hr, "failed put_validateOnParse");
395 hr = pixd->put_resolveExternals(VARIANT_FALSE);
381 - ExitOnFailure(hr, "failed put_resolveExternals");
396 + XmlExitOnFailure(hr, "failed put_resolveExternals");
397
398 pixd->put_async(VARIANT_FALSE);
399 hr = pixd->load(varPath, &vbSuccess);
@@ -392,7 +407,7 @@ extern "C" HRESULT DAPI XmlLoadDocumentFromFileEx(
407 XmlReportParseError(pixpe);
408 }
409
395 - ExitOnFailure(hr, "failed to load XML from: %ls", wzPath);
410 + XmlExitOnFailure(hr, "failed to load XML from: %ls", wzPath);
411
412 if (ppixdDocument)
413 {
@@ -434,13 +449,13 @@ extern "C" HRESULT DAPI XmlLoadDocumentFromBuffer(
449 {
450 hr = E_FAIL;
451 }
437 - ExitOnFailure(hr, "failed XmlCreateDocument");
452 + XmlExitOnFailure(hr, "failed XmlCreateDocument");
453
454 // Security issue. Avoid triggering anything external.
455 hr = pixdDocument->put_validateOnParse(VARIANT_FALSE);
441 - ExitOnFailure(hr, "failed put_validateOnParse");
456 + XmlExitOnFailure(hr, "failed put_validateOnParse");
457 hr = pixdDocument->put_resolveExternals(VARIANT_FALSE);
443 - ExitOnFailure(hr, "failed put_resolveExternals");
458 + XmlExitOnFailure(hr, "failed put_resolveExternals");
459
460 // load document
461 sa.cDims = 1;
@@ -456,7 +471,7 @@ extern "C" HRESULT DAPI XmlLoadDocumentFromBuffer(
471 {
472 hr = HRESULT_FROM_WIN32(ERROR_OPEN_FAILED);
473 }
459 - ExitOnFailure(hr, "failed loadXML");
474 + XmlExitOnFailure(hr, "failed loadXML");
475
476 // return value
477 *ppixdDocument = pixdDocument;
@@ -488,20 +503,20 @@ extern "C" HRESULT DAPI XmlSetAttribute(
503 IXMLDOMAttribute* pixaAttribute = NULL;
504 IXMLDOMNode* pixaNode = NULL;
505 BSTR bstrAttributeName = ::SysAllocString(pwzAttribute);
491 - ExitOnNull(bstrAttributeName, hr, E_OUTOFMEMORY, "failed to allocate bstr for AttributeName in XmlSetAttribute");
506 + XmlExitOnNull(bstrAttributeName, hr, E_OUTOFMEMORY, "failed to allocate bstr for AttributeName in XmlSetAttribute");
507
508 hr = pixnNode->get_attributes(&pixnnmAttributes);
494 - ExitOnFailure(hr, "failed get_attributes in XmlSetAttribute(%ls)", pwzAttribute);
509 + XmlExitOnFailure(hr, "failed get_attributes in XmlSetAttribute(%ls)", pwzAttribute);
510
511 hr = pixnNode->get_ownerDocument(&pixdDocument);
512 if (hr == S_FALSE)
513 {
514 hr = E_FAIL;
515 }
501 - ExitOnFailure(hr, "failed get_ownerDocument in XmlSetAttribute");
516 + XmlExitOnFailure(hr, "failed get_ownerDocument in XmlSetAttribute");
517
518 hr = pixdDocument->createAttribute(bstrAttributeName, &pixaAttribute);
504 - ExitOnFailure(hr, "failed createAttribute in XmlSetAttribute(%ls)", pwzAttribute);
519 + XmlExitOnFailure(hr, "failed createAttribute in XmlSetAttribute(%ls)", pwzAttribute);
520
521 varAttributeValue.vt = VT_BSTR;
522 varAttributeValue.bstrVal = ::SysAllocString(pwzAttributeValue);
@@ -509,13 +524,13 @@ extern "C" HRESULT DAPI XmlSetAttribute(
524 {
525 hr = HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY);
526 }
512 - ExitOnFailure(hr, "failed SysAllocString in XmlSetAttribute");
527 + XmlExitOnFailure(hr, "failed SysAllocString in XmlSetAttribute");
528
529 hr = pixaAttribute->put_nodeValue(varAttributeValue);
515 - ExitOnFailure(hr, "failed put_nodeValue in XmlSetAttribute(%ls)", pwzAttribute);
530 + XmlExitOnFailure(hr, "failed put_nodeValue in XmlSetAttribute(%ls)", pwzAttribute);
531
532 hr = pixnnmAttributes->setNamedItem(pixaAttribute, &pixaNode);
518 - ExitOnFailure(hr, "failed setNamedItem in XmlSetAttribute(%ls)", pwzAttribute);
533 + XmlExitOnFailure(hr, "failed setNamedItem in XmlSetAttribute(%ls)", pwzAttribute);
534
535 LExit:
536 ReleaseObject(pixdDocument);
@@ -543,11 +558,11 @@ extern "C" HRESULT DAPI XmlSelectSingleNode(
558
559 BSTR bstrXPath = NULL;
560
546 - ExitOnNull(pixnParent, hr, E_UNEXPECTED, "pixnParent parameter was null in XmlSelectSingleNode");
547 - ExitOnNull(ppixnChild, hr, E_UNEXPECTED, "ppixnChild parameter was null in XmlSelectSingleNode");
561 + XmlExitOnNull(pixnParent, hr, E_UNEXPECTED, "pixnParent parameter was null in XmlSelectSingleNode");
562 + XmlExitOnNull(ppixnChild, hr, E_UNEXPECTED, "ppixnChild parameter was null in XmlSelectSingleNode");
563
564 bstrXPath = ::SysAllocString(wzXPath ? wzXPath : L"");
550 - ExitOnNull(bstrXPath, hr, E_OUTOFMEMORY, "failed to allocate bstr for XPath expression in XmlSelectSingleNode");
565 + XmlExitOnNull(bstrXPath, hr, E_OUTOFMEMORY, "failed to allocate bstr for XPath expression in XmlSelectSingleNode");
566
567 hr = pixnParent->selectSingleNode(bstrXPath, ppixnChild);
568
@@ -575,7 +590,7 @@ extern "C" HRESULT DAPI XmlCreateTextNode(
590
591 HRESULT hr = S_OK;
592 BSTR bstrText = ::SysAllocString(wzText);
578 - ExitOnNull(bstrText, hr, E_OUTOFMEMORY, "failed SysAllocString");
593 + XmlExitOnNull(bstrText, hr, E_OUTOFMEMORY, "failed SysAllocString");
594 hr = pixdDocument->createTextNode(bstrText, ppixnTextNode);
595 LExit:
596 ReleaseBSTR(bstrText);
@@ -621,7 +636,7 @@ extern "C" HRESULT DAPI XmlGetAttribute(
636
637 // get attribute value from source
638 hr = pixnNode->get_attributes(&pixnnmAttributes);
624 - ExitOnFailure(hr, "failed get_attributes");
639 + XmlExitOnFailure(hr, "failed get_attributes");
640
641 hr = XmlGetNamedItem(pixnnmAttributes, bstrAttribute, &pixnAttribute);
642 if (S_FALSE == hr)
@@ -629,10 +644,10 @@ extern "C" HRESULT DAPI XmlGetAttribute(
644 // hr = E_FAIL;
645 ExitFunction();
646 }
632 - ExitOnFailure(hr, "failed getNamedItem in XmlGetAttribute(%ls)", pwzAttribute);
647 + XmlExitOnFailure(hr, "failed getNamedItem in XmlGetAttribute(%ls)", pwzAttribute);
648
649 hr = pixnAttribute->get_nodeValue(&varAttributeValue);
635 - ExitOnFailure(hr, "failed get_nodeValue in XmlGetAttribute(%ls)", pwzAttribute);
650 + XmlExitOnFailure(hr, "failed get_nodeValue in XmlGetAttribute(%ls)", pwzAttribute);
651
652 // steal the BSTR from the VARIANT
653 if (S_OK == hr && pbstrAttributeValue)
@@ -672,28 +687,28 @@ HRESULT DAPI XmlGetAttributeEx(
687
688 // get attribute value from source
689 hr = pixnNode->get_attributes(&pixnnmAttributes);
675 - ExitOnFailure(hr, "Failed get_attributes.");
690 + XmlExitOnFailure(hr, "Failed get_attributes.");
691
692 bstrAttribute = ::SysAllocString(wzAttribute);
678 - ExitOnNull(bstrAttribute, hr, E_OUTOFMEMORY, "Failed to allocate attribute name BSTR.");
693 + XmlExitOnNull(bstrAttribute, hr, E_OUTOFMEMORY, "Failed to allocate attribute name BSTR.");
694
695 hr = XmlGetNamedItem(pixnnmAttributes, bstrAttribute, &pixnAttribute);
696 if (S_FALSE == hr)
697 {
698 ExitFunction1(hr = E_NOTFOUND);
699 }
685 - ExitOnFailure(hr, "Failed getNamedItem in XmlGetAttribute(%ls)", wzAttribute);
700 + XmlExitOnFailure(hr, "Failed getNamedItem in XmlGetAttribute(%ls)", wzAttribute);
701
702 hr = pixnAttribute->get_nodeValue(&varAttributeValue);
703 if (S_FALSE == hr)
704 {
705 ExitFunction1(hr = E_NOTFOUND);
706 }
692 - ExitOnFailure(hr, "Failed get_nodeValue in XmlGetAttribute(%ls)", wzAttribute);
707 + XmlExitOnFailure(hr, "Failed get_nodeValue in XmlGetAttribute(%ls)", wzAttribute);
708
709 // copy value
710 hr = StrAllocString(psczAttributeValue, varAttributeValue.bstrVal, 0);
696 - ExitOnFailure(hr, "Failed to copy attribute value.");
711 + XmlExitOnFailure(hr, "Failed to copy attribute value.");
712
713 LExit:
714 ReleaseObject(pixnnmAttributes);
@@ -721,7 +736,7 @@ HRESULT DAPI XmlGetYesNoAttribute(
736 hr = XmlGetAttributeEx(pixnNode, wzAttribute, &sczValue);
737 if (E_NOTFOUND != hr)
738 {
724 - ExitOnFailure(hr, "Failed to get attribute.");
739 + XmlExitOnFailure(hr, "Failed to get attribute.");
740
741 *pfYes = CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, sczValue, -1, L"yes", -1);
742 }
@@ -764,7 +779,7 @@ extern "C" HRESULT DAPI XmlGetAttributeNumberBase(
779 BSTR bstrPointer = NULL;
780
781 hr = XmlGetAttribute(pixnNode, pwzAttribute, &bstrPointer);
767 - ExitOnFailure(hr, "Failed to get value from attribute.");
782 + XmlExitOnFailure(hr, "Failed to get value from attribute.");
783
784 if (S_OK == hr)
785 {
@@ -791,13 +806,13 @@ extern "C" HRESULT DAPI XmlGetAttributeLargeNumber(
806 BSTR bstrValue = NULL;
807
808 hr = XmlGetAttribute(pixnNode, pwzAttribute, &bstrValue);
794 - ExitOnFailure(hr, "failed XmlGetAttribute");
809 + XmlExitOnFailure(hr, "failed XmlGetAttribute");
810
811 if (S_OK == hr)
812 {
813 LONGLONG ll = 0;
814 hr = StrStringToInt64(bstrValue, 0, &ll);
800 - ExitOnFailure(hr, "Failed to treat attribute value as number.");
815 + XmlExitOnFailure(hr, "Failed to treat attribute value as number.");
816
817 *pdw64Value = ll;
818 }
@@ -829,7 +844,7 @@ extern "C" HRESULT DAPI XmlGetNamedItem(
844
845 HRESULT hr = S_OK;
846 BSTR bstrName = ::SysAllocString(wzName);
832 - ExitOnNull(bstrName, hr, E_OUTOFMEMORY, "failed SysAllocString");
847 + XmlExitOnNull(bstrName, hr, E_OUTOFMEMORY, "failed SysAllocString");
848
849 hr = pixnmAttributes->getNamedItem(bstrName, ppixnNamedItem);
850
@@ -863,12 +878,12 @@ extern "C" HRESULT DAPI XmlSetText(
878
879 // find the text node
880 hr = pixnNode->get_childNodes(&pixnlNodeList);
866 - ExitOnFailure(hr, "failed to get child nodes");
881 + XmlExitOnFailure(hr, "failed to get child nodes");
882
883 while (S_OK == (hr = pixnlNodeList->nextNode(&pixnChildNode)))
884 {
885 hr = pixnChildNode->get_nodeType(&dnType);
871 - ExitOnFailure(hr, "failed to get node type");
886 + XmlExitOnFailure(hr, "failed to get node type");
887
888 if (NODE_TEXT == dnType)
889 break;
@@ -887,10 +902,10 @@ extern "C" HRESULT DAPI XmlSetText(
902 {
903 hr = HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY);
904 }
890 - ExitOnFailure(hr, "failed SysAllocString in XmlSetText");
905 + XmlExitOnFailure(hr, "failed SysAllocString in XmlSetText");
906
907 hr = pixnChildNode->put_nodeValue(varText);
893 - ExitOnFailure(hr, "failed IXMLDOMNode::put_nodeValue");
908 + XmlExitOnFailure(hr, "failed IXMLDOMNode::put_nodeValue");
909 }
910 else
911 {
@@ -899,13 +914,13 @@ extern "C" HRESULT DAPI XmlSetText(
914 {
915 hr = E_FAIL;
916 }
902 - ExitOnFailure(hr, "failed get_ownerDocument in XmlSetAttribute");
917 + XmlExitOnFailure(hr, "failed get_ownerDocument in XmlSetAttribute");
918
919 hr = XmlCreateTextNode(pixdDocument, pwzText, &pixtTextNode);
905 - ExitOnFailure(hr, "failed createTextNode in XmlSetText(%ls)", pwzText);
920 + XmlExitOnFailure(hr, "failed createTextNode in XmlSetText(%ls)", pwzText);
921
922 hr = pixnNode->appendChild(pixtTextNode, NULL);
908 - ExitOnFailure(hr, "failed appendChild in XmlSetText(%ls)", pwzText);
923 + XmlExitOnFailure(hr, "failed appendChild in XmlSetText(%ls)", pwzText);
924 }
925
926 hr = *pwzText ? S_OK : S_FALSE;
@@ -933,7 +948,7 @@ extern "C" HRESULT DAPI XmlSetTextNumber(
948 WCHAR wzValue[12];
949
950 hr = ::StringCchPrintfW(wzValue, countof(wzValue), L"%u", dwValue);
936 - ExitOnFailure(hr, "Failed to format numeric value as string.");
951 + XmlExitOnFailure(hr, "Failed to format numeric value as string.");
952
953 hr = XmlSetText(pixnNode, wzValue);
954
@@ -963,21 +978,21 @@ extern "C" HRESULT DAPI XmlCreateChild(
978 {
979 hr = E_FAIL;
980 }
966 - ExitOnFailure(hr, "failed get_ownerDocument");
981 + XmlExitOnFailure(hr, "failed get_ownerDocument");
982
983 hr = XmlCreateElement(pixdDocument, pwzElementType, (IXMLDOMElement**) &pixnChild);
984 if (hr == S_FALSE)
985 {
986 hr = E_FAIL;
987 }
973 - ExitOnFailure(hr, "failed createElement");
988 + XmlExitOnFailure(hr, "failed createElement");
989
990 pixnParent->appendChild(pixnChild,NULL);
991 if (hr == S_FALSE)
992 {
993 hr = E_FAIL;
994 }
980 - ExitOnFailure(hr, "failed appendChild");
995 + XmlExitOnFailure(hr, "failed appendChild");
996
997 if (ppixnChild)
998 {
@@ -1005,13 +1020,13 @@ extern "C" HRESULT DAPI XmlRemoveAttribute(
1020 // RELEASEME
1021 IXMLDOMNamedNodeMap* pixnnmAttributes = NULL;
1022 BSTR bstrAttribute = ::SysAllocString(pwzAttribute);
1008 - ExitOnNull(bstrAttribute, hr, E_OUTOFMEMORY, "failed to allocate bstr for attribute in XmlRemoveAttribute");
1023 + XmlExitOnNull(bstrAttribute, hr, E_OUTOFMEMORY, "failed to allocate bstr for attribute in XmlRemoveAttribute");
1024
1025 hr = pixnNode->get_attributes(&pixnnmAttributes);
1011 - ExitOnFailure(hr, "failed get_attributes in RemoveXmlAttribute(%ls)", pwzAttribute);
1026 + XmlExitOnFailure(hr, "failed get_attributes in RemoveXmlAttribute(%ls)", pwzAttribute);
1027
1028 hr = pixnnmAttributes->removeNamedItem(bstrAttribute, NULL);
1014 - ExitOnFailure(hr, "failed removeNamedItem in RemoveXmlAttribute(%ls)", pwzAttribute);
1029 + XmlExitOnFailure(hr, "failed removeNamedItem in RemoveXmlAttribute(%ls)", pwzAttribute);
1030
1031 LExit:
1032 ReleaseObject(pixnnmAttributes);
@@ -1035,11 +1050,11 @@ extern "C" HRESULT DAPI XmlSelectNodes(
1050
1051 BSTR bstrXPath = NULL;
1052
1038 - ExitOnNull(pixnParent, hr, E_UNEXPECTED, "pixnParent parameter was null in XmlSelectNodes");
1039 - ExitOnNull(ppixnlChildren, hr, E_UNEXPECTED, "ppixnChild parameter was null in XmlSelectNodes");
1053 + XmlExitOnNull(pixnParent, hr, E_UNEXPECTED, "pixnParent parameter was null in XmlSelectNodes");
1054 + XmlExitOnNull(ppixnlChildren, hr, E_UNEXPECTED, "ppixnChild parameter was null in XmlSelectNodes");
1055
1056 bstrXPath = ::SysAllocString(wzXPath ? wzXPath : L"");
1042 - ExitOnNull(bstrXPath, hr, E_OUTOFMEMORY, "failed to allocate bstr for XPath expression in XmlSelectNodes");
1057 + XmlExitOnNull(bstrXPath, hr, E_OUTOFMEMORY, "failed to allocate bstr for XPath expression in XmlSelectNodes");
1058
1059 hr = pixnParent->selectNodes(bstrXPath, ppixnlChildren);
1060
@@ -1077,24 +1092,24 @@ extern "C" HRESULT DAPI XmlNextAttribute(
1092 }
1093
1094 hr = pixnnm->nextNode(&pixn);
1080 - ExitOnFailure(hr, "Failed to get next attribute.");
1095 + XmlExitOnFailure(hr, "Failed to get next attribute.");
1096
1097 if (S_OK == hr)
1098 {
1099 hr = pixn->get_nodeType(&nt);
1085 - ExitOnFailure(hr, "failed to get node type");
1100 + XmlExitOnFailure(hr, "failed to get node type");
1101
1102 if (NODE_ATTRIBUTE != nt)
1103 {
1104 hr = E_UNEXPECTED;
1090 - ExitOnFailure(hr, "Failed to get expected node type back: attribute");
1105 + XmlExitOnFailure(hr, "Failed to get expected node type back: attribute");
1106 }
1107
1108 // if the caller asked for the attribute name
1109 if (pbstrAttribute)
1110 {
1111 hr = pixn->get_baseName(pbstrAttribute);
1097 - ExitOnFailure(hr, "failed to get attribute name");
1112 + XmlExitOnFailure(hr, "failed to get attribute name");
1113 }
1114
1115 *pixnAttribute = pixn;
@@ -1140,20 +1155,20 @@ extern "C" HRESULT DAPI XmlNextElement(
1155 while (S_OK == (hr = pixnl->nextNode(&pixn)))
1156 {
1157 hr = pixn->get_nodeType(&nt);
1143 - ExitOnFailure(hr, "failed to get node type");
1158 + XmlExitOnFailure(hr, "failed to get node type");
1159
1160 if (NODE_ELEMENT == nt)
1161 break;
1162
1163 ReleaseNullObject(pixn);
1164 }
1150 - ExitOnFailure(hr, "failed to get next element");
1165 + XmlExitOnFailure(hr, "failed to get next element");
1166
1167 // if we have a node and the caller asked for the element name
1168 if (pixn && pbstrElement)
1169 {
1170 hr = pixn->get_baseName(pbstrElement);
1156 - ExitOnFailure(hr, "failed to get element name");
1171 + XmlExitOnFailure(hr, "failed to get element name");
1172 }
1173
1174 *pixnElement = pixn;
@@ -1185,12 +1200,12 @@ extern "C" HRESULT DAPI XmlRemoveChildren(
1200 if (pwzXPath)
1201 {
1202 hr = XmlSelectNodes(pixnSource, pwzXPath, &pixnlNodeList);
1188 - ExitOnFailure(hr, "failed XmlSelectNodes");
1203 + XmlExitOnFailure(hr, "failed XmlSelectNodes");
1204 }
1205 else
1206 {
1207 hr = pixnSource->get_childNodes(&pixnlNodeList);
1193 - ExitOnFailure(hr, "failed childNodes");
1208 + XmlExitOnFailure(hr, "failed childNodes");
1209 }
1210 if (S_FALSE == hr)
1211 {
@@ -1200,7 +1215,7 @@ extern "C" HRESULT DAPI XmlRemoveChildren(
1215 while (S_OK == (hr = pixnlNodeList->nextNode(&pixnNode)))
1216 {
1217 hr = pixnSource->removeChild(pixnNode, &pixnRemoveChild);
1203 - ExitOnFailure(hr, "failed removeChild");
1218 + XmlExitOnFailure(hr, "failed removeChild");
1219
1220 ReleaseNullObject(pixnRemoveChild);
1221 ReleaseNullObject(pixnNode);
@@ -1240,14 +1255,14 @@ extern "C" HRESULT DAPI XmlSaveDocument(
1255 {
1256 hr = HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY);
1257 }
1243 - ExitOnFailure(hr, "failed to create BSTR");
1258 + XmlExitOnFailure(hr, "failed to create BSTR");
1259
1260 hr = pixdDocument->save(varsDestPath);
1261 if (hr == S_FALSE)
1262 {
1263 hr = E_FAIL;
1264 }
1250 - ExitOnFailure(hr, "failed save in WriteDocument");
1265 + XmlExitOnFailure(hr, "failed save in WriteDocument");
1266
1267 LExit:
1268 ReleaseVariant(varsDestPath);
@@ -1277,33 +1292,33 @@ extern "C" HRESULT DAPI XmlSaveDocumentToBuffer(
1292
1293 // create stream
1294 hr = ::CreateStreamOnHGlobal(NULL, TRUE, &pStream);
1280 - ExitOnFailure(hr, "Failed to create stream.");
1295 + XmlExitOnFailure(hr, "Failed to create stream.");
1296
1297 // write document to stream
1298 vtDestination.vt = VT_UNKNOWN;
1299 vtDestination.punkVal = (IUnknown*)pStream;
1300 hr = pixdDocument->save(vtDestination);
1286 - ExitOnFailure(hr, "Failed to save document.");
1301 + XmlExitOnFailure(hr, "Failed to save document.");
1302
1303 // get stream size
1304 hr = pStream->Stat(&statstg, STATFLAG_NONAME);
1290 - ExitOnFailure(hr, "Failed to get stream size.");
1305 + XmlExitOnFailure(hr, "Failed to get stream size.");
1306
1307 // allocate buffer
1308 pbDest = static_cast<BYTE*>(MemAlloc((SIZE_T)statstg.cbSize.LowPart, TRUE));
1294 - ExitOnNull(pbDest, hr, E_OUTOFMEMORY, "Failed to allocate destination buffer.");
1309 + XmlExitOnNull(pbDest, hr, E_OUTOFMEMORY, "Failed to allocate destination buffer.");
1310
1311 // read data from stream
1312 li.QuadPart = 0;
1313 hr = pStream->Seek(li, STREAM_SEEK_SET, NULL);
1299 - ExitOnFailure(hr, "Failed to seek stream.");
1314 + XmlExitOnFailure(hr, "Failed to seek stream.");
1315
1316 hr = pStream->Read(pbDest, statstg.cbSize.LowPart, &cbRead);
1317 if (cbRead < statstg.cbSize.LowPart)
1318 {
1319 hr = E_FAIL;
1320 }
1306 - ExitOnFailure(hr, "Failed to read stream content to buffer.");
1321 + XmlExitOnFailure(hr, "Failed to read stream content to buffer.");
1322
1323 // return value
1324 *ppbDest = pbDest;