Refactor butil while cleaning up other things.
Sean Hall committed
Jul 18, 2021 at 19:52 UTC
1bdf42c558d6923380b9f3ea409027816f972f98
13 files changed
+369
-323
src/CustomizedNativeRecommendedRules.ruleset
renamed
src/Directory.vcxproj.props
+1
-1
@@ -20,7 +20,7 @@
20
</PropertyGroup>
21
22
<PropertyGroup>
23
- <CodeAnalysisRuleSet Condition=" Exists('$(MSBuildThisFileDirectory)CustomizedNativeRecommendedRules.ruleset') ">$(MSBuildThisFileDirectory)CustomizedNativeRecommendedRules.ruleset</CodeAnalysisRuleSet>
23
+ <CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)CustomizedNativeRecommendedRules.ruleset</CodeAnalysisRuleSet>
24
</PropertyGroup>
25
26
<ItemDefinitionGroup>
src/burn/CustomizedNativeRecommendedRules.ruleset
deleted
-8
@@ -1,8 +0,0 @@
1
-<?xml version="1.0" encoding="utf-8"?>
2
-<RuleSet Name="Customized Microsoft Native Recommended Rules" Description="Microsoft Native Recommended Rules, -C26812" ToolsVersion="16.0">
3
- <Include Path="nativerecommendedrules.ruleset" Action="Default" />
4
- <Rules AnalyzerId="Microsoft.Analyzers.NativeCodeAnalysis" RuleNamespace="Microsoft.Rules.Native">
5
- <!-- We need C style enums since we support BAs written in C -->
6
- <Rule Id="C26812" Action="None" />
7
- </Rules>
8
-</RuleSet>
\ No newline at end of file
src/burn/engine/registration.cpp
+1
-14
@@ -910,7 +910,6 @@ extern "C" HRESULT RegistrationSessionEnd(
910
{
911
HRESULT hr = S_OK;
912
LPWSTR sczRebootRequiredKey = NULL;
913
- LPWSTR sczVariableKey = NULL;
913
HKEY hkRebootRequired = NULL;
914
HKEY hkRegistration = NULL;
915
@@ -958,19 +957,8 @@ extern "C" HRESULT RegistrationSessionEnd(
957
958
RemoveSoftwareTags(pVariables, &pRegistration->softwareTags);
959
961
- // build variable registry key path
962
- hr = StrAllocFormatted(&sczVariableKey, L"%s\\%s", pRegistration->sczRegistrationKey, REGISTRY_BUNDLE_VARIABLE_KEY);
963
- ExitOnFailure(hr, "Failed to build variable registry key path.");
964
-
965
- // Delete registration variable key.
966
- hr = RegDelete(pRegistration->hkRoot, sczVariableKey, REG_KEY_DEFAULT, FALSE);
967
- if (E_FILENOTFOUND != hr)
968
- {
969
- ExitOnFailure(hr, "Failed to delete registration variable key: %ls", sczVariableKey);
970
- }
971
-
960
// Delete registration key.
973
- hr = RegDelete(pRegistration->hkRoot, pRegistration->sczRegistrationKey, REG_KEY_DEFAULT, FALSE);
961
+ hr = RegDelete(pRegistration->hkRoot, pRegistration->sczRegistrationKey, REG_KEY_DEFAULT, TRUE);
962
if (E_FILENOTFOUND != hr)
963
{
964
ExitOnFailure(hr, "Failed to delete registration key: %ls", pRegistration->sczRegistrationKey);
@@ -998,7 +986,6 @@ extern "C" HRESULT RegistrationSessionEnd(
986
LExit:
987
ReleaseRegKey(hkRegistration);
988
ReleaseRegKey(hkRebootRequired);
1001
- ReleaseStr(sczVariableKey);
989
ReleaseStr(sczRebootRequiredKey);
990
991
return hr;
src/burn/test/BurnUnitTest/RegistrationTest.cpp
+41
-39
@@ -4,16 +4,16 @@
4
5
6
#define ROOT_PATH L"SOFTWARE\\WiX_Burn_UnitTest"
7
-#define HKLM_PATH L"SOFTWARE\\WiX_Burn_UnitTest\\HKLM"
8
-#define HKCU_PATH L"SOFTWARE\\WiX_Burn_UnitTest\\HKCU"
7
+#define HKLM_PATH ROOT_PATH L"\\HKLM"
8
+#define HKCU_PATH ROOT_PATH L"\\HKCU"
9
#define REGISTRY_UNINSTALL_KEY L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
10
#define REGISTRY_RUN_KEY L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce"
11
-#define TEST_BUNDLE_ID L"{D54F896D-1952-43e6-9C67-B5652240618C}"
11
+#define TEST_BUNDLE_ID L"{D54F896D-1952-43E6-9C67-B5652240618C}"
12
#define TEST_BUNDLE_UPGRADE_CODE L"{89FDAE1F-8CC1-48B9-B930-3945E0D3E7F0}"
13
14
-#define TEST_UNINSTALL_KEY L"HKEY_CURRENT_USER\\" HKCU_PATH L"\\" REGISTRY_UNINSTALL_KEY L"\\{D54F896D-1952-43e6-9C67-B5652240618C}"
14
+#define TEST_UNINSTALL_KEY L"HKEY_CURRENT_USER\\" HKCU_PATH L"\\" REGISTRY_UNINSTALL_KEY L"\\" TEST_BUNDLE_ID
15
#define TEST_RUN_KEY L"HKEY_CURRENT_USER\\" HKCU_PATH L"\\" REGISTRY_RUN_KEY
16
-#define TEST_VARIABLE_KEY L"HKEY_CURRENT_USER\\" HKCU_PATH L"\\" REGISTRY_UNINSTALL_KEY L"\\{D54F896D-1952-43e6-9C67-B5652240618C}\\variables"
16
+#define TEST_VARIABLE_KEY L"HKEY_CURRENT_USER\\" HKCU_PATH L"\\" REGISTRY_UNINSTALL_KEY L"\\" TEST_BUNDLE_ID L"\\variables"
17
18
19
static LSTATUS APIENTRY RegistrationTest_RegCreateKeyExW(
@@ -75,7 +75,7 @@ namespace Bootstrapper
75
BURN_REGISTRATION registration = { };
76
BURN_LOGGING logging = { };
77
BURN_PACKAGES packages = { };
78
- String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"));
78
+ String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(TEST_BUNDLE_ID));
79
80
try
81
{
@@ -91,7 +91,7 @@ namespace Bootstrapper
91
L" <UX>"
92
L" <Payload Id='ux.dll' FilePath='ux.dll' Packaging='embedded' SourcePath='ux.dll' Hash='000000000000' />"
93
L" </UX>"
94
- L" <Registration Id='{D54F896D-1952-43e6-9C67-B5652240618C}' UpgradeCode='{D54F896D-1952-43e6-9C67-B5652240618C}' Tag='foo' ProviderKey='foo' Version='1.0.0.0' ExecutableName='setup.exe' PerMachine='no'>"
94
+ L" <Registration Id='{D54F896D-1952-43E6-9C67-B5652240618C}' UpgradeCode='{89FDAE1F-8CC1-48B9-B930-3945E0D3E7F0}' Tag='foo' ProviderKey='foo' Version='1.0.0.0' ExecutableName='setup.exe' PerMachine='no'>"
95
L" <Arp Register='yes' Publisher='WiX Toolset' DisplayName='RegisterBasicTest' DisplayVersion='1.0.0.0' />"
96
L" </Registration>"
97
L"</Bundle>";
@@ -123,7 +123,7 @@ namespace Bootstrapper
123
Assert::True(File::Exists(Path::Combine(cacheDirectory, gcnew String(L"setup.exe"))));
124
125
Assert::Equal(Int32(BURN_RESUME_MODE_ACTIVE), (Int32)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Resume"), nullptr));
126
- Assert::Equal<String^>(String::Concat(L"\"", Path::Combine(cacheDirectory, gcnew String(L"setup.exe")), L"\" /burn.runonce"), (String^)(Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"), nullptr)));
126
+ Assert::Equal<String^>(String::Concat(L"\"", Path::Combine(cacheDirectory, gcnew String(L"setup.exe")), L"\" /burn.runonce"), (String^)(Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr)));
127
128
// end session
129
hr = RegistrationSessionEnd(®istration, &variables, &packages, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER, BOOTSTRAPPER_REGISTRATION_TYPE_NONE);
@@ -133,7 +133,7 @@ namespace Bootstrapper
133
Assert::False(Directory::Exists(cacheDirectory));
134
135
Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Resume"), nullptr));
136
- Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"), nullptr));
136
+ Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
137
}
138
finally
139
{
@@ -165,7 +165,7 @@ namespace Bootstrapper
165
BURN_REGISTRATION registration = { };
166
BURN_LOGGING logging = { };
167
BURN_PACKAGES packages = { };
168
- String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"));
168
+ String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(TEST_BUNDLE_ID));
169
try
170
{
171
// set mock API's
@@ -180,7 +180,7 @@ namespace Bootstrapper
180
L" <UX>"
181
L" <Payload Id='ux.dll' FilePath='ux.dll' Packaging='embedded' SourcePath='ux.dll' Hash='000000000000' />"
182
L" </UX>"
183
- L" <Registration Id='{D54F896D-1952-43e6-9C67-B5652240618C}' UpgradeCode='{D54F896D-1952-43e6-9C67-B5652240618C}' Tag='foo' ProviderKey='foo' Version='1.0.0.0' ExecutableName='setup.exe' PerMachine='no'>"
183
+ L" <Registration Id='{D54F896D-1952-43E6-9C67-B5652240618C}' UpgradeCode='{89FDAE1F-8CC1-48B9-B930-3945E0D3E7F0}' Tag='foo' ProviderKey='foo' Version='1.0.0.0' ExecutableName='setup.exe' PerMachine='no'>"
184
L" <Arp Register='yes' Publisher='WiX Toolset' DisplayName='Product1' InProgressDisplayName='Product1 Installation' DisplayVersion='1.0.0.0' />"
185
L" </Registration>"
186
L"</Bundle>";
@@ -214,7 +214,7 @@ namespace Bootstrapper
214
// verify that registration was created
215
Assert::Equal<String^>(gcnew String(L"Product1 Installation"), (String^)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"DisplayName"), nullptr));
216
Assert::Equal(Int32(BURN_RESUME_MODE_ACTIVE), (Int32)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Resume"), nullptr));
217
- Assert::Equal<String^>(String::Concat(L"\"", Path::Combine(cacheDirectory, gcnew String(L"setup.exe")), L"\" /burn.runonce"), (String^)Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"), nullptr));
217
+ Assert::Equal<String^>(String::Concat(L"\"", Path::Combine(cacheDirectory, gcnew String(L"setup.exe")), L"\" /burn.runonce"), (String^)Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
218
219
// complete registration
220
hr = RegistrationSessionEnd(®istration, &variables, &packages, BURN_RESUME_MODE_ARP, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS);
@@ -223,7 +223,7 @@ namespace Bootstrapper
223
// verify that registration was updated
224
Assert::Equal(Int32(BURN_RESUME_MODE_ARP), (Int32)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Resume"), nullptr));
225
Assert::Equal(1, (Int32)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Installed"), nullptr));
226
- Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"), nullptr));
226
+ Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
227
228
//
229
// uninstall
@@ -236,7 +236,7 @@ namespace Bootstrapper
236
// verify that registration was updated
237
Assert::Equal(Int32(BURN_RESUME_MODE_ACTIVE), (Int32)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Resume"), nullptr));
238
Assert::Equal(1, (Int32)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Installed"), nullptr));
239
- Assert::Equal<String^>(String::Concat(L"\"", Path::Combine(cacheDirectory, gcnew String(L"setup.exe")), L"\" /burn.runonce"), (String^)Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"), nullptr));
239
+ Assert::Equal<String^>(String::Concat(L"\"", Path::Combine(cacheDirectory, gcnew String(L"setup.exe")), L"\" /burn.runonce"), (String^)Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
240
241
// delete registration
242
hr = RegistrationSessionEnd(®istration, &variables, &packages, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER, BOOTSTRAPPER_REGISTRATION_TYPE_NONE);
@@ -245,7 +245,7 @@ namespace Bootstrapper
245
// verify that registration was removed
246
Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Resume"), nullptr));
247
Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Installed"), nullptr));
248
- Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"), nullptr));
248
+ Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
249
}
250
finally
251
{
@@ -277,7 +277,7 @@ namespace Bootstrapper
277
BURN_REGISTRATION registration = { };
278
BURN_LOGGING logging = { };
279
BURN_PACKAGES packages = { };
280
- String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"));
280
+ String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(TEST_BUNDLE_ID));
281
try
282
{
283
// set mock API's
@@ -292,7 +292,7 @@ namespace Bootstrapper
292
L" <UX>"
293
L" <Payload Id='ux.dll' FilePath='ux.dll' Packaging='embedded' SourcePath='ux.dll' Hash='000000000000' />"
294
L" </UX>"
295
- L" <Registration Id='{D54F896D-1952-43e6-9C67-B5652240618C}' UpgradeCode='{D54F896D-1952-43e6-9C67-B5652240618C}' Tag='foo' ProviderKey='bar' Version='1.0.0.0' ExecutableName='setup.exe' PerMachine='no'>"
295
+ L" <Registration Id='{D54F896D-1952-43E6-9C67-B5652240618C}' UpgradeCode='{89FDAE1F-8CC1-48B9-B930-3945E0D3E7F0}' Tag='foo' ProviderKey='bar' Version='1.0.0.0' ExecutableName='setup.exe' PerMachine='no'>"
296
L" <Arp Register='yes' Publisher='WiX Toolset' DisplayName='Product1' DisplayVersion='1.0.0.0' />"
297
L" </Registration>"
298
L"</Bundle>";
@@ -325,7 +325,7 @@ namespace Bootstrapper
325
326
// verify that registration was created
327
Assert::Equal(Int32(BURN_RESUME_MODE_ACTIVE), (Int32)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Resume"), nullptr));
328
- Assert::Equal<String^>(String::Concat(L"\"", Path::Combine(cacheDirectory, gcnew String(L"setup.exe")), L"\" /burn.runonce"), (String^)Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"), nullptr));
328
+ Assert::Equal<String^>(String::Concat(L"\"", Path::Combine(cacheDirectory, gcnew String(L"setup.exe")), L"\" /burn.runonce"), (String^)Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
329
330
// complete registration
331
hr = RegistrationSessionEnd(®istration, &variables, &packages, BURN_RESUME_MODE_ARP, BOOTSTRAPPER_APPLY_RESTART_REQUIRED, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER, BOOTSTRAPPER_REGISTRATION_TYPE_FULL);
@@ -355,7 +355,7 @@ namespace Bootstrapper
355
// verify that registration was removed
356
Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Resume"), nullptr));
357
Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Installed"), nullptr));
358
- Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"), nullptr));
358
+ Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
359
}
360
finally
361
{
@@ -387,7 +387,7 @@ namespace Bootstrapper
387
BURN_REGISTRATION registration = { };
388
BURN_LOGGING logging = { };
389
BURN_PACKAGES packages = { };
390
- String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"));
390
+ String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(TEST_BUNDLE_ID));
391
try
392
{
393
// set mock API's
@@ -402,7 +402,7 @@ namespace Bootstrapper
402
L" <UX UxDllPayloadId='ux.dll'>"
403
L" <Payload Id='ux.dll' FilePath='ux.dll' Packaging='embedded' SourcePath='ux.dll' Hash='000000000000' />"
404
L" </UX>"
405
- L" <Registration Id='{D54F896D-1952-43e6-9C67-B5652240618C}' UpgradeCode='{D54F896D-1952-43e6-9C67-B5652240618C}' Tag='foo' ProviderKey='foo' Version='1.0.0.0' ExecutableName='setup.exe' PerMachine='no'>"
405
+ L" <Registration Id='{D54F896D-1952-43E6-9C67-B5652240618C}' UpgradeCode='{89FDAE1F-8CC1-48B9-B930-3945E0D3E7F0}' Tag='foo' ProviderKey='foo' Version='1.0.0.0' ExecutableName='setup.exe' PerMachine='no'>"
406
L" <Arp Register='yes' DisplayName='DisplayName1' DisplayVersion='1.2.3.4' Publisher='Publisher1' HelpLink='http://www.microsoft.com/help'"
407
L" HelpTelephone='555-555-5555' AboutUrl='http://www.microsoft.com/about' UpdateUrl='http://www.microsoft.com/update'"
408
L" Comments='Comments1' Contact='Contact1' DisableModify='yes' DisableRemove='yes' />"
@@ -437,7 +437,7 @@ namespace Bootstrapper
437
438
// verify that registration was created
439
Assert::Equal(Int32(BURN_RESUME_MODE_ACTIVE), (Int32)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Resume"), nullptr));
440
- Assert::Equal<String^>(String::Concat(L"\"", Path::Combine(cacheDirectory, gcnew String(L"setup.exe")), L"\" /burn.runonce"), (String^)Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"), nullptr));
440
+ Assert::Equal<String^>(String::Concat(L"\"", Path::Combine(cacheDirectory, gcnew String(L"setup.exe")), L"\" /burn.runonce"), (String^)Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
441
442
// finish registration
443
hr = RegistrationSessionEnd(®istration, &variables, &packages, BURN_RESUME_MODE_ARP, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER, BOOTSTRAPPER_REGISTRATION_TYPE_FULL);
@@ -446,7 +446,7 @@ namespace Bootstrapper
446
// verify that registration was updated
447
Assert::Equal(Int32(BURN_RESUME_MODE_ARP), (Int32)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Resume"), nullptr));
448
Assert::Equal(1, (Int32)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Installed"), nullptr));
449
- Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"), nullptr));
449
+ Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
450
451
Assert::Equal<String^>(gcnew String(L"DisplayName1"), (String^)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"DisplayName"), nullptr));
452
Assert::Equal<String^>(gcnew String(L"1.2.3.4"), (String^)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"DisplayVersion"), nullptr));
@@ -470,7 +470,7 @@ namespace Bootstrapper
470
471
// verify that registration was updated
472
Assert::Equal(Int32(BURN_RESUME_MODE_ACTIVE), (Int32)Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Resume"), nullptr));
473
- Assert::Equal<String^>(String::Concat(L"\"", Path::Combine(cacheDirectory, gcnew String(L"setup.exe")), L"\" /burn.runonce"), (String^)Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"), nullptr));
473
+ Assert::Equal<String^>(String::Concat(L"\"", Path::Combine(cacheDirectory, gcnew String(L"setup.exe")), L"\" /burn.runonce"), (String^)Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
474
475
// delete registration
476
hr = RegistrationSessionEnd(®istration, &variables, &packages, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER, BOOTSTRAPPER_REGISTRATION_TYPE_NONE);
@@ -479,7 +479,7 @@ namespace Bootstrapper
479
// verify that registration was removed
480
Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Resume"), nullptr));
481
Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_UNINSTALL_KEY), gcnew String(L"Installed"), nullptr));
482
- Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"), nullptr));
482
+ Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
483
}
484
finally
485
{
@@ -517,7 +517,7 @@ namespace Bootstrapper
517
BYTE* pbBuffer = NULL;
518
SIZE_T cbBuffer = 0;
519
520
- String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"));
520
+ String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(TEST_BUNDLE_ID));
521
try
522
{
523
// set mock API's
@@ -532,8 +532,8 @@ namespace Bootstrapper
532
L" <UX>"
533
L" <Payload Id='ux.dll' FilePath='ux.dll' Packaging='embedded' SourcePath='ux.dll' Hash='000000000000' />"
534
L" </UX>"
535
- L" <RelatedBundle Id='" TEST_BUNDLE_UPGRADE_CODE "' Action='Upgrade' />"
536
- L" <Registration Id='" TEST_BUNDLE_ID "' Tag='foo' ProviderKey='" TEST_BUNDLE_ID "' Version='1.0.0.0' ExecutableName='setup.exe' PerMachine='no'>"
535
+ L" <RelatedBundle Id='" TEST_BUNDLE_UPGRADE_CODE L"' Action='Upgrade' />"
536
+ L" <Registration Id='" TEST_BUNDLE_ID L"' Tag='foo' ProviderKey='" TEST_BUNDLE_ID L"' Version='1.0.0.0' ExecutableName='setup.exe' PerMachine='no'>"
537
L" <Arp Register='yes' Publisher='WiX Toolset' DisplayName='RegisterBasicTest' DisplayVersion='1.0.0.0' />"
538
L" </Registration>"
539
L" <Variable Id='MyBurnVariable1' Type='numeric' Value='0' Hidden='no' Persisted='yes' />"
@@ -585,6 +585,7 @@ namespace Bootstrapper
585
586
ReleaseNullBuffer(pbBuffer);
587
cbBuffer = 0;
588
+
589
// Verify the variables exist
590
Assert::Equal<String^>(gcnew String(L"42"), (String^)Registry::GetValue(gcnew String(TEST_VARIABLE_KEY), gcnew String(L"MyBurnVariable1"), nullptr));
591
Assert::Equal<String^>(gcnew String(L"bar"), (String^)Registry::GetValue(gcnew String(TEST_VARIABLE_KEY), gcnew String(L"MyBurnVariable2"), nullptr));
@@ -596,12 +597,14 @@ namespace Bootstrapper
597
// Verify we can find ourself via the UpgradeCode
598
hr = BundleEnumRelatedBundle(TEST_BUNDLE_UPGRADE_CODE, BUNDLE_INSTALL_CONTEXT_USER, &dwRelatedBundleIndex, sczRelatedBundleId);
599
TestThrowOnFailure(hr, L"Failed to enumerate related bundle.");
599
- Assert::Equal<String^>(gcnew String(TEST_BUNDLE_ID), gcnew String(sczRelatedBundleId));
600
+
601
+ NativeAssert::StringEqual(TEST_BUNDLE_ID, sczRelatedBundleId);
602
603
// Verify we can read the bundle variables via the API
604
hr = BundleGetBundleVariable(TEST_BUNDLE_ID, L"MyBurnVariable1", &sczValue);
605
TestThrowOnFailure(hr, L"Failed to read MyBurnVariable1.");
604
- Assert::Equal<String^>(gcnew String(L"42"), gcnew String(sczValue));
606
+
607
+ NativeAssert::StringEqual(L"42", sczValue);
608
609
// end session
610
hr = RegistrationSessionEnd(®istration, &variables, &packages, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER, BOOTSTRAPPER_REGISTRATION_TYPE_NONE);
@@ -626,7 +629,7 @@ namespace Bootstrapper
629
}
630
}
631
629
- [Fact]//(Skip = "Currently fails")]
632
+ [Fact]
633
void ResumeTest()
634
{
635
HRESULT hr = S_OK;
@@ -643,7 +646,7 @@ namespace Bootstrapper
646
BYTE* pbBuffer = NULL;
647
SIZE_T cbBuffer = 0;
648
SIZE_T piBuffer = 0;
646
- String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"));
649
+ String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(TEST_BUNDLE_ID));
650
try
651
{
652
// set mock API's
@@ -658,7 +661,7 @@ namespace Bootstrapper
661
L" <UX>"
662
L" <Payload Id='ux.dll' FilePath='ux.dll' Packaging='embedded' SourcePath='ux.dll' Hash='000000000000' />"
663
L" </UX>"
661
- L" <Registration Id='{D54F896D-1952-43e6-9C67-B5652240618C}' UpgradeCode='{D54F896D-1952-43e6-9C67-B5652240618C}' Tag='foo' ProviderKey='foo' Version='1.0.0.0' ExecutableName='setup.exe' PerMachine='no'>"
664
+ L" <Registration Id='{D54F896D-1952-43E6-9C67-B5652240618C}' UpgradeCode='{89FDAE1F-8CC1-48B9-B930-3945E0D3E7F0}' Tag='foo' ProviderKey='foo' Version='1.0.0.0' ExecutableName='setup.exe' PerMachine='no'>"
665
L" <Arp Register='yes' Publisher='WiX Toolset' DisplayName='RegisterBasicTest' DisplayVersion='1.0.0.0' />"
666
L" </Registration>"
667
L" <Variable Id='MyBurnVariable1' Type='numeric' Value='0' Hidden='no' Persisted='yes' />"
@@ -715,6 +718,7 @@ namespace Bootstrapper
718
719
ReleaseNullBuffer(pbBuffer);
720
cbBuffer = 0;
721
+
722
// Verify the variables exist
723
Assert::Equal<String^>(gcnew String(L"42"), (String^)Registry::GetValue(gcnew String(TEST_VARIABLE_KEY), gcnew String(L"MyBurnVariable1"), nullptr));
724
Assert::Equal<String^>(gcnew String(L"bar"), (String^)Registry::GetValue(gcnew String(TEST_VARIABLE_KEY), gcnew String(L"MyBurnVariable2"), nullptr));
@@ -723,7 +727,8 @@ namespace Bootstrapper
727
728
hr = BundleGetBundleVariable(TEST_BUNDLE_ID, L"MyBurnVariable1", &sczValue);
729
TestThrowOnFailure(hr, L"Failed to read MyBurnVariable1.");
726
- Assert::Equal<String^>(gcnew String(L"42"), gcnew String(sczValue));
730
+
731
+ NativeAssert::StringEqual(L"42", sczValue);
732
733
// read interrupted resume type
734
hr = RegistrationDetectResumeType(®istration, &resumeType);
@@ -736,7 +741,7 @@ namespace Bootstrapper
741
TestThrowOnFailure(hr, L"Failed to suspend session.");
742
743
// verify that run key was removed
739
- Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"), nullptr));
744
+ Assert::Equal((Object^)nullptr, Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
745
746
// read suspend resume type
747
hr = RegistrationDetectResumeType(®istration, &resumeType);
@@ -751,15 +756,12 @@ namespace Bootstrapper
756
hr = VariableDeserialize(&variables, TRUE, pbBuffer, cbBuffer, &piBuffer);
757
TestThrowOnFailure(hr, L"Failed to deserialize variables.");
758
754
- //Assert::Equal((SIZE_T)sizeof(rgbData), cbBuffer);
755
- //Assert::True(0 == memcmp(pbBuffer, rgbData, sizeof(rgbData)));
756
-
759
// write active resume mode
760
hr = RegistrationSessionResume(®istration, &variables, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS);
761
TestThrowOnFailure(hr, L"Failed to write active resume mode.");
762
763
// verify that run key was put back
762
- Assert::NotEqual((Object^)nullptr, Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"), nullptr));
764
+ Assert::NotEqual((Object^)nullptr, Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
765
766
// end session
767
hr = RegistrationSessionEnd(®istration, &variables, &packages, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER, BOOTSTRAPPER_REGISTRATION_TYPE_NONE);
src/ext/Bal/CustomizedNativeRecommendedRules.ruleset
deleted
-8
@@ -1,8 +0,0 @@
1
-<?xml version="1.0" encoding="utf-8"?>
2
-<RuleSet Name="Customized Microsoft Native Recommended Rules" Description="Microsoft Native Recommended Rules, -C26812" ToolsVersion="16.0">
3
- <Include Path="nativerecommendedrules.ruleset" Action="Default" />
4
- <Rules AnalyzerId="Microsoft.Analyzers.NativeCodeAnalysis" RuleNamespace="Microsoft.Rules.Native">
5
- <!-- We need C style enums since we support BAs written in C -->
6
- <Rule Id="C26812" Action="None" />
7
- </Rules>
8
-</RuleSet>
\ No newline at end of file
src/ext/NetFx/CustomizedNativeRecommendedRules.ruleset
deleted
-8
@@ -1,8 +0,0 @@
1
-<?xml version="1.0" encoding="utf-8"?>
2
-<RuleSet Name="Customized Microsoft Native Recommended Rules" Description="Microsoft Native Recommended Rules, -C26812" ToolsVersion="16.0">
3
- <Include Path="nativerecommendedrules.ruleset" Action="Default" />
4
- <Rules AnalyzerId="Microsoft.Analyzers.NativeCodeAnalysis" RuleNamespace="Microsoft.Rules.Native">
5
- <!-- We need C style enums since we support BAs written in C -->
6
- <Rule Id="C26812" Action="None" />
7
- </Rules>
8
-</RuleSet>
\ No newline at end of file
src/ext/Util/CustomizedNativeRecommendedRules.ruleset
deleted
-8
@@ -1,8 +0,0 @@
1
-<?xml version="1.0" encoding="utf-8"?>
2
-<RuleSet Name="Customized Microsoft Native Recommended Rules" Description="Microsoft Native Recommended Rules, -C26812" ToolsVersion="16.0">
3
- <Include Path="nativerecommendedrules.ruleset" Action="Default" />
4
- <Rules AnalyzerId="Microsoft.Analyzers.NativeCodeAnalysis" RuleNamespace="Microsoft.Rules.Native">
5
- <!-- We need C style enums since we support BAs written in C -->
6
- <Rule Id="C26812" Action="None" />
7
- </Rules>
8
-</RuleSet>
\ No newline at end of file
src/libs/dutil/CustomizedNativeRecommendedRules.ruleset
deleted
-8
@@ -1,8 +0,0 @@
1
-<?xml version="1.0" encoding="utf-8"?>
2
-<RuleSet Name="Customized Microsoft Native Recommended Rules" Description="Microsoft Native Recommended Rules, -C26812" ToolsVersion="16.0">
3
- <Include Path="nativerecommendedrules.ruleset" Action="Default" />
4
- <Rules AnalyzerId="Microsoft.Analyzers.NativeCodeAnalysis" RuleNamespace="Microsoft.Rules.Native">
5
- <!-- We need C style enums since we support BAs written in C -->
6
- <Rule Id="C26812" Action="None" />
7
- </Rules>
8
-</RuleSet>
\ No newline at end of file
src/libs/dutil/WixToolset.DUtil/butil.cpp
+118
-74
@@ -8,6 +8,7 @@
8
#define ButilExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_BUTIL, x, s, __VA_ARGS__)
9
#define ButilExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_BUTIL, x, s, __VA_ARGS__)
10
#define ButilExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_BUTIL, x, s, __VA_ARGS__)
11
+#define ButilExitWithRootFailure(x, e, s, ...) ExitWithRootFailureSource(DUTIL_SOURCE_BUTIL, x, e, s, __VA_ARGS__)
12
#define ButilExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_BUTIL, x, s, __VA_ARGS__)
13
#define ButilExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_BUTIL, p, x, e, s, __VA_ARGS__)
14
#define ButilExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_BUTIL, p, x, s, __VA_ARGS__)
@@ -22,7 +23,29 @@ const LPCWSTR BUNDLE_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE = L"BundleUpgrade
23
const LPCWSTR BUNDLE_REGISTRATION_REGISTRY_BUNDLE_PROVIDER_KEY = L"BundleProviderKey";
24
const LPCWSTR BUNDLE_REGISTRATION_REGISTRY_BUNDLE_VARIABLE_KEY = L"variables";
25
26
+enum INTERNAL_BUNDLE_STATUS
27
+{
28
+ INTERNAL_BUNDLE_STATUS_SUCCESS,
29
+ INTERNAL_BUNDLE_STATUS_UNKNOWN_BUNDLE,
30
+ INTERNAL_BUNDLE_STATUS_UNKNOWN_PROPERTY,
31
+};
32
+
33
// Forward declarations.
34
+/********************************************************************
35
+LocateAndQueryBundleValue - Locates the requested key for the bundle,
36
+ then queries the registry type for requested value.
37
+
38
+NOTE: caller is responsible for closing key
39
+********************************************************************/
40
+static HRESULT LocateAndQueryBundleValue(
41
+ __in_z LPCWSTR wzBundleId,
42
+ __in_opt LPCWSTR wzSubKey,
43
+ __in LPCWSTR wzValueName,
44
+ __inout HKEY* phKey,
45
+ __inout DWORD* pdwType,
46
+ __out INTERNAL_BUNDLE_STATUS* pStatus
47
+ );
48
+
49
/********************************************************************
50
OpenBundleKey - Opens the bundle uninstallation key for a given bundle
51
@@ -31,43 +54,44 @@ NOTE: caller is responsible for closing key
54
static HRESULT OpenBundleKey(
55
__in_z LPCWSTR wzBundleId,
56
__in BUNDLE_INSTALL_CONTEXT context,
34
- __in_opt LPCWSTR szSubKey,
35
- __inout HKEY* key);
57
+ __in_opt LPCWSTR wzSubKey,
58
+ __inout HKEY* phKey
59
+ );
60
37
-/********************************************************************
38
-BundleGetBundleInfo - Read the registration data for a gven bundle
39
-********************************************************************/
40
-extern "C" HRESULT DAPI BundleGetBundleInfo(
41
- __in_z LPCWSTR wzBundleId,
42
- __in_z LPCWSTR wzAttribute,
43
- __out_ecount_opt(*pcchValueBuf) LPWSTR lpValueBuf,
44
- __inout_opt LPDWORD pcchValueBuf
45
- )
61
+DAPI_(HRESULT) BundleGetBundleInfo(
62
+ __in_z LPCWSTR wzBundleId,
63
+ __in_z LPCWSTR wzAttribute,
64
+ __out_ecount_opt(*pcchValueBuf) LPWSTR lpValueBuf,
65
+ __inout_opt LPDWORD pcchValueBuf
66
+ )
67
{
68
Assert(wzBundleId && wzAttribute);
69
70
HRESULT hr = S_OK;
71
LPWSTR sczValue = NULL;
72
HKEY hkBundle = NULL;
73
+ INTERNAL_BUNDLE_STATUS status = INTERNAL_BUNDLE_STATUS_SUCCESS;
74
DWORD cchSource = 0;
75
DWORD dwType = 0;
76
DWORD dwValue = 0;
77
78
if ((lpValueBuf && !pcchValueBuf) || !wzBundleId || !wzAttribute)
79
{
58
- ButilExitOnFailure(hr = E_INVALIDARG, "An invalid parameter was passed to the function.");
80
+ ButilExitWithRootFailure(hr, E_INVALIDARG, "An invalid parameter was passed to the function.");
81
}
82
61
- if (FAILED(hr = OpenBundleKey(wzBundleId, BUNDLE_INSTALL_CONTEXT_MACHINE, NULL, &hkBundle)) &&
62
- FAILED(hr = OpenBundleKey(wzBundleId, BUNDLE_INSTALL_CONTEXT_USER, NULL, &hkBundle)))
83
+ hr = LocateAndQueryBundleValue(wzBundleId, NULL, wzAttribute, &hkBundle, &dwType, &status);
84
+ ButilExitOnFailure(hr, "Failed to locate and query bundle attribute.");
85
+
86
+ switch (status)
87
{
64
- ButilExitOnFailure(E_FILENOTFOUND == hr ? HRESULT_FROM_WIN32(ERROR_UNKNOWN_PRODUCT) : hr, "Failed to locate bundle uninstall key path.");
88
+ case INTERNAL_BUNDLE_STATUS_UNKNOWN_BUNDLE:
89
+ ExitFunction1(hr = HRESULT_FROM_WIN32(ERROR_UNKNOWN_PRODUCT));
90
+ case INTERNAL_BUNDLE_STATUS_UNKNOWN_PROPERTY:
91
+ // If the bundle doesn't have the property defined, return ERROR_UNKNOWN_PROPERTY
92
+ ExitFunction1(hr = HRESULT_FROM_WIN32(ERROR_UNKNOWN_PROPERTY));
93
}
94
67
- // If the bundle doesn't have the property defined, return ERROR_UNKNOWN_PROPERTY
68
- hr = RegGetType(hkBundle, wzAttribute, &dwType);
69
- ButilExitOnFailure(E_FILENOTFOUND == hr ? HRESULT_FROM_WIN32(ERROR_UNKNOWN_PROPERTY) : hr, "Failed to locate bundle property.");
70
-
95
switch (dwType)
96
{
97
case REG_SZ:
@@ -82,12 +106,11 @@ extern "C" HRESULT DAPI BundleGetBundleInfo(
106
ButilExitOnFailure(hr, "Failed to format dword property as string.");
107
break;
108
default:
85
- ButilExitOnFailure(hr = E_NOTIMPL, "Reading bundle info of type 0x%x not implemented.", dwType);
86
-
109
+ ButilExitWithRootFailure(hr, E_NOTIMPL, "Reading bundle info of type 0x%x not implemented.", dwType);
110
}
111
112
hr = ::StringCchLengthW(sczValue, STRSAFE_MAX_CCH, reinterpret_cast<UINT_PTR*>(&cchSource));
90
- ButilExitOnFailure(hr, "Failed to calculate length of string");
113
+ ButilExitOnRootFailure(hr, "Failed to calculate length of string.");
114
115
if (lpValueBuf)
116
{
@@ -95,11 +118,11 @@ extern "C" HRESULT DAPI BundleGetBundleInfo(
118
if (*pcchValueBuf <= cchSource)
119
{
120
*pcchValueBuf = ++cchSource;
98
- ButilExitOnFailure(hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA), "A buffer is too small to hold the requested data.");
121
+ ExitFunction1(hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA));
122
}
123
124
hr = ::StringCchCatNExW(lpValueBuf, *pcchValueBuf, sczValue, cchSource, NULL, NULL, STRSAFE_FILL_BEHIND_NULL);
102
- ButilExitOnFailure(hr, "Failed to copy the property value to the output buffer.");
125
+ ButilExitOnRootFailure(hr, "Failed to copy the property value to the output buffer.");
126
127
*pcchValueBuf = cchSource++;
128
}
@@ -111,10 +134,8 @@ LExit:
134
return hr;
135
}
136
114
-/********************************************************************
115
-********************************************************************/
137
117
-extern "C" HRESULT DAPI BundleEnumRelatedBundle(
138
+DAPI_(HRESULT) BundleEnumRelatedBundle(
139
__in_z LPCWSTR wzUpgradeCode,
140
__in BUNDLE_INSTALL_CONTEXT context,
141
__inout PDWORD pdwStartIndex,
@@ -170,6 +191,7 @@ extern "C" HRESULT DAPI BundleEnumRelatedBundle(
191
case REG_SZ:
192
hr = RegReadString(hkBundle, BUNDLE_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE, &sczValue);
193
ButilExitOnFailure(hr, "Failed to read BundleUpgradeCode string property.");
194
+
195
if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, sczValue, -1, wzUpgradeCode, -1))
196
{
197
*pdwStartIndex = dwIndex;
@@ -202,8 +224,7 @@ extern "C" HRESULT DAPI BundleEnumRelatedBundle(
224
break;
225
226
default:
205
- ButilExitOnFailure(hr = E_NOTIMPL, "BundleUpgradeCode of type 0x%x not implemented.", dwType);
206
-
227
+ ButilExitWithRootFailure(hr, E_NOTIMPL, "BundleUpgradeCode of type 0x%x not implemented.", dwType);
228
}
229
230
if (fUpgradeCodeFound)
@@ -211,10 +232,10 @@ extern "C" HRESULT DAPI BundleEnumRelatedBundle(
232
if (lpBundleIdBuf)
233
{
234
hr = ::StringCchLengthW(sczUninstallSubKey, STRSAFE_MAX_CCH, reinterpret_cast<UINT_PTR*>(&cchUninstallSubKey));
214
- ButilExitOnFailure(hr, "Failed to calculate length of string");
235
+ ButilExitOnRootFailure(hr, "Failed to calculate length of string");
236
237
hr = ::StringCchCopyNExW(lpBundleIdBuf, MAX_GUID_CHARS + 1, sczUninstallSubKey, cchUninstallSubKey, NULL, NULL, STRSAFE_FILL_BEHIND_NULL);
217
- ButilExitOnFailure(hr, "Failed to copy the property value to the output buffer.");
238
+ ButilExitOnRootFailure(hr, "Failed to copy the property value to the output buffer.");
239
}
240
241
break;
@@ -237,52 +258,37 @@ LExit:
258
return hr;
259
}
260
240
-/********************************************************************
241
-BundleGetBundleVariable - Queries the bundle installation metadata for a given variable,
242
-the caller is expected to free the memory returned vis psczValue
243
-RETURNS:
244
-S_OK
245
- Success, if the variable had a value, it's returned in psczValue
246
-E_INVALIDARG
247
- An invalid parameter was passed to the function.
248
-HRESULT_FROM_WIN32(ERROR_UNKNOWN_PRODUCT)
249
- The bundle is not installed
250
-HRESULT_FROM_WIN32(ERROR_UNKNOWN_PROPERTY)
251
- The variable is unrecognized
252
-E_NOTIMPL:
253
- Tried to read a bundle variable for a type which has not been implemented
254
-
255
-All other returns are unexpected returns from other dutil methods.
256
-********************************************************************/
261
258
-extern "C" HRESULT DAPI BundleGetBundleVariable(
262
+DAPI_(HRESULT) BundleGetBundleVariable(
263
__in_z LPCWSTR wzBundleId,
264
__in_z LPCWSTR wzVariable,
261
- __deref_out_z LPWSTR * psczValue
262
-)
265
+ __deref_out_z LPWSTR* psczValue
266
+ )
267
{
268
Assert(wzBundleId && wzVariable);
269
270
HRESULT hr = S_OK;
267
- BUNDLE_INSTALL_CONTEXT context = BUNDLE_INSTALL_CONTEXT_MACHINE;
271
HKEY hkBundle = NULL;
272
+ INTERNAL_BUNDLE_STATUS status = INTERNAL_BUNDLE_STATUS_SUCCESS;
273
DWORD dwType = 0;
274
275
if (!wzBundleId || !wzVariable || !psczValue)
276
{
273
- ButilExitOnFailure(hr = E_INVALIDARG, "An invalid parameter was passed to the function.");
277
+ ButilExitWithRootFailure(hr, E_INVALIDARG, "An invalid parameter was passed to the function.");
278
}
279
276
- if (FAILED(hr = OpenBundleKey(wzBundleId, context = BUNDLE_INSTALL_CONTEXT_MACHINE, BUNDLE_REGISTRATION_REGISTRY_BUNDLE_VARIABLE_KEY, &hkBundle)) &&
277
- FAILED(hr = OpenBundleKey(wzBundleId, context = BUNDLE_INSTALL_CONTEXT_USER, BUNDLE_REGISTRATION_REGISTRY_BUNDLE_VARIABLE_KEY, &hkBundle)))
280
+ hr = LocateAndQueryBundleValue(wzBundleId, BUNDLE_REGISTRATION_REGISTRY_BUNDLE_VARIABLE_KEY, wzVariable, &hkBundle, &dwType, &status);
281
+ ButilExitOnFailure(hr, "Failed to locate and query bundle variable.");
282
+
283
+ switch (status)
284
{
279
- ButilExitOnFailure(E_FILENOTFOUND == hr ? HRESULT_FROM_WIN32(ERROR_UNKNOWN_PRODUCT) : hr, "Failed to locate bundle uninstall key variable path.");
285
+ case INTERNAL_BUNDLE_STATUS_UNKNOWN_BUNDLE:
286
+ ExitFunction1(hr = HRESULT_FROM_WIN32(ERROR_UNKNOWN_PRODUCT));
287
+ case INTERNAL_BUNDLE_STATUS_UNKNOWN_PROPERTY:
288
+ // If the bundle doesn't have the shared variable defined, return ERROR_UNKNOWN_PROPERTY
289
+ ExitFunction1(hr = HRESULT_FROM_WIN32(ERROR_UNKNOWN_PROPERTY));
290
}
291
282
- // If the bundle doesn't have the shared variable defined, return ERROR_UNKNOWN_PROPERTY
283
- hr = RegGetType(hkBundle, wzVariable, &dwType);
284
- ButilExitOnFailure(E_FILENOTFOUND == hr ? HRESULT_FROM_WIN32(ERROR_UNKNOWN_PROPERTY) : hr, "Failed to locate bundle variable.");
285
-
292
switch (dwType)
293
{
294
case REG_SZ:
@@ -293,35 +299,74 @@ extern "C" HRESULT DAPI BundleGetBundleVariable(
299
hr = S_OK;
300
break;
301
default:
296
- ButilExitOnFailure(hr = E_NOTIMPL, "Reading bundle variable of type 0x%x not implemented.", dwType);
297
-
302
+ ButilExitWithRootFailure(hr, E_NOTIMPL, "Reading bundle variable of type 0x%x not implemented.", dwType);
303
}
304
305
LExit:
306
ReleaseRegKey(hkBundle);
307
308
return hr;
309
+}
310
+
311
+static HRESULT LocateAndQueryBundleValue(
312
+ __in_z LPCWSTR wzBundleId,
313
+ __in_opt LPCWSTR wzSubKey,
314
+ __in LPCWSTR wzValueName,
315
+ __inout HKEY* phKey,
316
+ __inout DWORD* pdwType,
317
+ __out INTERNAL_BUNDLE_STATUS* pStatus
318
+ )
319
+{
320
+ HRESULT hr = S_OK;
321
+
322
+ *pStatus = INTERNAL_BUNDLE_STATUS_SUCCESS;
323
324
+ if (FAILED(hr = OpenBundleKey(wzBundleId, BUNDLE_INSTALL_CONTEXT_MACHINE, wzSubKey, phKey)) &&
325
+ FAILED(hr = OpenBundleKey(wzBundleId, BUNDLE_INSTALL_CONTEXT_USER, wzSubKey, phKey)))
326
+ {
327
+ if (E_FILENOTFOUND == hr)
328
+ {
329
+ *pStatus = INTERNAL_BUNDLE_STATUS_UNKNOWN_BUNDLE;
330
+ ExitFunction1(hr = S_OK);
331
+ }
332
+
333
+ ButilExitOnFailure(hr, "Failed to open bundle key.");
334
+ }
335
+
336
+ // If the bundle doesn't have the value defined, return ERROR_UNKNOWN_PROPERTY
337
+ hr = RegGetType(*phKey, wzValueName, pdwType);
338
+ if (FAILED(hr))
339
+ {
340
+ if (E_FILENOTFOUND == hr)
341
+ {
342
+ *pStatus = INTERNAL_BUNDLE_STATUS_UNKNOWN_PROPERTY;
343
+ ExitFunction1(hr = S_OK);
344
+ }
345
+
346
+ ButilExitOnFailure(hr, "Failed to read bundle value.");
347
+ }
348
+
349
+LExit:
350
+ return hr;
351
}
306
-/********************************************************************
307
-*
308
-********************************************************************/
309
-HRESULT OpenBundleKey(
352
+
353
+static HRESULT OpenBundleKey(
354
__in_z LPCWSTR wzBundleId,
355
__in BUNDLE_INSTALL_CONTEXT context,
312
- __in_opt LPCWSTR szSubKey,
313
- __inout HKEY* key)
356
+ __in_opt LPCWSTR wzSubKey,
357
+ __inout HKEY* phKey
358
+ )
359
{
315
- Assert(key && wzBundleId);
316
- AssertSz(NULL == *key, "*key should be null");
360
+ Assert(phKey && wzBundleId);
361
+ AssertSz(NULL == *phKey, "*key should be null");
362
363
HRESULT hr = S_OK;
364
HKEY hkRoot = BUNDLE_INSTALL_CONTEXT_USER == context ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
365
LPWSTR sczKeypath = NULL;
366
322
- if (szSubKey)
367
+ if (wzSubKey)
368
{
324
- hr = StrAllocFormatted(&sczKeypath, L"%ls\\%ls\\%ls", BUNDLE_REGISTRATION_REGISTRY_UNINSTALL_KEY, wzBundleId, szSubKey);
369
+ hr = StrAllocFormatted(&sczKeypath, L"%ls\\%ls\\%ls", BUNDLE_REGISTRATION_REGISTRY_UNINSTALL_KEY, wzBundleId, wzSubKey);
370
}
371
else
372
{
@@ -329,7 +374,7 @@ HRESULT OpenBundleKey(
374
}
375
ButilExitOnFailure(hr, "Failed to allocate bundle uninstall key path.");
376
332
- hr = RegOpen(hkRoot, sczKeypath, KEY_READ, key);
377
+ hr = RegOpen(hkRoot, sczKeypath, KEY_READ, phKey);
378
ButilExitOnFailure(hr, "Failed to open bundle uninstall key path.");
379
380
LExit:
@@ -337,4 +382,3 @@ LExit:
382
383
return hr;
384
}
340
-
src/libs/dutil/WixToolset.DUtil/inc/butil.h
+20
-2
@@ -6,7 +6,7 @@
6
extern "C" {
7
#endif
8
9
-typedef enum BUNDLE_INSTALL_CONTEXT
9
+typedef enum _BUNDLE_INSTALL_CONTEXT
10
{
11
BUNDLE_INSTALL_CONTEXT_MACHINE,
12
BUNDLE_INSTALL_CONTEXT_USER,
@@ -55,11 +55,29 @@ HRESULT DAPI BundleEnumRelatedBundle(
55
__out_ecount(MAX_GUID_CHARS+1) LPWSTR lpBundleIdBuf
56
);
57
58
+/********************************************************************
59
+BundleGetBundleVariable - Queries the bundle installation metadata for a given variable,
60
+ the caller is expected to free the memory returned vis psczValue
61
+
62
+RETURNS:
63
+ S_OK
64
+ Success, if the variable had a value, it's returned in psczValue
65
+ E_INVALIDARG
66
+ An invalid parameter was passed to the function.
67
+ HRESULT_FROM_WIN32(ERROR_UNKNOWN_PRODUCT)
68
+ The bundle is not installed
69
+ HRESULT_FROM_WIN32(ERROR_UNKNOWN_PROPERTY)
70
+ The variable is unrecognized
71
+ E_NOTIMPL:
72
+ Tried to read a bundle variable for a type which has not been implemented
73
+
74
+ All other returns are unexpected returns from other dutil methods.
75
+********************************************************************/
76
HRESULT DAPI BundleGetBundleVariable(
77
__in_z LPCWSTR wzBundleId,
78
__in_z LPCWSTR wzVariable,
79
__deref_out_z LPWSTR* psczValue
62
-);
80
+ );
81
82
83
#ifdef __cplusplus
src/libs/dutil/WixToolset.DUtil/inc/regutil.h
+154
-7
@@ -99,9 +99,23 @@ typedef LSTATUS (APIENTRY *PFN_REGDELETEVALUEW)(
99
__in_opt LPCWSTR lpValueName
100
);
101
102
+/********************************************************************
103
+ RegInitialize - initializes regutil
104
+
105
+*********************************************************************/
106
HRESULT DAPI RegInitialize();
107
+
108
+/********************************************************************
109
+ RegUninitialize - uninitializes regutil
110
+
111
+*********************************************************************/
112
void DAPI RegUninitialize();
113
114
+/********************************************************************
115
+ RegFunctionOverride - overrides the registry functions. Typically used
116
+ for unit testing.
117
+
118
+*********************************************************************/
119
void DAPI RegFunctionOverride(
120
__in_opt PFN_REGCREATEKEYEXW pfnRegCreateKeyExW,
121
__in_opt PFN_REGOPENKEYEXW pfnRegOpenKeyExW,
@@ -113,12 +127,22 @@ void DAPI RegFunctionOverride(
127
__in_opt PFN_REGSETVALUEEXW pfnRegSetValueExW,
128
__in_opt PFN_REGDELETEVALUEW pfnRegDeleteValueW
129
);
130
+
131
+/********************************************************************
132
+ RegCreate - creates a registry key.
133
+
134
+*********************************************************************/
135
HRESULT DAPI RegCreate(
136
__in HKEY hkRoot,
137
__in_z LPCWSTR wzSubKey,
138
__in DWORD dwAccess,
139
__out HKEY* phk
140
);
141
+
142
+/********************************************************************
143
+ RegCreateEx - creates a registry key with extra options.
144
+
145
+*********************************************************************/
146
HRESULT DAPI RegCreateEx(
147
__in HKEY hkRoot,
148
__in_z LPCWSTR wzSubKey,
@@ -128,112 +152,229 @@ HRESULT DAPI RegCreateEx(
152
__out HKEY* phk,
153
__out_opt BOOL* pfCreated
154
);
155
+
156
+/********************************************************************
157
+ RegOpen - opens a registry key.
158
+
159
+*********************************************************************/
160
HRESULT DAPI RegOpen(
161
__in HKEY hkRoot,
162
__in_z LPCWSTR wzSubKey,
163
__in DWORD dwAccess,
164
__out HKEY* phk
165
);
166
+
167
+/********************************************************************
168
+ RegDelete - deletes a registry key (and optionally it's whole tree).
169
+
170
+*********************************************************************/
171
HRESULT DAPI RegDelete(
172
__in HKEY hkRoot,
173
__in_z LPCWSTR wzSubKey,
174
__in REG_KEY_BITNESS kbKeyBitness,
175
__in BOOL fDeleteTree
176
);
177
+
178
+/********************************************************************
179
+ RegKeyEnum - enumerates child registry keys.
180
+
181
+*********************************************************************/
182
HRESULT DAPI RegKeyEnum(
183
__in HKEY hk,
184
__in DWORD dwIndex,
185
__deref_out_z LPWSTR* psczKey
186
);
187
+
188
+/********************************************************************
189
+ RegValueEnum - enumerates registry values.
190
+
191
+*********************************************************************/
192
HRESULT DAPI RegValueEnum(
193
__in HKEY hk,
194
__in DWORD dwIndex,
195
__deref_out_z LPWSTR* psczName,
196
__out_opt DWORD *pdwType
197
);
198
+
199
+/********************************************************************
200
+ RegGetType - reads a registry key value type.
201
+ *********************************************************************/
202
HRESULT DAPI RegGetType(
203
__in HKEY hk,
204
__in_z_opt LPCWSTR wzName,
205
__out DWORD *pdwType
206
);
207
+
208
+/********************************************************************
209
+ RegReadBinary - reads a registry key binary value.
210
+ NOTE: caller is responsible for freeing *ppbBuffer
211
+*********************************************************************/
212
HRESULT DAPI RegReadBinary(
213
__in HKEY hk,
214
__in_z_opt LPCWSTR wzName,
215
__deref_out_bcount_opt(*pcbBuffer) BYTE** ppbBuffer,
216
__out SIZE_T *pcbBuffer
217
);
218
+
219
+/********************************************************************
220
+ RegReadString - reads a registry key value as a string.
221
+
222
+*********************************************************************/
223
HRESULT DAPI RegReadString(
224
__in HKEY hk,
225
__in_z_opt LPCWSTR wzName,
226
__deref_out_z LPWSTR* psczValue
227
);
228
+
229
+/********************************************************************
230
+ RegReadStringArray - reads a registry key value REG_MULTI_SZ value as a string array.
231
+
232
+*********************************************************************/
233
HRESULT DAPI RegReadStringArray(
234
__in HKEY hk,
235
__in_z_opt LPCWSTR wzName,
236
__deref_out_ecount_opt(*pcStrings) LPWSTR** prgsczStrings,
237
__out DWORD *pcStrings
238
);
239
+
240
+/********************************************************************
241
+ RegReadVersion - reads a registry key value as a version.
242
+
243
+*********************************************************************/
244
HRESULT DAPI RegReadVersion(
245
__in HKEY hk,
246
__in_z_opt LPCWSTR wzName,
247
__out DWORD64* pdw64Version
248
);
249
+
250
+/********************************************************************
251
+ RegReadNone - reads a NONE registry key value.
252
+
253
+*********************************************************************/
254
HRESULT DAPI RegReadNone(
255
__in HKEY hk,
256
__in_z_opt LPCWSTR wzName
184
-);
257
+ );
258
+
259
+/********************************************************************
260
+ RegReadNumber - reads a DWORD registry key value as a number.
261
+
262
+*********************************************************************/
263
HRESULT DAPI RegReadNumber(
264
__in HKEY hk,
265
__in_z_opt LPCWSTR wzName,
266
__out DWORD* pdwValue
267
);
268
+
269
+/********************************************************************
270
+ RegReadQword - reads a QWORD registry key value as a number.
271
+
272
+*********************************************************************/
273
HRESULT DAPI RegReadQword(
274
__in HKEY hk,
275
__in_z_opt LPCWSTR wzName,
276
__out DWORD64* pqwValue
277
);
278
+
279
+/********************************************************************
280
+ RegWriteBinary - writes a registry key value as a binary.
281
+
282
+*********************************************************************/
283
HRESULT DAPI RegWriteBinary(
284
__in HKEY hk,
285
__in_z_opt LPCWSTR wzName,
286
__in_bcount(cbBuffer) const BYTE *pbBuffer,
287
__in DWORD cbBuffer
288
);
201
-HRESULT DAPI RegWriteString(
289
+
290
+/********************************************************************
291
+RegWriteExpandString - writes a registry key value as an expand string.
292
+
293
+Note: if wzValue is NULL the value will be removed.
294
+*********************************************************************/
295
+HRESULT DAPI RegWriteExpandString(
296
__in HKEY hk,
297
__in_z_opt LPCWSTR wzName,
298
__in_z_opt LPCWSTR wzValue
299
);
206
-HRESULT DAPI RegWriteStringArray(
300
+
301
+/********************************************************************
302
+ RegWriteString - writes a registry key value as a string.
303
+
304
+ Note: if wzValue is NULL the value will be removed.
305
+*********************************************************************/
306
+HRESULT DAPI RegWriteString(
307
__in HKEY hk,
308
__in_z_opt LPCWSTR wzName,
209
- __in_ecount(cStrings) LPWSTR *rgwzStrings,
210
- __in DWORD cStrings
309
+ __in_z_opt LPCWSTR wzValue
310
);
212
-HRESULT DAPI RegWriteStringFormatted(
311
+
312
+/********************************************************************
313
+ RegWriteStringFormatted - writes a registry key value as a formatted string.
314
+
315
+*********************************************************************/
316
+HRESULT DAPIV RegWriteStringFormatted(
317
__in HKEY hk,
318
__in_z_opt LPCWSTR wzName,
319
__in __format_string LPCWSTR szFormat,
320
...
321
);
322
+
323
+/********************************************************************
324
+ RegWriteStringArray - writes an array of strings as a REG_MULTI_SZ value
325
+
326
+*********************************************************************/
327
+HRESULT DAPI RegWriteStringArray(
328
+ __in HKEY hk,
329
+ __in_z_opt LPCWSTR wzName,
330
+ __in_ecount(cStrings) LPWSTR* rgwzStrings,
331
+ __in DWORD cStrings
332
+ );
333
+
334
+/********************************************************************
335
+ RegWriteNone - writes a registry key value as none.
336
+
337
+*********************************************************************/
338
HRESULT DAPI RegWriteNone(
339
__in HKEY hk,
340
__in_z_opt LPCWSTR wzName
221
-);
341
+ );
342
+
343
+/********************************************************************
344
+ RegWriteNumber - writes a registry key value as a number.
345
+
346
+*********************************************************************/
347
HRESULT DAPI RegWriteNumber(
348
__in HKEY hk,
349
__in_z_opt LPCWSTR wzName,
350
__in DWORD dwValue
351
);
352
+
353
+/********************************************************************
354
+ RegWriteQword - writes a registry key value as a Qword.
355
+
356
+*********************************************************************/
357
HRESULT DAPI RegWriteQword(
358
__in HKEY hk,
359
__in_z_opt LPCWSTR wzName,
360
__in DWORD64 qwValue
361
);
362
+
363
+/********************************************************************
364
+ RegQueryKey - queries the key for the number of subkeys and values.
365
+
366
+*********************************************************************/
367
HRESULT DAPI RegQueryKey(
368
__in HKEY hk,
369
__out_opt DWORD* pcSubKeys,
370
__out_opt DWORD* pcValues
371
);
372
+
373
+/********************************************************************
374
+RegKeyReadNumber - reads a DWORD registry key value as a number from
375
+a specified subkey.
376
+
377
+*********************************************************************/
378
HRESULT DAPI RegKeyReadNumber(
379
__in HKEY hk,
380
__in_z LPCWSTR wzSubKey,
@@ -241,6 +382,12 @@ HRESULT DAPI RegKeyReadNumber(
382
__in BOOL f64Bit,
383
__out DWORD* pdwValue
384
);
385
+
386
+/********************************************************************
387
+RegValueExists - determines whether a named value exists in a
388
+specified subkey.
389
+
390
+*********************************************************************/
391
BOOL DAPI RegValueExists(
392
__in HKEY hk,
393
__in_z LPCWSTR wzSubKey,
src/libs/dutil/WixToolset.DUtil/regutil.cpp
+34
-146
@@ -37,14 +37,9 @@ static HRESULT WriteStringToRegistry(
37
__in_z_opt LPCWSTR wzName,
38
__in_z_opt LPCWSTR wzValue,
39
__in DWORD dwType
40
-);
40
+ );
41
42
-/********************************************************************
43
- RegInitialize - initializes regutil
44
-
45
-*********************************************************************/
46
-extern "C" HRESULT DAPI RegInitialize(
47
- )
42
+DAPI_(HRESULT) RegInitialize()
43
{
44
HRESULT hr = S_OK;
45
@@ -66,12 +61,7 @@ LExit:
61
}
62
63
69
-/********************************************************************
70
- RegUninitialize - uninitializes regutil
71
-
72
-*********************************************************************/
73
-extern "C" void DAPI RegUninitialize(
74
- )
64
+DAPI_(void) RegUninitialize()
65
{
66
if (vhAdvApi32Dll)
67
{
@@ -85,12 +75,7 @@ extern "C" void DAPI RegUninitialize(
75
}
76
77
88
-/********************************************************************
89
- RegFunctionOverride - overrides the registry functions. Typically used
90
- for unit testing.
91
-
92
-*********************************************************************/
93
-extern "C" void DAPI RegFunctionOverride(
78
+DAPI_(void) RegFunctionOverride(
79
__in_opt PFN_REGCREATEKEYEXW pfnRegCreateKeyExW,
80
__in_opt PFN_REGOPENKEYEXW pfnRegOpenKeyExW,
81
__in_opt PFN_REGDELETEKEYEXW pfnRegDeleteKeyExW,
@@ -114,11 +99,7 @@ extern "C" void DAPI RegFunctionOverride(
99
}
100
101
117
-/********************************************************************
118
- RegCreate - creates a registry key.
119
-
120
-*********************************************************************/
121
-extern "C" HRESULT DAPI RegCreate(
102
+DAPI_(HRESULT) RegCreate(
103
__in HKEY hkRoot,
104
__in_z LPCWSTR wzSubKey,
105
__in DWORD dwAccess,
@@ -136,11 +117,7 @@ LExit:
117
}
118
119
139
-/********************************************************************
140
- RegCreate - creates a registry key with extra options.
141
-
142
-*********************************************************************/
143
-HRESULT DAPI RegCreateEx(
120
+DAPI_(HRESULT) RegCreateEx(
121
__in HKEY hkRoot,
122
__in_z LPCWSTR wzSubKey,
123
__in DWORD dwAccess,
@@ -167,11 +144,7 @@ LExit:
144
}
145
146
170
-/********************************************************************
171
- RegOpen - opens a registry key.
172
-
173
-*********************************************************************/
174
-extern "C" HRESULT DAPI RegOpen(
147
+DAPI_(HRESULT) RegOpen(
148
__in HKEY hkRoot,
149
__in_z LPCWSTR wzSubKey,
150
__in DWORD dwAccess,
@@ -193,11 +166,7 @@ LExit:
166
}
167
168
196
-/********************************************************************
197
- RegDelete - deletes a registry key (and optionally it's whole tree).
198
-
199
-*********************************************************************/
200
-extern "C" HRESULT DAPI RegDelete(
169
+DAPI_(HRESULT) RegDelete(
170
__in HKEY hkRoot,
171
__in_z LPCWSTR wzSubKey,
172
__in REG_KEY_BITNESS kbKeyBitness,
@@ -282,11 +251,7 @@ LExit:
251
}
252
253
285
-/********************************************************************
286
- RegKeyEnum - enumerates child registry keys.
287
-
288
-*********************************************************************/
289
-extern "C" HRESULT DAPI RegKeyEnum(
254
+DAPI_(HRESULT) RegKeyEnum(
255
__in HKEY hk,
256
__in DWORD dwIndex,
257
__deref_out_z LPWSTR* psczKey
@@ -342,11 +307,7 @@ LExit:
307
}
308
309
345
-/********************************************************************
346
- RegValueEnum - enumerates registry values.
347
-
348
-*********************************************************************/
349
-HRESULT DAPI RegValueEnum(
310
+DAPI_(HRESULT) RegValueEnum(
311
__in HKEY hk,
312
__in DWORD dwIndex,
313
__deref_out_z LPWSTR* psczName,
@@ -377,10 +338,7 @@ LExit:
338
return hr;
339
}
340
380
-/********************************************************************
381
- RegGetType - reads a registry key value type.
382
- *********************************************************************/
383
-HRESULT DAPI RegGetType(
341
+DAPI_(HRESULT) RegGetType(
342
__in HKEY hk,
343
__in_z_opt LPCWSTR wzName,
344
__out DWORD *pdwType
@@ -400,11 +358,7 @@ LExit:
358
return hr;
359
}
360
403
-/********************************************************************
404
- RegReadBinary - reads a registry key binary value.
405
- NOTE: caller is responsible for freeing *ppbBuffer
406
-*********************************************************************/
407
-HRESULT DAPI RegReadBinary(
361
+DAPI_(HRESULT) RegReadBinary(
362
__in HKEY hk,
363
__in_z_opt LPCWSTR wzName,
364
__deref_out_bcount_opt(*pcbBuffer) BYTE** ppbBuffer,
@@ -453,11 +407,7 @@ LExit:
407
}
408
409
456
-/********************************************************************
457
- RegReadString - reads a registry key value as a string.
458
-
459
-*********************************************************************/
460
-extern "C" HRESULT DAPI RegReadString(
410
+DAPI_(HRESULT) RegReadString(
411
__in HKEY hk,
412
__in_z_opt LPCWSTR wzName,
413
__deref_out_z LPWSTR* psczValue
@@ -530,11 +480,7 @@ LExit:
480
}
481
482
533
-/********************************************************************
534
- RegReadStringArray - reads a registry key value REG_MULTI_SZ value as a string array.
535
-
536
-*********************************************************************/
537
-HRESULT DAPI RegReadStringArray(
483
+DAPI_(HRESULT) RegReadStringArray(
484
__in HKEY hk,
485
__in_z_opt LPCWSTR wzName,
486
__deref_out_ecount_opt(*pcStrings) LPWSTR** prgsczStrings,
@@ -626,11 +572,7 @@ LExit:
572
}
573
574
629
-/********************************************************************
630
- RegReadVersion - reads a registry key value as a version.
631
-
632
-*********************************************************************/
633
-extern "C" HRESULT DAPI RegReadVersion(
575
+DAPI_(HRESULT) RegReadVersion(
576
__in HKEY hk,
577
__in_z_opt LPCWSTR wzName,
578
__out DWORD64* pdw64Version
@@ -672,13 +614,10 @@ LExit:
614
return hr;
615
}
616
675
-/********************************************************************
676
- RegReadNone - reads a NONE registry key value.
677
-
678
-*********************************************************************/
679
-extern "C" HRESULT DAPI RegReadNone(
617
+DAPI_(HRESULT) RegReadNone(
618
__in HKEY hk,
681
- __in_z_opt LPCWSTR wzName)
619
+ __in_z_opt LPCWSTR wzName
620
+ )
621
{
622
HRESULT hr = S_OK;
623
DWORD er = ERROR_SUCCESS;
@@ -694,18 +633,14 @@ extern "C" HRESULT DAPI RegReadNone(
633
if (REG_NONE != dwType)
634
{
635
hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATATYPE);
697
- RegExitOnRootFailure(hr, "Error reading version registry value due to unexpected data type: %u", dwType);
636
+ RegExitOnRootFailure(hr, "Error reading none registry value due to unexpected data type: %u", dwType);
637
}
638
639
LExit:
640
return hr;
641
}
642
704
-/********************************************************************
705
- RegReadNumber - reads a DWORD registry key value as a number.
706
-
707
-*********************************************************************/
708
-extern "C" HRESULT DAPI RegReadNumber(
643
+DAPI_(HRESULT) RegReadNumber(
644
__in HKEY hk,
645
__in_z_opt LPCWSTR wzName,
646
__out DWORD* pdwValue
@@ -734,11 +669,7 @@ LExit:
669
}
670
671
737
-/********************************************************************
738
- RegReadQword - reads a QWORD registry key value as a number.
739
-
740
-*********************************************************************/
741
-extern "C" HRESULT DAPI RegReadQword(
672
+DAPI_(HRESULT) RegReadQword(
673
__in HKEY hk,
674
__in_z_opt LPCWSTR wzName,
675
__out DWORD64* pqwValue
@@ -767,11 +698,7 @@ LExit:
698
}
699
700
770
-/********************************************************************
771
- RegWriteBinary - writes a registry key value as a binary.
772
-
773
-*********************************************************************/
774
-HRESULT DAPI RegWriteBinary(
701
+DAPI_(HRESULT) RegWriteBinary(
702
__in HKEY hk,
703
__in_z_opt LPCWSTR wzName,
704
__in_bcount(cbBuffer) const BYTE *pbBuffer,
@@ -789,27 +716,17 @@ LExit:
716
}
717
718
792
-/********************************************************************
793
-RegWriteExpandString - writes a registry key value as an expand string.
794
-
795
-Note: if wzValue is NULL the value will be removed.
796
-*********************************************************************/
797
-extern "C" HRESULT DAPI RegWriteExpandString(
719
+DAPI_(HRESULT) RegWriteExpandString(
720
__in HKEY hk,
721
__in_z_opt LPCWSTR wzName,
722
__in_z_opt LPCWSTR wzValue
801
-)
723
+ )
724
{
725
return WriteStringToRegistry(hk, wzName, wzValue, REG_EXPAND_SZ);
726
}
727
728
807
-/********************************************************************
808
- RegWriteString - writes a registry key value as a string.
809
-
810
- Note: if wzValue is NULL the value will be removed.
811
-*********************************************************************/
812
-extern "C" HRESULT DAPI RegWriteString(
729
+DAPI_(HRESULT) RegWriteString(
730
__in HKEY hk,
731
__in_z_opt LPCWSTR wzName,
732
__in_z_opt LPCWSTR wzValue
@@ -819,11 +736,7 @@ extern "C" HRESULT DAPI RegWriteString(
736
}
737
738
822
-/********************************************************************
823
- RegWriteStringFormatted - writes a registry key value as a formatted string.
824
-
825
-*********************************************************************/
826
-extern "C" HRESULT DAPI RegWriteStringFormatted(
739
+DAPIV_(HRESULT) RegWriteStringFormatted(
740
__in HKEY hk,
741
__in_z_opt LPCWSTR wzName,
742
__in __format_string LPCWSTR szFormat,
@@ -848,11 +761,7 @@ LExit:
761
}
762
763
851
-/********************************************************************
852
- RegWriteStringArray - writes an array of strings as a REG_MULTI_SZ value
853
-
854
-*********************************************************************/
855
-HRESULT DAPI RegWriteStringArray(
764
+DAPI_(HRESULT) RegWriteStringArray(
765
__in HKEY hk,
766
__in_z_opt LPCWSTR wzName,
767
__in_ecount(cValues) LPWSTR *rgwzValues,
@@ -913,14 +822,10 @@ LExit:
822
return hr;
823
}
824
916
-/********************************************************************
917
- RegWriteNone - writes a registry key value as none.
918
-
919
-*********************************************************************/
920
-extern "C" HRESULT DAPI RegWriteNone(
825
+DAPI_(HRESULT) RegWriteNone(
826
__in HKEY hk,
827
__in_z_opt LPCWSTR wzName
923
-)
828
+ )
829
{
830
HRESULT hr = S_OK;
831
DWORD er = ERROR_SUCCESS;
@@ -932,11 +837,7 @@ LExit:
837
return hr;
838
}
839
935
-/********************************************************************
936
- RegWriteNumber - writes a registry key value as a number.
937
-
938
-*********************************************************************/
939
-extern "C" HRESULT DAPI RegWriteNumber(
840
+DAPI_(HRESULT) RegWriteNumber(
841
__in HKEY hk,
842
__in_z_opt LPCWSTR wzName,
843
__in DWORD dwValue
@@ -952,11 +853,7 @@ LExit:
853
return hr;
854
}
855
955
-/********************************************************************
956
- RegWriteQword - writes a registry key value as a Qword.
957
-
958
-*********************************************************************/
959
-extern "C" HRESULT DAPI RegWriteQword(
856
+DAPI_(HRESULT) RegWriteQword(
857
__in HKEY hk,
858
__in_z_opt LPCWSTR wzName,
859
__in DWORD64 qwValue
@@ -972,11 +869,7 @@ LExit:
869
return hr;
870
}
871
975
-/********************************************************************
976
- RegQueryKey - queries the key for the number of subkeys and values.
977
-
978
-*********************************************************************/
979
-extern "C" HRESULT DAPI RegQueryKey(
872
+DAPI_(HRESULT) RegQueryKey(
873
__in HKEY hk,
874
__out_opt DWORD* pcSubKeys,
875
__out_opt DWORD* pcValues
@@ -992,12 +885,7 @@ LExit:
885
return hr;
886
}
887
995
-/********************************************************************
996
-RegKeyReadNumber - reads a DWORD registry key value as a number from
997
-a specified subkey.
998
-
999
-*********************************************************************/
1000
-extern "C" HRESULT DAPI RegKeyReadNumber(
888
+DAPI_(HRESULT) RegKeyReadNumber(
889
__in HKEY hk,
890
__in_z LPCWSTR wzSubKey,
891
__in_z_opt LPCWSTR wzName,
@@ -1025,7 +913,7 @@ RegValueExists - determines whether a named value exists in a
913
specified subkey.
914
915
*********************************************************************/
1028
-extern "C" BOOL DAPI RegValueExists(
916
+DAPI_(BOOL) RegValueExists(
917
__in HKEY hk,
918
__in_z LPCWSTR wzSubKey,
919
__in_z_opt LPCWSTR wzName,