1 /* Microsoft Developer Support Copyright (c) 1993 Microsoft Corporation. */
3 /* Skip asynch rpc inclusion */
16 #define PERR(bSuccess, api) {if(!(bSuccess)) printf("%s: Error %d from %s \
17 on line %d\n", __FILE__, GetLastError(), api, __LINE__);}
20 /*********************************************************************
21 * FUNCTION: addSourceToRegistry(LPSTR pszAppname, LPSTR pszMsgDLL) *
23 * PURPOSE: Add a source name key, message DLL name value, and *
24 * message type supported value to the registry *
26 * INPUT: source name, path of message DLL *
29 *********************************************************************/
31 void addSourceToRegistry(LPSTR pszAppname, LPSTR pszMsgDLL)
33 HKEY hk; /* registry key handle */
37 char *lpregarray = regarray;
39 /* When an application uses the RegisterEventSource or OpenEventLog
40 function to get a handle of an event log, the event loggging service
41 searches for the specified source name in the registry. You can add a
42 new source name to the registry by opening a new registry subkey
43 under the Application key and adding registry values to the new
46 strcpy(lpregarray, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\");
47 strcat(lpregarray, pszAppname);
49 /* Create a new key for our application */
50 bSuccess = RegCreateKey(HKEY_LOCAL_MACHINE,lpregarray, &hk);
51 PERR(bSuccess == ERROR_SUCCESS, "RegCreateKey");
53 /* Add the Event-ID message-file name to the subkey. */
54 bSuccess = RegSetValueEx(hk, /* subkey handle */
55 "EventMessageFile", /* value name */
57 REG_EXPAND_SZ, /* value type */
58 (LPBYTE) pszMsgDLL, /* address of value data */
59 strlen(pszMsgDLL) + 1); /* length of value data */
60 PERR(bSuccess == ERROR_SUCCESS, "RegSetValueEx");
62 /* Set the supported types flags and addit to the subkey. */
63 dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE |
64 EVENTLOG_INFORMATION_TYPE;
65 bSuccess = RegSetValueEx(hk, /* subkey handle */
66 "TypesSupported", /* value name */
68 REG_DWORD, /* value type */
69 (LPBYTE) &dwData, /* address of value data */
70 sizeof(DWORD)); /* length of value data */
71 PERR(bSuccess == ERROR_SUCCESS, "RegSetValueEx");
76 /*********************************************************************
77 * FUNCTION: reportAnEvent(DWORD dwIdEvent, WORD cStrings, *
78 * LPTSTR *ppszStrings); *
80 * PURPOSE: add the event to the event log *
82 * INPUT: the event ID to report in the log, the number of insert *
83 * strings, and an array of null-terminated insert strings *
86 *********************************************************************/
88 void reportAnIEvent(DWORD dwIdEvent, WORD cStrings, LPTSTR *pszStrings)
93 /* Get a handle to the Application event log */
94 hAppLog = RegisterEventSource(NULL, /* use local machine */
95 "NTP"); /* source name */
96 PERR(hAppLog, "RegisterEventSource");
98 /* Now report the event, which will add this event to the event log */
99 bSuccess = ReportEvent(hAppLog, /* event-log handle */
100 EVENTLOG_INFORMATION_TYPE, /* event type */
101 0, /* category zero */
102 dwIdEvent, /* event ID */
103 NULL, /* no user SID */
104 cStrings, /* number of substitution strings */
105 0, /* no binary data */
106 pszStrings, /* string array */
107 NULL); /* address of data */
108 PERR(bSuccess, "ReportEvent");
109 DeregisterEventSource(hAppLog);
113 void reportAnWEvent(DWORD dwIdEvent, WORD cStrings, LPTSTR *pszStrings)
118 /* Get a handle to the Application event log */
119 hAppLog = RegisterEventSource(NULL, /* use local machine */
120 "NTP"); /* source name */
121 PERR(hAppLog, "RegisterEventSource");
123 /* Now report the event, which will add this event to the event log */
124 bSuccess = ReportEvent(hAppLog, /* event-log handle */
125 EVENTLOG_WARNING_TYPE, /* event type */
126 0, /* category zero */
127 dwIdEvent, /* event ID */
128 NULL, /* no user SID */
129 cStrings, /* number of substitution strings */
130 0, /* no binary data */
131 pszStrings, /* string array */
132 NULL); /* address of data */
133 PERR(bSuccess, "ReportEvent");
134 DeregisterEventSource(hAppLog);
138 void reportAnEEvent(DWORD dwIdEvent, WORD cStrings, LPTSTR *pszStrings)
143 /* Get a handle to the Application event log */
144 hAppLog = RegisterEventSource(NULL, /* use local machine */
145 "NTP"); /* source name */
146 PERR(hAppLog, "RegisterEventSource");
148 /* Now report the event, which will add this event to the event log */
149 bSuccess = ReportEvent(hAppLog, /* event-log handle */
150 EVENTLOG_ERROR_TYPE, /* event type */
151 0, /* category zero */
152 dwIdEvent, /* event ID */
153 NULL, /* no user SID */
154 cStrings, /* number of substitution strings */
155 0, /* no binary data */
156 pszStrings, /* string array */
157 NULL); /* address of data */
158 PERR(bSuccess, "ReportEvent");
159 DeregisterEventSource(hAppLog);