diff options
author | Bernard Normier <bernard@zeroc.com> | 2007-02-09 19:33:18 +0000 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2007-02-09 19:33:18 +0000 |
commit | 94c2a1b0e29fb44fa2545ff9b1533798d5ef9e3b (patch) | |
tree | c83c4d7af0a67cc05a2db0ae1ad53e3feeb58d9f /cpp/src/Ice/EventLoggerI.cpp | |
parent | bug 1777: test/Ice/threads vs. JDK 1.4 (diff) | |
download | ice-94c2a1b0e29fb44fa2545ff9b1533798d5ef9e3b.tar.bz2 ice-94c2a1b0e29fb44fa2545ff9b1533798d5ef9e3b.tar.xz ice-94c2a1b0e29fb44fa2545ff9b1533798d5ef9e3b.zip |
Fixed bug #1803
Diffstat (limited to 'cpp/src/Ice/EventLoggerI.cpp')
-rwxr-xr-x | cpp/src/Ice/EventLoggerI.cpp | 102 |
1 files changed, 59 insertions, 43 deletions
diff --git a/cpp/src/Ice/EventLoggerI.cpp b/cpp/src/Ice/EventLoggerI.cpp index c626e62c83f..23e90e98c79 100755 --- a/cpp/src/Ice/EventLoggerI.cpp +++ b/cpp/src/Ice/EventLoggerI.cpp @@ -37,59 +37,75 @@ Ice::EventLoggerI::EventLoggerI(const string& appName) : } string key = "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\" + _appName; - // - // Create the key if it doesn't already exist. - // HKEY hKey; DWORD d; LONG err; - err = RegCreateKeyEx(HKEY_LOCAL_MACHINE, key.c_str(), 0, "REG_SZ", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0, - &hKey, &d); - if(err != ERROR_SUCCESS) - { - SyscallException ex(__FILE__, __LINE__); - ex.error = err; - throw ex; - } // - // Get the filename of this DLL. + // Try to create the key or gain full key access and set the values // - char path[_MAX_PATH]; - assert(_module != NULL); - if(!GetModuleFileName(_module, path, _MAX_PATH)) - { - RegCloseKey(hKey); - SyscallException ex(__FILE__, __LINE__); - ex.error = GetLastError(); - throw ex; - } - - // - // The event resources are bundled into this DLL, therefore the - // "EventMessageFile" key should contain the path to this DLL. - // - err = RegSetValueEx(hKey, "EventMessageFile", 0, REG_EXPAND_SZ, - (unsigned char*)path, static_cast<DWORD>(strlen(path) + 1)); + + bool setValues = true; + err = RegCreateKeyEx(HKEY_LOCAL_MACHINE, key.c_str(), 0, "REG_SZ", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0, + &hKey, &d); if(err != ERROR_SUCCESS) { - RegCloseKey(hKey); - SyscallException ex(__FILE__, __LINE__); - ex.error = err; - throw ex; + // + // If the key exist and I can read it, that's good enough ... we hope the values are set properly. + // + if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, key.c_str(), 0, KEY_READ, &hKey) == ERROR_SUCCESS) + { + setValues = false; + } + else + { + SyscallException ex(__FILE__, __LINE__); + ex.error = err; + throw ex; + } } - - // - // The "TypesSupported" key indicates the supported event types. - // - DWORD typesSupported = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE; - err = RegSetValueEx(hKey, "TypesSupported", 0, REG_DWORD, (unsigned char*)&typesSupported, sizeof(typesSupported)); - if(err != ERROR_SUCCESS) + + if(setValues) { - RegCloseKey(hKey); - SyscallException ex(__FILE__, __LINE__); - ex.error = err; - throw ex; + // + // Get the filename of this DLL. + // + char path[_MAX_PATH]; + assert(_module != NULL); + if(!GetModuleFileName(_module, path, _MAX_PATH)) + { + RegCloseKey(hKey); + SyscallException ex(__FILE__, __LINE__); + ex.error = GetLastError(); + throw ex; + } + + // + // The event resources are bundled into this DLL, therefore the + // "EventMessageFile" key should contain the path to this DLL. + // + err = RegSetValueEx(hKey, "EventMessageFile", 0, REG_EXPAND_SZ, + (unsigned char*)path, static_cast<DWORD>(strlen(path) + 1)); + if(err != ERROR_SUCCESS) + { + RegCloseKey(hKey); + SyscallException ex(__FILE__, __LINE__); + ex.error = err; + throw ex; + } + + // + // The "TypesSupported" key indicates the supported event types. + // + DWORD typesSupported = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE; + err = RegSetValueEx(hKey, "TypesSupported", 0, REG_DWORD, (unsigned char*)&typesSupported, sizeof(typesSupported)); + if(err != ERROR_SUCCESS) + { + RegCloseKey(hKey); + SyscallException ex(__FILE__, __LINE__); + ex.error = err; + throw ex; + } } RegCloseKey(hKey); |