1 /* Microsoft Developer Support Copyright (c) 1993 Microsoft Corporation. */
11 #define PERR(bSuccess, api) {if(!(bSuccess)) printf("%s: Error %d from %s \
12 on line %d\n", __FILE__, GetLastError(), api, __LINE__);}
15 /*********************************************************************
16 * FUNCTION: addSourceToRegistry(void) *
18 * PURPOSE: Add a source name key, message DLL name value, and *
19 * message type supported value to the registry *
21 * INPUT: source name, path of message DLL *
24 *********************************************************************/
26 void addSourceToRegistry(LPSTR pszAppname, LPSTR pszMsgDLL)
28 HKEY hk; /* registry key handle */
32 /* When an application uses the RegisterEventSource or OpenEventLog
33 function to get a handle of an event log, the event loggging service
34 searches for the specified source name in the registry. You can add a
35 new source name to the registry by opening a new registry subkey
36 under the Application key and adding registry values to the new
39 /* Create a new key for our application */
40 bSuccess = RegCreateKey(HKEY_LOCAL_MACHINE,
41 "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\NTP", &hk);
42 PERR(bSuccess == ERROR_SUCCESS, "RegCreateKey");
44 /* Add the Event-ID message-file name to the subkey. */
45 bSuccess = RegSetValueEx(hk, /* subkey handle */
46 "EventMessageFile", /* value name */
48 REG_EXPAND_SZ, /* value type */
49 (LPBYTE) pszMsgDLL, /* address of value data */
50 strlen(pszMsgDLL) + 1); /* length of value data */
51 PERR(bSuccess == ERROR_SUCCESS, "RegSetValueEx");
53 /* Set the supported types flags and addit to the subkey. */
54 dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE |
55 EVENTLOG_INFORMATION_TYPE;
56 bSuccess = RegSetValueEx(hk, /* subkey handle */
57 "TypesSupported", /* value name */
59 REG_DWORD, /* value type */
60 (LPBYTE) &dwData, /* address of value data */
61 sizeof(DWORD)); /* length of value data */
62 PERR(bSuccess == ERROR_SUCCESS, "RegSetValueEx");
67 /*********************************************************************
68 * FUNCTION: reportAnEvent(DWORD dwIdEvent, WORD cStrings, *
69 * LPTSTR *ppszStrings); *
71 * PURPOSE: add the event to the event log *
73 * INPUT: the event ID to report in the log, the number of insert *
74 * strings, and an array of null-terminated insert strings *
77 *********************************************************************/
79 void reportAnIEvent(DWORD dwIdEvent, WORD cStrings, LPTSTR *pszStrings)
84 /* Get a handle to the Application event log */
85 hAppLog = RegisterEventSource(NULL, /* use local machine */
86 "NTP"); /* source name */
87 PERR(hAppLog, "RegisterEventSource");
89 /* Now report the event, which will add this event to the event log */
90 bSuccess = ReportEvent(hAppLog, /* event-log handle */
91 EVENTLOG_INFORMATION_TYPE, /* event type */
92 0, /* category zero */
93 dwIdEvent, /* event ID */
94 NULL, /* no user SID */
95 cStrings, /* number of substitution strings */
96 0, /* no binary data */
97 pszStrings, /* string array */
98 NULL); /* address of data */
99 PERR(bSuccess, "ReportEvent");
100 DeregisterEventSource(hAppLog);
104 void reportAnWEvent(DWORD dwIdEvent, WORD cStrings, LPTSTR *pszStrings)
109 /* Get a handle to the Application event log */
110 hAppLog = RegisterEventSource(NULL, /* use local machine */
111 "NTP"); /* source name */
112 PERR(hAppLog, "RegisterEventSource");
114 /* Now report the event, which will add this event to the event log */
115 bSuccess = ReportEvent(hAppLog, /* event-log handle */
116 EVENTLOG_WARNING_TYPE, /* event type */
117 0, /* category zero */
118 dwIdEvent, /* event ID */
119 NULL, /* no user SID */
120 cStrings, /* number of substitution strings */
121 0, /* no binary data */
122 pszStrings, /* string array */
123 NULL); /* address of data */
124 PERR(bSuccess, "ReportEvent");
125 DeregisterEventSource(hAppLog);
129 void reportAnEEvent(DWORD dwIdEvent, WORD cStrings, LPTSTR *pszStrings)
134 /* Get a handle to the Application event log */
135 hAppLog = RegisterEventSource(NULL, /* use local machine */
136 "NTP"); /* source name */
137 PERR(hAppLog, "RegisterEventSource");
139 /* Now report the event, which will add this event to the event log */
140 bSuccess = ReportEvent(hAppLog, /* event-log handle */
141 EVENTLOG_ERROR_TYPE, /* event type */
142 0, /* category zero */
143 dwIdEvent, /* event ID */
144 NULL, /* no user SID */
145 cStrings, /* number of substitution strings */
146 0, /* no binary data */
147 pszStrings, /* string array */
148 NULL); /* address of data */
149 PERR(bSuccess, "ReportEvent");
150 DeregisterEventSource(hAppLog);