|
6 | 6 | #include <windows.h> |
7 | 7 | #include <winreg.h> |
8 | 8 |
|
9 | | -bool createWerRegistryKey(const std::string& dllPath) { |
10 | | - const char* registryPath = "SOFTWARE\\Microsoft\\Windows\\Windows Error Reporting\\RuntimeExceptionHandlerModules"; |
11 | | - HKEY hKey; |
12 | | - |
13 | | - // Open/create the registry key |
14 | | - LONG result = RegCreateKeyExA( |
15 | | - HKEY_CURRENT_USER, |
16 | | - registryPath, |
17 | | - 0, |
18 | | - NULL, |
19 | | - REG_OPTION_NON_VOLATILE, |
20 | | - KEY_WRITE, |
21 | | - NULL, |
22 | | - &hKey, |
23 | | - NULL |
24 | | - ); |
| 9 | +BOOL DoesRegistryValueExist(HKEY hRootKey, LPCWSTR keyPath, LPCWSTR valueName) |
| 10 | +{ |
| 11 | + HKEY hKey = NULL; |
| 12 | + LSTATUS result = RegOpenKeyExW(hRootKey, keyPath, 0, KEY_READ, &hKey); |
25 | 13 |
|
26 | 14 | if (result != ERROR_SUCCESS) { |
27 | | - std::cerr << "Failed to open/create WER registry key. Error: " << result << std::endl; |
28 | | - return false; |
| 15 | + return FALSE; // Key doesn't exist |
29 | 16 | } |
30 | 17 |
|
31 | | - // Set the DLL path as a DWORD value with data 0x0 |
32 | | - DWORD value = 0x0; |
33 | | - result = RegSetValueExA( |
34 | | - hKey, |
35 | | - dllPath.c_str(), // Value name is the full DLL path |
36 | | - 0, |
37 | | - REG_DWORD, |
38 | | - reinterpret_cast<const BYTE*>(&value), |
39 | | - sizeof(DWORD) |
40 | | - ); |
41 | | - |
| 18 | + // Check if the specific value exists |
| 19 | + result = RegQueryValueExW(hKey, valueName, NULL, NULL, NULL, NULL); |
42 | 20 | RegCloseKey(hKey); |
43 | 21 |
|
44 | | - if (result != ERROR_SUCCESS) { |
45 | | - std::cerr << "Failed to set WER registry value. Error: " << result << std::endl; |
46 | | - return false; |
47 | | - } |
| 22 | + return (result == ERROR_SUCCESS); |
| 23 | +} |
| 24 | + |
| 25 | +// Check for RuntimeExceptionHelperModules key |
| 26 | +BOOL CheckRuntimeExceptionHelper(const std::string& dllPath) |
| 27 | +{ |
| 28 | + const LPCWSTR keyPath = L"SOFTWARE\\Microsoft\\Windows\\Windows Error Reporting\\RuntimeExceptionHelperModules"; |
| 29 | + |
| 30 | + // Create the value name we're looking for |
| 31 | + std::wstring wideDllPath(dllPath.begin(), dllPath.end()); |
| 32 | + WCHAR valueName[2048]; |
| 33 | + swprintf_s(valueName, 2048, wideDllPath.c_str()); |
48 | 34 |
|
49 | | - std::cout << "Successfully created WER registry key for: " << dllPath << std::endl; |
50 | | - return true; |
| 35 | + // Check if our specific value exists |
| 36 | + BOOL exists = DoesRegistryValueExist(HKEY_LOCAL_MACHINE, keyPath, valueName); |
| 37 | + |
| 38 | + return exists; |
51 | 39 | } |
52 | 40 |
|
| 41 | + |
53 | 42 | void setupWerIntegration(crashpad::CrashpadClient& client, const std::string& exeDir) { |
54 | | - std::string werDllPath = exeDir + "\\crashpad_wer.dll"; |
55 | | - std::cout << "Looking for Crashpad WER DLL at: " << werDllPath << std::endl; |
56 | | - |
| 43 | + std::string werDllPath = exeDir + "\\crashpad_wer.dll"; |
57 | 44 | if (!std::filesystem::exists(werDllPath)) { |
58 | | - std::cout << "Crashpad WER DLL not found - continuing without WER integration" << std::endl; |
| 45 | + std::cout << "Crashpad WER DLL not found at: " << werDllPath << " - continuing without WER integration" << std::endl; |
59 | 46 | return; |
60 | 47 | } |
61 | | - |
62 | | - std::cout << "Crashpad WER DLL found, setting up WER integration..." << std::endl; |
63 | | - |
64 | | - // Create registry key for WER integration |
65 | | - bool registryCreated = createWerRegistryKey(werDllPath); |
| 48 | + |
| 49 | + // Check registry key for WER integration |
| 50 | + bool registryExists = CheckRuntimeExceptionHelper(werDllPath); |
| 51 | + if (!registryExists) { |
| 52 | + std::cout << "Crashpad WER registry key: " << werDllPath << " not found" << std::endl; |
| 53 | + std::cout << "Create this registry value in HKLM\\SOFTWARE\\Microsoft\\Windows\\Windows Error Reporting\\RuntimeExceptionHelperModules" << std::endl; |
| 54 | + std::cout << "Continuing without WER integration" << std::endl; |
| 55 | + return; |
| 56 | + } |
66 | 57 |
|
67 | 58 | // Register WER module with Crashpad |
68 | 59 | std::wstring werDllPathW(werDllPath.begin(), werDllPath.end()); |
69 | 60 | bool moduleRegistered = client.RegisterWerModule(werDllPathW); |
70 | 61 |
|
71 | 62 | // Report results |
72 | | - if (registryCreated && moduleRegistered) { |
73 | | - std::cout << "Successfully set up WER integration: " << werDllPath << std::endl; |
| 63 | + if (!moduleRegistered) { |
| 64 | + std::cerr << "Warning: Failed to register WER module with Crashpad - continuing without WER integration" << std::endl; |
74 | 65 | return; |
75 | 66 | } |
76 | 67 |
|
77 | | - // Handle partial or complete failure |
78 | | - if (!registryCreated) { |
79 | | - std::cerr << "Warning: Failed to create WER registry key" << std::endl; |
80 | | - } |
81 | | - if (!moduleRegistered) { |
82 | | - std::cerr << "Warning: Failed to register WER module with Crashpad" << std::endl; |
83 | | - } |
84 | | - std::cerr << "WER integration may not work properly" << std::endl; |
| 68 | + std::cout << "Successfully set up WER integration: " << werDllPath << std::endl; |
85 | 69 | } |
86 | 70 |
|
87 | 71 | #endif // _WIN32 |
0 commit comments