2 * Win32 advapi functions
4 * Copyright 1995 Sven Verdoolaege
5 * Copyright 1998 Juergen Schmied
6 * Copyright 2003 Mike Hearn
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
34 WINE_DECLARE_DEBUG_CHANNEL(eventlog);
36 /******************************************************************************
37 * BackupEventLogA [ADVAPI32.@]
39 * Saves the event log to a backup file.
42 * hEventLog [I] Handle to event log to backup.
43 * lpBackupFileName [I] Name of the backup file.
46 * Success: nonzero. File lpBackupFileName will contain the contents of
50 BOOL WINAPI BackupEventLogA( HANDLE hEventLog, LPCSTR lpBackupFileName )
56 /******************************************************************************
57 * BackupEventLogW [ADVAPI32.@]
62 BackupEventLogW( HANDLE hEventLog, LPCWSTR lpBackupFileName )
68 /******************************************************************************
69 * ClearEventLogA [ADVAPI32.@]
71 * Clears the event log and/or saves the log to a backup file.
74 * hEvenLog [I] Handle to event log to clear.
75 * lpBackupFileName [I] Name of the backup file.
78 * Success: nonzero. if lpBackupFileName != NULL, lpBackupFileName will
79 * contain the contents of hEvenLog and the log will be cleared.
80 * Failure: zero. Fails if the event log is empty or if lpBackupFileName
83 BOOL WINAPI ClearEventLogA ( HANDLE hEventLog, LPCSTR lpBackupFileName )
89 /******************************************************************************
90 * ClearEventLogW [ADVAPI32.@]
94 BOOL WINAPI ClearEventLogW ( HANDLE hEventLog, LPCWSTR lpBackupFileName )
100 /******************************************************************************
101 * CloseEventLog [ADVAPI32.@]
103 * Closes a read handle to the event log.
106 * hEventLog [I/O] Handle of the event log to close.
112 BOOL WINAPI CloseEventLog ( HANDLE hEventLog )
118 /******************************************************************************
119 * DeregisterEventSource [ADVAPI32.@]
121 * Closes a write handle to an event log
124 * hEventLog [I/O] Handle of the event log.
130 BOOL WINAPI DeregisterEventSource( HANDLE hEventLog )
132 FIXME("(%p): stub\n",hEventLog);
136 /******************************************************************************
137 * GetNumberOfEventLogRecords [ADVAPI32.@]
139 * Retrieves the number of records in an event log.
142 * hEventLog [I] Handle to an open event log.
143 * NumberOfRecords [O] Number of records in the log.
146 * Success: nonzero. NumberOfRecords will contain the number of records in
151 GetNumberOfEventLogRecords( HANDLE hEventLog, PDWORD NumberOfRecords )
157 /******************************************************************************
158 * GetOldestEventLogRecord [ADVAPI32.@]
160 * Retrieves the absolute record number of the oldest record in an even log.
163 * hEventLog [I] Handle to an open event log.
164 * OldestRecord [O] Absolute record number of the oldest record.
167 * Success: nonzero. OldestRecord contains the record number of the oldest
172 GetOldestEventLogRecord( HANDLE hEventLog, PDWORD OldestRecord )
178 /******************************************************************************
179 * NotifyChangeEventLog [ADVAPI32.@]
181 * Enables an application to receive notification when an event is written
185 * hEventLog [I] Handle to an event log.
186 * hEvent [I] Handle to a manual-reset event object.
192 BOOL WINAPI NotifyChangeEventLog( HANDLE hEventLog, HANDLE hEvent )
198 /******************************************************************************
199 * OpenBackupEventLogA [ADVAPI32.@]
201 * Opens a handle to a backup event log.
204 * lpUNCServerName [I] Universal Naming Convention name of the server on which
205 * this will be performed.
206 * lpFileName [I] Specifies the name of the backup file.
209 * Success: Handle to the backup event log.
213 OpenBackupEventLogA( LPCSTR lpUNCServerName, LPCSTR lpFileName )
219 /******************************************************************************
220 * OpenBackupEventLogW [ADVAPI32.@]
222 * see OpenBackupEventLogA
225 OpenBackupEventLogW( LPCWSTR lpUNCServerName, LPCWSTR lpFileName )
231 /******************************************************************************
232 * OpenEventLogA [ADVAPI32.@]
234 * Opens a handle to the specified event log.
237 * lpUNCServerName [I] UNC name of the server on which the event log is
239 * lpSourceName [I] Name of the log.
242 * Success: Handle to an event log.
245 HANDLE WINAPI OpenEventLogA(LPCSTR uncname,LPCSTR source)
247 FIXME("(%s,%s),stub!\n",uncname,source);
248 return (HANDLE)0xcafe4242;
251 /******************************************************************************
252 * OpenEventLogW [ADVAPI32.@]
257 OpenEventLogW( LPCWSTR uncname, LPCWSTR source )
263 /******************************************************************************
264 * ReadEventLogA [ADVAPI32.@]
266 * Reads a whole number of entries from an event log.
269 * hEventLog [I] Handle of the event log to read.
270 * dwReadFlags [I] see MSDN doc.
271 * dwRecordOffset [I] Log-entry record number to start at.
272 * lpBuffer [O] Buffer for the data read.
273 * nNumberOfBytesToRead [I] Size of lpBuffer.
274 * pnBytesRead [O] Receives number of bytes read.
275 * pnMinNumberOfBytesNeeded [O] Receives number of bytes required for the
282 BOOL WINAPI ReadEventLogA( HANDLE hEventLog, DWORD dwReadFlags, DWORD dwRecordOffset,
283 LPVOID lpBuffer, DWORD nNumberOfBytesToRead, DWORD *pnBytesRead, DWORD *pnMinNumberOfBytesNeeded )
289 /******************************************************************************
290 * ReadEventLogW [ADVAPI32.@]
295 ReadEventLogW( HANDLE hEventLog, DWORD dwReadFlags, DWORD dwRecordOffset,
296 LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
297 DWORD *pnBytesRead, DWORD *pnMinNumberOfBytesNeeded )
303 /******************************************************************************
304 * RegisterEventSourceA [ADVAPI32.@]
306 * Returns a registered handle to an event log.
309 * lpUNCServerName [I] UNC name of the source server.
310 * lpSourceName [I] Specifies the name of the event source to retrieve.
313 * Success: Handle to the event log.
314 * Failure: NULL. Returns ERROR_INVALID_HANDLE if lpSourceName specifies the
315 * Security event log.
317 HANDLE WINAPI RegisterEventSourceA( LPCSTR lpUNCServerName, LPCSTR lpSourceName )
320 UNICODE_STRING lpUNCServerNameW;
321 UNICODE_STRING lpSourceNameW;
323 RtlCreateUnicodeStringFromAsciiz(&lpUNCServerNameW, lpUNCServerName);
324 RtlCreateUnicodeStringFromAsciiz(&lpSourceNameW, lpSourceName);
325 ret = RegisterEventSourceW(lpUNCServerNameW.Buffer,lpSourceNameW.Buffer);
326 RtlFreeUnicodeString (&lpUNCServerNameW);
327 RtlFreeUnicodeString (&lpSourceNameW);
331 /******************************************************************************
332 * RegisterEventSourceW [ADVAPI32.@]
334 * see RegisterEventSourceA
337 RegisterEventSourceW( LPCWSTR lpUNCServerName, LPCWSTR lpSourceName )
339 FIXME("(%s,%s): stub\n", debugstr_w(lpUNCServerName),
340 debugstr_w(lpSourceName));
344 /******************************************************************************
345 * ReportEventA [ADVAPI32.@]
347 * Writes an entry at the end of an event log.
350 * hEventLog [I] Handle of an event log.
351 * wType [I] See MSDN doc.
352 * wCategory [I] Event category.
353 * dwEventID [I] Event identifier.
354 * lpUserSid [I] Current user's security identifier.
355 * wNumStrings [I] Number of insert strings in lpStrings.
356 * dwDataSize [I] Size of event-specific raw data to write.
357 * lpStrings [I] Buffer containing an array of string to be merged.
358 * lpRawData [I] Buffer containing the binary data.
361 * Success: nonzero. Entry was written to the log.
365 * The ReportEvent function adds the time, the entry's length, and the
366 * offsets before storing the entry in the log. If lpUserSid != NULL, the
367 * username is also logged.
369 BOOL WINAPI ReportEventA ( HANDLE hEventLog, WORD wType, WORD wCategory, DWORD dwEventID,
370 PSID lpUserSid, WORD wNumStrings, DWORD dwDataSize, LPCSTR *lpStrings, LPVOID lpRawData)
372 LPCWSTR *wideStrArray;
377 if (wNumStrings == 0) return TRUE;
378 if (!lpStrings) return TRUE;
380 wideStrArray = HeapAlloc(GetProcessHeap(), 0, sizeof(LPCWSTR) * wNumStrings);
381 for (i = 0; i < wNumStrings; i++)
383 RtlCreateUnicodeStringFromAsciiz(&str, lpStrings[i]);
384 wideStrArray[i] = str.Buffer;
386 ret = ReportEventW(hEventLog, wType, wCategory, dwEventID, lpUserSid,
387 wNumStrings, dwDataSize, wideStrArray, lpRawData);
388 for (i = 0; i < wNumStrings; i++)
390 HeapFree( GetProcessHeap(), 0, (LPSTR)wideStrArray[i] );
392 HeapFree(GetProcessHeap(), 0, wideStrArray);
396 /******************************************************************************
397 * ReportEventW [ADVAPI32.@]
402 ReportEventW( HANDLE hEventLog, WORD wType, WORD wCategory,
403 DWORD dwEventID, PSID lpUserSid, WORD wNumStrings,
404 DWORD dwDataSize, LPCWSTR *lpStrings, LPVOID lpRawData )
410 if (wNumStrings == 0) return TRUE;
411 if (!lpStrings) return TRUE;
413 for (i = 0; i < wNumStrings; i++)
417 case EVENTLOG_SUCCESS:
418 TRACE_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
420 case EVENTLOG_ERROR_TYPE:
421 ERR_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
423 case EVENTLOG_WARNING_TYPE:
424 WARN_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
427 TRACE_(eventlog)("%s\n", debugstr_w(lpStrings[i]));