[prev in list] [next in list] [prev in thread] [next in thread]
List: sptk-commits
Subject: r1042 - trunk/src/utils
From: alexey () mail ! total-knowledge ! com
Date: 2009-10-31 7:12:47
Message-ID: courier.000000004AEBE36F.00000199 () mail ! total-knowledge ! com
[Download RAW message or body]
Author: alexey
Date: 2009-10-31 00:12:47 -0700 (Sat, 31 Oct 2009)
New Revision: 1042
Added:
trunk/src/utils/CFileLogger.cpp
trunk/src/utils/CSysLogger.cpp
Removed:
trunk/src/utils/CFileLog.cpp
trunk/src/utils/CSysLog.cpp
Log:
Fixing race conditions ..
Deleted: trunk/src/utils/CFileLog.cpp
===================================================================
--- trunk/src/utils/CFileLog.cpp 2009-10-31 06:01:38 UTC (rev 1041)
+++ trunk/src/utils/CFileLog.cpp 2009-10-31 07:12:47 UTC (rev 1042)
@@ -1,79 +0,0 @@
-/***************************************************************************
- SIMPLY POWERFUL TOOLKIT (SPTK)
- CFileLog.cpp - description
- -------------------
- begin : Tue Jan 31 2006
- copyright : (C) 2001-2009 by Alexey Parshin. All rights reserved.
-
- This module creation was sponsored by Total Knowledge \
(http://www.total-knowledge.com).
- Author thanks the developers of CPPSERV project \
(http://www.total-knowledge.com/progs/cppserv)
- for defining the requirements for this class.
- ***************************************************************************/
-
-/***************************************************************************
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the <ORGANIZATION> nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- ***************************************************************************/
-
-#include <sptk4/CFileLog.h>
-
-using namespace std;
-using namespace sptk;
-
-void CFileLog::saveMessage(CDateTime date, const char* prefix, const char *message, \
const CLogPriority *priority) throw(CException)
-{
- if (m_options & CLO_ENABLE) {
- if (!m_fileStream.is_open()) {
- m_fileStream.open(m_fileName.c_str(), ofstream::out | ofstream::app);
- if (!m_fileStream.is_open())
- throw CException("Can't append or create log file '" + m_fileName + \
"'", __FILE__, __LINE__);
- }
-
- print(m_fileStream, date, prefix, message, priority);
- }
-
- if (m_options & CLO_STDOUT)
- print(cout, date, prefix, message, priority);
-
- if (m_fileStream.bad())
- throw CException("Can't write to log file '" + m_fileName + "'", __FILE__, \
__LINE__);
-}
-
-CFileLog::~CFileLog()
-{
- m_buffer.flush();
- if (m_fileStream.is_open())
- m_fileStream.close();
-}
-
-void CFileLog::reset() throw(CException)
-{
- if (m_fileStream.is_open())
- m_fileStream.close();
- if (m_fileName.empty())
- throw CException("File name isn't defined", __FILE__, __LINE__);
- m_fileStream.open(m_fileName.c_str(), ofstream::out | ofstream::trunc);
- if (!m_fileStream.is_open())
- throw CException("Can't open log file '" + m_fileName + "'", __FILE__, \
__LINE__);
-}
Added: trunk/src/utils/CFileLogger.cpp
===================================================================
--- trunk/src/utils/CFileLogger.cpp (rev 0)
+++ trunk/src/utils/CFileLogger.cpp 2009-10-31 07:12:47 UTC (rev 1042)
@@ -0,0 +1,78 @@
+/***************************************************************************
+ SIMPLY POWERFUL TOOLKIT (SPTK)
+ CFileLogger.cpp - description
+ -------------------
+ begin : Tue Jan 31 2006
+ copyright : (C) 2001-2009 by Alexey Parshin. All rights reserved.
+
+ This module creation was sponsored by Total Knowledge \
(http://www.total-knowledge.com). + Author thanks the developers of CPPSERV \
project (http://www.total-knowledge.com/progs/cppserv) + for defining the \
requirements for this class. + \
***************************************************************************/ +
+/***************************************************************************
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of the <ORGANIZATION> nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ ***************************************************************************/
+
+#include <sptk4/CFileLogger.h>
+
+using namespace std;
+using namespace sptk;
+
+void CFileLogger::saveMessage(CDateTime date, const char* prefix, const char \
*message, const CLogPriority *priority) throw(CException) +{
+ if (m_options & CLO_ENABLE) {
+ if (!m_fileStream.is_open()) {
+ m_fileStream.open(m_fileName.c_str(), ofstream::out | ofstream::app);
+ if (!m_fileStream.is_open())
+ throw CException("Can't append or create log file '" + m_fileName + \
"'", __FILE__, __LINE__); + }
+
+ print(m_fileStream, date, prefix, message, priority);
+ }
+
+ if (m_options & CLO_STDOUT)
+ print(cout, date, prefix, message, priority);
+
+ if (m_fileStream.bad())
+ throw CException("Can't write to log file '" + m_fileName + "'", __FILE__, \
__LINE__); +}
+
+CFileLogger::~CFileLogger()
+{
+ if (m_fileStream.is_open())
+ m_fileStream.close();
+}
+
+void CFileLogger::reset() throw(CException)
+{
+ if (m_fileStream.is_open())
+ m_fileStream.close();
+ if (m_fileName.empty())
+ throw CException("File name isn't defined", __FILE__, __LINE__);
+ m_fileStream.open(m_fileName.c_str(), ofstream::out | ofstream::trunc);
+ if (!m_fileStream.is_open())
+ throw CException("Can't open log file '" + m_fileName + "'", __FILE__, \
__LINE__); +}
Deleted: trunk/src/utils/CSysLog.cpp
===================================================================
--- trunk/src/utils/CSysLog.cpp 2009-10-31 06:01:38 UTC (rev 1041)
+++ trunk/src/utils/CSysLog.cpp 2009-10-31 07:12:47 UTC (rev 1042)
@@ -1,220 +0,0 @@
-/***************************************************************************
- SIMPLY POWERFUL TOOLKIT (SPTK)
- CSysLog.cpp - description
- -------------------
- begin : Tue Jan 31 2006
- copyright : (C) 2001-2009 by Alexey Parshin. All rights reserved.
-
- This module creation was sponsored by Total Knowledge \
(http://www.total-knowledge.com).
- Author thanks the developers of CPPSERV project \
(http://www.total-knowledge.com/progs/cppserv)
- for defining the requirements for this class.
- ***************************************************************************/
-
-/***************************************************************************
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the <ORGANIZATION> nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- ***************************************************************************/
-
-#include <sptk4/CSysLog.h>
-#include <sptk4/CGuard.h>
-#include <sptk4/string_ext.h>
-
-using namespace std;
-using namespace sptk;
-
-#ifndef _WIN32
-int CSysLog::m_objectCounter = 0;
-bool CSysLog::m_logOpened = false;
-#else
-#include <VC7/events.h>
-string CSysLog::m_moduleFileName;
-bool CSysLog::m_registrySet = false;
-#endif
-
-string CSysLog::m_programName;
-
-/* Unix facilities
- { "auth", LOG_AUTH },
- { "authpriv", LOG_AUTHPRIV },
- { "cron", LOG_CRON },
- { "daemon", LOG_DAEMON },
- { "ftp", LOG_FTP },
- { "kern", LOG_KERN },
- { "lpr", LOG_LPR },
- { "mail", LOG_MAIL },
- { "news", LOG_NEWS },
- { "syslog", LOG_SYSLOG },
- { "user", LOG_USER },
- { "uucp", LOG_UUCP },
- */
-
-CSysLog::CSysLog(uint32_t facilities) :
- m_facilities(facilities)
-{
-#ifndef _WIN32
- m_objectCounter++;
-#else
-
- m_logHandle = 0;
-#endif
-}
-
-void CSysLog::saveMessage(CDateTime date, const char* prefix, const char *message, \
const CLogPriority *priority) throw(CException)
-{
- GUARD(m_lock);
- if (m_options & CLO_ENABLE) {
-#ifndef _WIN32
- if (!m_logOpened) {
- openlog(m_programName.c_str(), LOG_NOWAIT, LOG_USER | LOG_INFO);
- m_logOpened = true;
- }
- const char* messagePrefix = "";
- if (prefix)
- messagePrefix = prefix;
- syslog(m_facilities | priority->id(), "%-7s %s%s", \
upperCase(priority->name()).c_str(), messagePrefix, message);
-#else
- if (!m_logHandle) {
- OSVERSIONINFO version;
- version.dwOSVersionInfoSize = sizeof(version);
- if (!GetVersionEx(&version))
- throw CException("Can't determine Windows version");
- if (version.dwPlatformId != VER_PLATFORM_WIN32_NT)
- throw CException("EventLog is only implemented on NT-based Windows");
- m_logHandle = RegisterEventSource(0,m_programName.c_str());
- }
- if (!m_logHandle)
- throw CException("Can't open Application Event Log");
-
- unsigned eventType;
- switch (priority->id()) {
- case LOG_EMERG:
- case LOG_ALERT:
- case LOG_CRIT:
- case LOG_ERR:
- eventType = EVENTLOG_ERROR_TYPE;
- break;
- case LOG_WARNING:
- eventType = EVENTLOG_WARNING_TYPE;
- break;
- default:
- eventType = EVENTLOG_INFORMATION_TYPE;
- break;
- }
-
- //const char *messageStrings[] = { message, NULL };
- LPCTSTR messageStrings[]= {TEXT(message)};
-
- if (!ReportEvent(
- m_logHandle, // handle returned by RegisterEventSource
- WORD(eventType), // event type to log
- 0, // event category
- SPTK_MESSAGE, // event identifier
- 0, // user security identifier (optional)
- 1, // number of strings to merge with message
- 0, // size of binary data, in bytes
- messageStrings, // array of strings to merge with message
- 0 // address of binary data
- )) {
- throw CException("Can't write an event to Application Event Log ");
- }
-#endif
- }
-
- if (m_options & CLO_STDOUT)
- print(cout, date, prefix, message, priority);
-}
-
-CSysLog::~CSysLog()
-{
-#ifndef _WIN32
- m_objectCounter--;
- if (m_logOpened && m_objectCounter < 1)
- closelog();
-#else
- if (m_logHandle)
- CloseEventLog(m_logHandle);
-#endif
-}
-
-void CSysLog::programName(string progName)
-{
- m_programName = progName;
-#ifndef _WIN32
- m_logOpened = false;
- closelog();
-#else
- char *buffer = new char[_MAX_PATH];
- GetModuleFileName(0,buffer,_MAX_PATH);
- m_moduleFileName = buffer;
-
- if (!m_registrySet) {
- string keyName = \
"SYSTEM\\ControlSet001\\Services\\EventLog\\Application\\"+progName;
-
- HKEY keyHandle;
- if (RegCreateKey(
- HKEY_LOCAL_MACHINE,
- \
("SYSTEM\\ControlSet001\\Services\\EventLog\\Application\\"+progName).c_str(),
- &keyHandle) != ERROR_SUCCESS)
- throw CException("Can't open registry (HKEY_LOCAL_MACHINE) for write");
-
- unsigned long len = _MAX_PATH;
- unsigned long vtype = REG_EXPAND_SZ;
- if (RegQueryValueEx(
- keyHandle, // handle to key to query
- "EventMessageFile",
- 0,
- &vtype,
- (BYTE *)buffer, // buffer for returned string
- &len // receives size of returned string
- ) != ERROR_SUCCESS)
- throw CException("Can't open registry (HKEY_LOCAL_MACHINE) for write");
-
- if (strcmp(buffer,m_moduleFileName.c_str()) != 0) {
-
- if (RegSetValueEx(
- keyHandle, // handle to key to set value for
- "EventMessageFile", // name of the value to set
- 0, // reserved
- REG_EXPAND_SZ, // flag for value type
- (CONST BYTE *)m_moduleFileName.c_str(), // address of \
value data
- DWORD(m_moduleFileName.length()+1) // size of value data
- ) != ERROR_SUCCESS)
- throw CException("Can't open registry (HKEY_LOCAL_MACHINE) for write");
-
- unsigned typesSupported = 7;
- if (RegSetValueEx(
- keyHandle, // handle to key to set value for
- "TypesSupported", // name of the value to set
- 0, // reserved
- REG_DWORD, // flag for value type
- (CONST BYTE *)&typesSupported, // address of value data
- sizeof(typesSupported) // size of value data
- ) != ERROR_SUCCESS)
- throw CException("Can't open registry (HKEY_LOCAL_MACHINE) for write");
- RegCloseKey(keyHandle);
- }
- m_registrySet = true;
- }
-#endif
-}
Added: trunk/src/utils/CSysLogger.cpp
===================================================================
--- trunk/src/utils/CSysLogger.cpp (rev 0)
+++ trunk/src/utils/CSysLogger.cpp 2009-10-31 07:12:47 UTC (rev 1042)
@@ -0,0 +1,219 @@
+/***************************************************************************
+ SIMPLY POWERFUL TOOLKIT (SPTK)
+ CSysLogger.cpp - description
+ -------------------
+ begin : Tue Jan 31 2006
+ copyright : (C) 2001-2009 by Alexey Parshin. All rights reserved.
+
+ This module creation was sponsored by Total Knowledge \
(http://www.total-knowledge.com). + Author thanks the developers of CPPSERV \
project (http://www.total-knowledge.com/progs/cppserv) + for defining the \
requirements for this class. + \
***************************************************************************/ +
+/***************************************************************************
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of the <ORGANIZATION> nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ ***************************************************************************/
+
+#include <sptk4/CSysLogger.h>
+#include <sptk4/CGuard.h>
+#include <sptk4/string_ext.h>
+
+using namespace std;
+using namespace sptk;
+
+#ifndef _WIN32
+int CSysLogger::m_objectCounter = 0;
+bool CSysLogger::m_logOpened = false;
+#else
+#include <VC7/events.h>
+string CSysLogger::m_moduleFileName;
+bool CSysLogger::m_registrySet = false;
+#endif
+
+string CSysLogger::m_programName;
+
+/* Unix facilities
+ { "auth", LOG_AUTH },
+ { "authpriv", LOG_AUTHPRIV },
+ { "cron", LOG_CRON },
+ { "daemon", LOG_DAEMON },
+ { "ftp", LOG_FTP },
+ { "kern", LOG_KERN },
+ { "lpr", LOG_LPR },
+ { "mail", LOG_MAIL },
+ { "news", LOG_NEWS },
+ { "syslog", LOG_SYSLOG },
+ { "user", LOG_USER },
+ { "uucp", LOG_UUCP },
+ */
+
+CSysLogger::CSysLogger(uint32_t facilities) :
+ m_facilities(facilities)
+{
+#ifndef _WIN32
+ m_objectCounter++;
+#else
+ m_logHandle = 0;
+#endif
+}
+
+void CSysLogger::saveMessage(CDateTime date, const char* prefix, const char \
*message, const CLogPriority *priority) throw(CException) +{
+ GUARD(m_lock);
+ if (m_options & CLO_ENABLE) {
+#ifndef _WIN32
+ if (!m_logOpened) {
+ openlog(m_programName.c_str(), LOG_NOWAIT, LOG_USER | LOG_INFO);
+ m_logOpened = true;
+ }
+ const char* messagePrefix = "";
+ if (prefix)
+ messagePrefix = prefix;
+ syslog(m_facilities | priority->id(), "%-7s %s%s", \
upperCase(priority->name()).c_str(), messagePrefix, message); +#else
+ if (!m_logHandle) {
+ OSVERSIONINFO version;
+ version.dwOSVersionInfoSize = sizeof(version);
+ if (!GetVersionEx(&version))
+ throw CException("Can't determine Windows version");
+ if (version.dwPlatformId != VER_PLATFORM_WIN32_NT)
+ throw CException("EventLog is only implemented on NT-based Windows");
+ m_logHandle = RegisterEventSource(0,m_programName.c_str());
+ }
+ if (!m_logHandle)
+ throw CException("Can't open Application Event Log");
+
+ unsigned eventType;
+ switch (priority->id()) {
+ case LOG_EMERG:
+ case LOG_ALERT:
+ case LOG_CRIT:
+ case LOG_ERR:
+ eventType = EVENTLOG_ERROR_TYPE;
+ break;
+ case LOG_WARNING:
+ eventType = EVENTLOG_WARNING_TYPE;
+ break;
+ default:
+ eventType = EVENTLOG_INFORMATION_TYPE;
+ break;
+ }
+
+ //const char *messageStrings[] = { message, NULL };
+ LPCTSTR messageStrings[]= {TEXT(message)};
+
+ if (!ReportEvent(
+ m_logHandle, // handle returned by RegisterEventSource
+ WORD(eventType), // event type to log
+ 0, // event category
+ SPTK_MESSAGE, // event identifier
+ 0, // user security identifier (optional)
+ 1, // number of strings to merge with message
+ 0, // size of binary data, in bytes
+ messageStrings, // array of strings to merge with message
+ 0 // address of binary data
+ )) {
+ throw CException("Can't write an event to Application Event Log ");
+ }
+#endif
+ }
+
+ if (m_options & CLO_STDOUT)
+ print(cout, date, prefix, message, priority);
+}
+
+CSysLogger::~CSysLogger()
+{
+#ifndef _WIN32
+ m_objectCounter--;
+ if (m_logOpened && m_objectCounter < 1)
+ closelog();
+#else
+ if (m_logHandle)
+ CloseEventLog(m_logHandle);
+#endif
+}
+
+void CSysLogger::programName(string progName)
+{
+ m_programName = progName;
+#ifndef _WIN32
+ m_logOpened = false;
+ closelog();
+#else
+ char *buffer = new char[_MAX_PATH];
+ GetModuleFileName(0,buffer,_MAX_PATH);
+ m_moduleFileName = buffer;
+
+ if (!m_registrySet) {
+ string keyName = \
"SYSTEM\\ControlSet001\\Services\\EventLog\\Application\\"+progName; +
+ HKEY keyHandle;
+ if (RegCreateKey(
+ HKEY_LOCAL_MACHINE,
+ \
("SYSTEM\\ControlSet001\\Services\\EventLog\\Application\\"+progName).c_str(), + \
&keyHandle) != ERROR_SUCCESS) + throw CException("Can't open registry \
(HKEY_LOCAL_MACHINE) for write"); +
+ unsigned long len = _MAX_PATH;
+ unsigned long vtype = REG_EXPAND_SZ;
+ if (RegQueryValueEx(
+ keyHandle, // handle to key to query
+ "EventMessageFile",
+ 0,
+ &vtype,
+ (BYTE *)buffer, // buffer for returned string
+ &len // receives size of returned string
+ ) != ERROR_SUCCESS)
+ throw CException("Can't open registry (HKEY_LOCAL_MACHINE) for write");
+
+ if (strcmp(buffer,m_moduleFileName.c_str()) != 0) {
+
+ if (RegSetValueEx(
+ keyHandle, // handle to key to set value for
+ "EventMessageFile", // name of the value to set
+ 0, // reserved
+ REG_EXPAND_SZ, // flag for value type
+ (CONST BYTE *)m_moduleFileName.c_str(), // address of \
value data + DWORD(m_moduleFileName.length()+1) // size of \
value data + ) != ERROR_SUCCESS)
+ throw CException("Can't open registry (HKEY_LOCAL_MACHINE) for write");
+
+ unsigned typesSupported = 7;
+ if (RegSetValueEx(
+ keyHandle, // handle to key to set value for
+ "TypesSupported", // name of the value to set
+ 0, // reserved
+ REG_DWORD, // flag for value type
+ (CONST BYTE *)&typesSupported, // address of value data
+ sizeof(typesSupported) // size of value data
+ ) != ERROR_SUCCESS)
+ throw CException("Can't open registry (HKEY_LOCAL_MACHINE) for write");
+ RegCloseKey(keyHandle);
+ }
+ m_registrySet = true;
+ }
+#endif
+}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic