ReactOS  0.4.15-dev-2985-g54406bf
misc.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Automatic Testing Utility
3  * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE: Functions for writing to the Event Log
5  * COPYRIGHT: Copyright 2009 Dmitry Chapyshev (dmitry@reactos.org)
6  */
7 
8 #include "precomp.h"
10 
11 VOID
13 {
14  WCHAR szBuf[MAX_PATH] = L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\RosAutotest";
16  DWORD dwCategoryNum = 1;
17  DWORD dwDisp, dwData;
18  HKEY hKey;
19 
21  szBuf, 0, NULL,
23  KEY_WRITE, NULL, &hKey, &dwDisp) != ERROR_SUCCESS)
24  {
25  return;
26  }
27 
28  if (!GetModuleFileName(NULL, szPath, sizeof(szPath) / sizeof(szPath[0])))
29  return;
30 
31  if (RegSetValueExW(hKey,
32  L"EventMessageFile",
33  0,
35  (LPBYTE)szPath,
36  (DWORD)(wcslen(szPath) + 1) * sizeof(WCHAR)) != ERROR_SUCCESS)
37  {
39  return;
40  }
41 
44 
45  if (RegSetValueExW(hKey,
46  L"TypesSupported",
47  0,
48  REG_DWORD,
49  (LPBYTE)&dwData,
50  sizeof(DWORD)) != ERROR_SUCCESS)
51  {
53  return;
54  }
55 
56  if (RegSetValueExW(hKey,
57  L"CategoryMessageFile",
58  0,
60  (LPBYTE)szPath,
61  (DWORD)(wcslen(szPath) + 1) * sizeof(WCHAR)) != ERROR_SUCCESS)
62  {
64  return;
65  }
66 
67  if (RegSetValueExW(hKey,
68  L"CategoryCount",
69  0,
70  REG_DWORD,
71  (LPBYTE)&dwCategoryNum,
72  sizeof(DWORD)) != ERROR_SUCCESS)
73  {
75  return;
76  }
77 
79 
80  hLog = RegisterEventSourceW(NULL, L"RosAutotest");
81 }
82 
83 
84 VOID
86 {
88 }
89 
90 
91 BOOL
92 WriteLogMessage(WORD wType, DWORD dwEventID, LPWSTR lpMsg)
93 {
94  if (!ReportEventW(hLog,
95  wType,
96  0,
97  dwEventID,
98  NULL,
99  1,
100  0,
101  (LPCWSTR*)&lpMsg,
102  NULL))
103  {
104  return FALSE;
105  }
106 
107  return TRUE;
108 }
#define ERROR_SUCCESS
Definition: deptool.c:10
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define TRUE
Definition: types.h:120
static HANDLE ULONG_PTR dwData
Definition: file.c:35
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1091
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:53
#define EVENTLOG_ERROR_TYPE
Definition: winnt_old.h:2702
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
VOID InitLogs()
Definition: misc.cpp:195
HANDLE hLog
Definition: misc.cpp:9
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_WRITE
Definition: nt_native.h:1031
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4895
#define EVENTLOG_INFORMATION_TYPE
Definition: winnt_old.h:2704
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define EVENTLOG_WARNING_TYPE
Definition: winnt_old.h:2703
#define MAX_PATH
Definition: compat.h:34
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
#define GetModuleFileName
Definition: winbase.h:3687
static const WCHAR L[]
Definition: oid.c:1250
BOOL WINAPI ReportEventW(IN HANDLE hEventLog, IN WORD wType, IN WORD wCategory, IN DWORD dwEventID, IN PSID lpUserSid, IN WORD wNumStrings, IN DWORD dwDataSize, IN LPCWSTR *lpStrings, IN LPVOID lpRawData)
Definition: eventlog.c:1516
BOOL WriteLogMessage(WORD wType, DWORD dwEventID, LPCWSTR lpMsg)
Definition: misc.cpp:250
FxAutoRegKey hKey
LPCWSTR szPath
Definition: env.c:37
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
#define NULL
Definition: types.h:112
BOOL WINAPI DeregisterEventSource(IN HANDLE hEventLog)
Definition: eventlog.c:473
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
VOID FreeLogs()
Definition: misc.cpp:241
WCHAR * LPWSTR
Definition: xmlstorage.h:184
HANDLE WINAPI RegisterEventSourceW(IN LPCWSTR lpUNCServerName, IN LPCWSTR lpSourceName)
Definition: eventlog.c:1295
#define REG_DWORD
Definition: sdbapi.c:596
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12