aboutsummaryrefslogtreecommitdiff
path: root/src/dutil/deputil.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/dutil/deputil.cpp145
1 files changed, 80 insertions, 65 deletions
diff --git a/src/dutil/deputil.cpp b/src/dutil/deputil.cpp
index d65c4348..362b3345 100644
--- a/src/dutil/deputil.cpp
+++ b/src/dutil/deputil.cpp
@@ -2,6 +2,21 @@
2 2
3#include "precomp.h" 3#include "precomp.h"
4 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
5#define ARRAY_GROWTH_SIZE 5 20#define ARRAY_GROWTH_SIZE 5
6 21
7static LPCWSTR vcszVersionValue = L"Version"; 22static LPCWSTR vcszVersionValue = L"Version";
@@ -42,7 +57,7 @@ DAPI_(HRESULT) DepGetProviderInformation(
42 57
43 // Format the provider dependency registry key. 58 // Format the provider dependency registry key.
44 hr = AllocDependencyKeyName(wzProviderKey, &sczKey); 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);
46 61
47 // Try to open the dependency key. 62 // Try to open the dependency key.
48 hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey); 63 hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey);
@@ -50,7 +65,7 @@ DAPI_(HRESULT) DepGetProviderInformation(
50 { 65 {
51 ExitFunction1(hr = E_NOTFOUND); 66 ExitFunction1(hr = E_NOTFOUND);
52 } 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);
54 69
55 // Get the Id if requested and available. 70 // Get the Id if requested and available.
56 if (psczId) 71 if (psczId)
@@ -60,7 +75,7 @@ DAPI_(HRESULT) DepGetProviderInformation(
60 { 75 {
61 hr = S_OK; 76 hr = S_OK;
62 } 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);
64 } 79 }
65 80
66 // Get the DisplayName if requested and available. 81 // Get the DisplayName if requested and available.
@@ -71,7 +86,7 @@ DAPI_(HRESULT) DepGetProviderInformation(
71 { 86 {
72 hr = S_OK; 87 hr = S_OK;
73 } 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);
75 } 90 }
76 91
77 // Get the Version if requested and available. 92 // Get the Version if requested and available.
@@ -82,7 +97,7 @@ DAPI_(HRESULT) DepGetProviderInformation(
82 { 97 {
83 hr = S_OK; 98 hr = S_OK;
84 } 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);
86 } 101 }
87 102
88LExit: 103LExit:
@@ -116,19 +131,19 @@ DAPI_(HRESULT) DepCheckDependency(
116 131
117 // Format the provider dependency registry key. 132 // Format the provider dependency registry key.
118 hr = AllocDependencyKeyName(wzProviderKey, &sczKey); 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);
120 135
121 // Try to open the key. If that fails, add the missing dependency key to the dependency array if it doesn't already exist. 136 // Try to open the key. If that fails, add the missing dependency key to the dependency array if it doesn't already exist.
122 hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey); 137 hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey);
123 if (E_FILENOTFOUND != hr) 138 if (E_FILENOTFOUND != hr)
124 { 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);
126 141
127 // If there are no registry values, consider the key orphaned and treat it as missing. 142 // If there are no registry values, consider the key orphaned and treat it as missing.
128 hr = RegReadVersion(hkKey, vcszVersionValue, &dw64Version); 143 hr = RegReadVersion(hkKey, vcszVersionValue, &dw64Version);
129 if (E_FILENOTFOUND != hr) 144 if (E_FILENOTFOUND != hr)
130 { 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);
132 } 147 }
133 } 148 }
134 149
@@ -138,15 +153,15 @@ DAPI_(HRESULT) DepCheckDependency(
138 hr = DictKeyExists(sdDependencies, wzProviderKey); 153 hr = DictKeyExists(sdDependencies, wzProviderKey);
139 if (E_NOTFOUND != hr) 154 if (E_NOTFOUND != hr)
140 { 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);
142 } 157 }
143 else 158 else
144 { 159 {
145 hr = DepDependencyArrayAlloc(prgDependencies, pcDependencies, wzProviderKey, NULL); 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);
147 162
148 hr = DictAddKey(sdDependencies, wzProviderKey); 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);
150 } 165 }
151 166
152 // Exit since the check already failed. 167 // Exit since the check already failed.
@@ -160,7 +175,7 @@ DAPI_(HRESULT) DepCheckDependency(
160 if (0 < cchMinVersion) 175 if (0 < cchMinVersion)
161 { 176 {
162 hr = FileVersionFromStringEx(wzMinVersion, cchMinVersion, &dw64MinVersion); 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);
164 179
165 fAllowEqual = iAttributes & RequiresAttributesMinVersionInclusive; 180 fAllowEqual = iAttributes & RequiresAttributesMinVersionInclusive;
166 if (!(fAllowEqual && dw64MinVersion <= dw64Version || dw64MinVersion < dw64Version)) 181 if (!(fAllowEqual && dw64MinVersion <= dw64Version || dw64MinVersion < dw64Version))
@@ -168,18 +183,18 @@ DAPI_(HRESULT) DepCheckDependency(
168 hr = DictKeyExists(sdDependencies, wzProviderKey); 183 hr = DictKeyExists(sdDependencies, wzProviderKey);
169 if (E_NOTFOUND != hr) 184 if (E_NOTFOUND != hr)
170 { 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);
172 } 187 }
173 else 188 else
174 { 189 {
175 hr = RegReadString(hkKey, vcszDisplayNameValue, &sczName); 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);
177 192
178 hr = DepDependencyArrayAlloc(prgDependencies, pcDependencies, wzProviderKey, sczName); 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);
180 195
181 hr = DictAddKey(sdDependencies, wzProviderKey); 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);
183 } 198 }
184 199
185 // Exit since the check already failed. 200 // Exit since the check already failed.
@@ -195,7 +210,7 @@ DAPI_(HRESULT) DepCheckDependency(
195 if (0 < cchMaxVersion) 210 if (0 < cchMaxVersion)
196 { 211 {
197 hr = FileVersionFromStringEx(wzMaxVersion, cchMaxVersion, &dw64MaxVersion); 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);
199 214
200 fAllowEqual = iAttributes & RequiresAttributesMaxVersionInclusive; 215 fAllowEqual = iAttributes & RequiresAttributesMaxVersionInclusive;
201 if (!(fAllowEqual && dw64Version <= dw64MaxVersion || dw64Version < dw64MaxVersion)) 216 if (!(fAllowEqual && dw64Version <= dw64MaxVersion || dw64Version < dw64MaxVersion))
@@ -203,18 +218,18 @@ DAPI_(HRESULT) DepCheckDependency(
203 hr = DictKeyExists(sdDependencies, wzProviderKey); 218 hr = DictKeyExists(sdDependencies, wzProviderKey);
204 if (E_NOTFOUND != hr) 219 if (E_NOTFOUND != hr)
205 { 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);
207 } 222 }
208 else 223 else
209 { 224 {
210 hr = RegReadString(hkKey, vcszDisplayNameValue, &sczName); 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);
212 227
213 hr = DepDependencyArrayAlloc(prgDependencies, pcDependencies, wzProviderKey, sczName); 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);
215 230
216 hr = DictAddKey(sdDependencies, wzProviderKey); 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);
218 } 233 }
219 234
220 // Exit since the check already failed. 235 // Exit since the check already failed.
@@ -249,17 +264,17 @@ DAPI_(HRESULT) DepCheckDependents(
249 264
250 // Format the provider dependency registry key. 265 // Format the provider dependency registry key.
251 hr = AllocDependencyKeyName(wzProviderKey, &sczKey); 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);
253 268
254 // Try to open the key. If that fails, the dependency information is corrupt. 269 // Try to open the key. If that fails, the dependency information is corrupt.
255 hr = RegOpen(hkHive, sczKey, KEY_READ, &hkProviderKey); 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);
257 272
258 // Try to open the dependencies key. If that does not exist, there are no dependents. 273 // Try to open the dependencies key. If that does not exist, there are no dependents.
259 hr = RegOpen(hkProviderKey, vsczRegistryDependents, KEY_READ, &hkDependentsKey); 274 hr = RegOpen(hkProviderKey, vsczRegistryDependents, KEY_READ, &hkDependentsKey);
260 if (E_FILENOTFOUND != hr) 275 if (E_FILENOTFOUND != hr)
261 { 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);
263 } 278 }
264 else 279 else
265 { 280 {
@@ -272,7 +287,7 @@ DAPI_(HRESULT) DepCheckDependents(
272 hr = RegKeyEnum(hkDependentsKey, dwIndex, &sczDependentKey); 287 hr = RegKeyEnum(hkDependentsKey, dwIndex, &sczDependentKey);
273 if (E_NOMOREITEMS != hr) 288 if (E_NOMOREITEMS != hr)
274 { 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);
276 } 291 }
277 else 292 else
278 { 293 {
@@ -284,16 +299,16 @@ DAPI_(HRESULT) DepCheckDependents(
284 hr = DictKeyExists(sdIgnoredDependents, sczDependentKey); 299 hr = DictKeyExists(sdIgnoredDependents, sczDependentKey);
285 if (E_NOTFOUND != hr) 300 if (E_NOTFOUND != hr)
286 { 301 {
287 ExitOnFailure(hr, "Failed to check the dictionary of ignored dependents."); 302 DepExitOnFailure(hr, "Failed to check the dictionary of ignored dependents.");
288 } 303 }
289 else 304 else
290 { 305 {
291 // Get the name of the dependent from the key. 306 // Get the name of the dependent from the key.
292 hr = GetDependencyNameFromKey(hkHive, sczDependentKey, &sczDependentName); 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);
294 309
295 hr = DepDependencyArrayAlloc(prgDependents, pcDependents, sczDependentKey, sczDependentName); 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);
297 } 312 }
298 } 313 }
299 314
@@ -323,32 +338,32 @@ DAPI_(HRESULT) DepRegisterDependency(
323 338
324 // Format the provider dependency registry key. 339 // Format the provider dependency registry key.
325 hr = AllocDependencyKeyName(wzProviderKey, &sczKey); 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);
327 342
328 // Create the dependency key (or open it if it already exists). 343 // Create the dependency key (or open it if it already exists).
329 hr = RegCreateEx(hkHive, sczKey, KEY_WRITE, FALSE, NULL, &hkKey, &fCreated); 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);
331 346
332 // Set the id if it was provided. 347 // Set the id if it was provided.
333 if (wzId) 348 if (wzId)
334 { 349 {
335 hr = RegWriteString(hkKey, NULL, wzId); 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);
337 } 352 }
338 353
339 // Set the version. 354 // Set the version.
340 hr = RegWriteString(hkKey, vcszVersionValue, wzVersion); 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);
342 357
343 // Set the display name. 358 // Set the display name.
344 hr = RegWriteString(hkKey, vcszDisplayNameValue, wzDisplayName); 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);
346 361
347 // Set the attributes if non-zero. 362 // Set the attributes if non-zero.
348 if (0 != iAttributes) 363 if (0 != iAttributes)
349 { 364 {
350 hr = RegWriteNumber(hkKey, vcszAttributesValue, static_cast<DWORD>(iAttributes)); 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);
352 } 367 }
353 368
354LExit: 369LExit:
@@ -370,12 +385,12 @@ DAPI_(HRESULT) DepDependentExists(
370 385
371 // Format the provider dependents registry key. 386 // Format the provider dependents registry key.
372 hr = StrAllocFormatted(&sczDependentKey, L"%ls%ls\\%ls\\%ls", vsczRegistryRoot, wzDependencyProviderKey, vsczRegistryDependents, wzProviderKey); 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.");
374 389
375 hr = RegOpen(hkHive, sczDependentKey, KEY_READ, &hkDependentKey); 390 hr = RegOpen(hkHive, sczDependentKey, KEY_READ, &hkDependentKey);
376 if (E_FILENOTFOUND != hr) 391 if (E_FILENOTFOUND != hr)
377 { 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);
379 } 394 }
380 395
381LExit: 396LExit:
@@ -403,32 +418,32 @@ DAPI_(HRESULT) DepRegisterDependent(
403 418
404 // Format the provider dependency registry key. 419 // Format the provider dependency registry key.
405 hr = AllocDependencyKeyName(wzDependencyProviderKey, &sczDependencyKey); 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);
407 422
408 // Create the dependency key (or open it if it already exists). 423 // Create the dependency key (or open it if it already exists).
409 hr = RegCreateEx(hkHive, sczDependencyKey, KEY_WRITE, FALSE, NULL, &hkDependencyKey, &fCreated); 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);
411 426
412 // Create the subkey to register the dependent. 427 // Create the subkey to register the dependent.
413 hr = StrAllocFormatted(&sczKey, L"%ls\\%ls", vsczRegistryDependents, wzProviderKey); 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);
415 430
416 hr = RegCreateEx(hkDependencyKey, sczKey, KEY_WRITE, FALSE, NULL, &hkKey, &fCreated); 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);
418 433
419 // Set the minimum version if not NULL. 434 // Set the minimum version if not NULL.
420 hr = RegWriteString(hkKey, vcszMinVersionValue, wzMinVersion); 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);
422 437
423 // Set the maximum version if not NULL. 438 // Set the maximum version if not NULL.
424 hr = RegWriteString(hkKey, vcszMaxVersionValue, wzMaxVersion); 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);
426 441
427 // Set the attributes if non-zero. 442 // Set the attributes if non-zero.
428 if (0 != iAttributes) 443 if (0 != iAttributes)
429 { 444 {
430 hr = RegWriteNumber(hkKey, vcszAttributesValue, static_cast<DWORD>(iAttributes)); 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);
432 } 447 }
433 448
434LExit: 449LExit:
@@ -451,13 +466,13 @@ DAPI_(HRESULT) DepUnregisterDependency(
451 466
452 // Format the provider dependency registry key. 467 // Format the provider dependency registry key.
453 hr = AllocDependencyKeyName(wzProviderKey, &sczKey); 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);
455 470
456 // Delete the entire key including all sub-keys. 471 // Delete the entire key including all sub-keys.
457 hr = RegDelete(hkHive, sczKey, REG_KEY_DEFAULT, TRUE); 472 hr = RegDelete(hkHive, sczKey, REG_KEY_DEFAULT, TRUE);
458 if (E_FILENOTFOUND != hr) 473 if (E_FILENOTFOUND != hr)
459 { 474 {
460 ExitOnFailure(hr, "Failed to delete the key \"%ls\".", sczKey); 475 DepExitOnFailure(hr, "Failed to delete the key \"%ls\".", sczKey);
461 } 476 }
462 477
463LExit: 478LExit:
@@ -484,7 +499,7 @@ DAPI_(HRESULT) DepUnregisterDependent(
484 hr = RegOpen(hkHive, vsczRegistryRoot, KEY_READ, &hkRegistryRoot); 499 hr = RegOpen(hkHive, vsczRegistryRoot, KEY_READ, &hkRegistryRoot);
485 if (E_FILENOTFOUND != hr) 500 if (E_FILENOTFOUND != hr)
486 { 501 {
487 ExitOnFailure(hr, "Failed to open root registry key \"%ls\".", vsczRegistryRoot); 502 DepExitOnFailure(hr, "Failed to open root registry key \"%ls\".", vsczRegistryRoot);
488 } 503 }
489 else 504 else
490 { 505 {
@@ -495,7 +510,7 @@ DAPI_(HRESULT) DepUnregisterDependent(
495 hr = RegOpen(hkRegistryRoot, wzDependencyProviderKey, KEY_READ, &hkDependencyProviderKey); 510 hr = RegOpen(hkRegistryRoot, wzDependencyProviderKey, KEY_READ, &hkDependencyProviderKey);
496 if (E_FILENOTFOUND != hr) 511 if (E_FILENOTFOUND != hr)
497 { 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);
499 } 514 }
500 else 515 else
501 { 516 {
@@ -506,7 +521,7 @@ DAPI_(HRESULT) DepUnregisterDependent(
506 hr = RegOpen(hkDependencyProviderKey, vsczRegistryDependents, KEY_READ, &hkRegistryDependents); 521 hr = RegOpen(hkDependencyProviderKey, vsczRegistryDependents, KEY_READ, &hkRegistryDependents);
507 if (E_FILENOTFOUND != hr) 522 if (E_FILENOTFOUND != hr)
508 { 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);
510 } 525 }
511 else 526 else
512 { 527 {
@@ -515,11 +530,11 @@ DAPI_(HRESULT) DepUnregisterDependent(
515 530
516 // Delete the wzProviderKey dependent sub-key. 531 // Delete the wzProviderKey dependent sub-key.
517 hr = RegDelete(hkRegistryDependents, wzProviderKey, REG_KEY_DEFAULT, TRUE); 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);
519 534
520 // If there are no remaining dependents, delete the Dependents subkey. 535 // If there are no remaining dependents, delete the Dependents subkey.
521 hr = RegQueryKey(hkRegistryDependents, &cSubKeys, NULL); 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);
523 538
524 if (0 < cSubKeys) 539 if (0 < cSubKeys)
525 { 540 {
@@ -531,11 +546,11 @@ DAPI_(HRESULT) DepUnregisterDependent(
531 546
532 // Fail if there are any subkeys since we just checked. 547 // Fail if there are any subkeys since we just checked.
533 hr = RegDelete(hkDependencyProviderKey, vsczRegistryDependents, REG_KEY_DEFAULT, FALSE); 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);
535 550
536 // If there are no values, delete the provider dependency key. 551 // If there are no values, delete the provider dependency key.
537 hr = RegQueryKey(hkDependencyProviderKey, NULL, &cValues); 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);
539 554
540 if (0 == cValues) 555 if (0 == cValues)
541 { 556 {
@@ -544,7 +559,7 @@ DAPI_(HRESULT) DepUnregisterDependent(
544 559
545 // Fail if there are any subkeys since we just checked. 560 // Fail if there are any subkeys since we just checked.
546 hr = RegDelete(hkRegistryRoot, wzDependencyProviderKey, REG_KEY_DEFAULT, FALSE); 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);
548 } 563 }
549 564
550LExit: 565LExit:
@@ -567,21 +582,21 @@ DAPI_(HRESULT) DepDependencyArrayAlloc(
567 DEPENDENCY* pDependency = NULL; 582 DEPENDENCY* pDependency = NULL;
568 583
569 hr = ::UIntAdd(*pcDependencies, 1, &cRequired); 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.");
571 586
572 hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(prgDependencies), cRequired, sizeof(DEPENDENCY), ARRAY_GROWTH_SIZE); 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.");
574 589
575 pDependency = static_cast<DEPENDENCY*>(&(*prgDependencies)[*pcDependencies]); 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.");
577 592
578 hr = StrAllocString(&(pDependency->sczKey), wzKey, 0); 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.");
580 595
581 if (wzName) 596 if (wzName)
582 { 597 {
583 hr = StrAllocString(&(pDependency->sczName), wzName, 0); 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.");
585 } 600 }
586 601
587 // Update the number of current elements in the dependency array. 602 // Update the number of current elements in the dependency array.
@@ -623,18 +638,18 @@ static HRESULT AllocDependencyKeyName(
623 638
624 // Get the length of the dependency, and add to the length of the root. 639 // Get the length of the dependency, and add to the length of the root.
625 hr = ::StringCchLengthW(wzName, STRSAFE_MAX_CCH, &cchName); 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.");
627 642
628 // Add the sizes together to allocate memory once (callee will add space for nul). 643 // Add the sizes together to allocate memory once (callee will add space for nul).
629 hr = ::SizeTAdd(cchRegistryRoot, cchName, &cchKeyName); 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.");
631 646
632 // Allocate and concat the strings together. 647 // Allocate and concat the strings together.
633 hr = StrAllocString(psczKeyName, vsczRegistryRoot, cchKeyName); 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.");
635 650
636 hr = StrAllocConcat(psczKeyName, wzName, cchName); 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.");
638 653
639LExit: 654LExit:
640 return hr; 655 return hr;
@@ -656,13 +671,13 @@ static HRESULT GetDependencyNameFromKey(
656 671
657 // Format the provider dependency registry key. 672 // Format the provider dependency registry key.
658 hr = AllocDependencyKeyName(wzProviderKey, &sczKey); 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);
660 675
661 // Try to open the dependency key. 676 // Try to open the dependency key.
662 hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey); 677 hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey);
663 if (E_FILENOTFOUND != hr) 678 if (E_FILENOTFOUND != hr)
664 { 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);
666 } 681 }
667 else 682 else
668 { 683 {
@@ -673,7 +688,7 @@ static HRESULT GetDependencyNameFromKey(
673 hr = RegReadString(hkKey, vcszDisplayNameValue, psczName); 688 hr = RegReadString(hkKey, vcszDisplayNameValue, psczName);
674 if (E_FILENOTFOUND != hr) 689 if (E_FILENOTFOUND != hr)
675 { 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);
677 } 692 }
678 else 693 else
679 { 694 {