wiaservc: COM cleanup for the IWiaDevMgr iface.
[wine] / dlls / advapi32 / eventlog.c
1 /*
2  * Win32 advapi functions
3  *
4  * Copyright 1995 Sven Verdoolaege
5  * Copyright 1998 Juergen Schmied
6  * Copyright 2003 Mike Hearn
7  *
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.
12  *
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.
17  *
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22
23 #include <stdarg.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winerror.h"
28 #include "winternl.h"
29 #include "wmistr.h"
30 #include "evntrace.h"
31 #include "evntprov.h"
32
33 #include "wine/unicode.h"
34 #include "wine/debug.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
37 WINE_DECLARE_DEBUG_CHANNEL(eventlog);
38
39 static inline LPWSTR SERV_dup( LPCSTR str )
40 {
41     UINT len;
42     LPWSTR wstr;
43
44     if( !str )
45         return NULL;
46     len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
47     wstr = HeapAlloc( GetProcessHeap(), 0, len*sizeof (WCHAR) );
48     MultiByteToWideChar( CP_ACP, 0, str, -1, wstr, len );
49     return wstr;
50 }
51
52 /******************************************************************************
53  * BackupEventLogA [ADVAPI32.@]
54  *
55  * Saves the event log to a backup file.
56  *
57  * PARAMS
58  *  hEventLog        [I] Handle to event log to backup.
59  *  lpBackupFileName [I] Name of the backup file.
60  *
61  * RETURNS
62  *  Success: nonzero. File lpBackupFileName will contain the contents of
63  *           hEvenLog.
64  *  Failure: zero.
65  */
66 BOOL WINAPI BackupEventLogA( HANDLE hEventLog, LPCSTR lpBackupFileName )
67 {
68     LPWSTR backupW;
69     BOOL ret;
70
71     backupW = SERV_dup(lpBackupFileName);
72     ret = BackupEventLogW(hEventLog, backupW);
73     HeapFree(GetProcessHeap(), 0, backupW);
74
75     return ret;
76 }
77
78 /******************************************************************************
79  * BackupEventLogW [ADVAPI32.@]
80  *
81  * See BackupEventLogA.
82  */
83 BOOL WINAPI BackupEventLogW( HANDLE hEventLog, LPCWSTR lpBackupFileName )
84 {
85     FIXME("(%p,%s) stub\n", hEventLog, debugstr_w(lpBackupFileName));
86
87     if (!lpBackupFileName)
88     {
89         SetLastError(ERROR_INVALID_PARAMETER);
90         return FALSE;
91     }
92
93     if (!hEventLog)
94     {
95         SetLastError(ERROR_INVALID_HANDLE);
96         return FALSE;
97     }
98
99     if (GetFileAttributesW(lpBackupFileName) != INVALID_FILE_ATTRIBUTES)
100     {
101         SetLastError(ERROR_ALREADY_EXISTS);
102         return FALSE;
103     }
104
105     return TRUE;
106 }
107
108 /******************************************************************************
109  * ClearEventLogA [ADVAPI32.@]
110  *
111  * Clears the event log and optionally saves the log to a backup file.
112  *
113  * PARAMS
114  *  hEvenLog         [I] Handle to event log to clear.
115  *  lpBackupFileName [I] Name of the backup file.
116  *
117  * RETURNS
118  *  Success: nonzero. if lpBackupFileName != NULL, lpBackupFileName will 
119  *           contain the contents of hEvenLog and the log will be cleared.
120  *  Failure: zero. Fails if the event log is empty or if lpBackupFileName
121  *           exists.
122  */
123 BOOL WINAPI ClearEventLogA( HANDLE hEventLog, LPCSTR lpBackupFileName )
124 {
125     LPWSTR backupW;
126     BOOL ret;
127
128     backupW = SERV_dup(lpBackupFileName);
129     ret = ClearEventLogW(hEventLog, backupW);
130     HeapFree(GetProcessHeap(), 0, backupW);
131
132     return ret;
133 }
134
135 /******************************************************************************
136  * ClearEventLogW [ADVAPI32.@]
137  *
138  * See ClearEventLogA.
139  */
140 BOOL WINAPI ClearEventLogW( HANDLE hEventLog, LPCWSTR lpBackupFileName )
141 {
142     FIXME("(%p,%s) stub\n", hEventLog, debugstr_w(lpBackupFileName));
143
144     if (!hEventLog)
145     {
146         SetLastError(ERROR_INVALID_HANDLE);
147         return FALSE;
148     }
149
150     return TRUE;
151 }
152
153 /******************************************************************************
154  * CloseEventLog [ADVAPI32.@]
155  *
156  * Closes a read handle to the event log.
157  *
158  * PARAMS
159  *  hEventLog [I/O] Handle of the event log to close.
160  *
161  * RETURNS
162  *  Success: nonzero
163  *  Failure: zero
164  */
165 BOOL WINAPI CloseEventLog( HANDLE hEventLog )
166 {
167     FIXME("(%p) stub\n", hEventLog);
168
169     if (!hEventLog)
170     {
171         SetLastError(ERROR_INVALID_HANDLE);
172         return FALSE;
173     }
174
175     return TRUE;
176 }
177
178 /******************************************************************************
179  * ControlTraceW [ADVAPI32.@]
180  *
181  * Control a givel event trace session
182  *
183  */
184 ULONG WINAPI ControlTraceW( TRACEHANDLE hSession, LPCWSTR SessionName, PEVENT_TRACE_PROPERTIES Properties, ULONG control )
185 {
186     FIXME("(%s, %s, %p, %d) stub\n", wine_dbgstr_longlong(hSession), debugstr_w(SessionName), Properties, control);
187     return ERROR_SUCCESS;
188 }
189
190 /******************************************************************************
191  * ControlTraceA [ADVAPI32.@]
192  *
193  * See ControlTraceW.
194  *
195  */
196 ULONG WINAPI ControlTraceA( TRACEHANDLE hSession, LPCSTR SessionName, PEVENT_TRACE_PROPERTIES Properties, ULONG control )
197 {
198     FIXME("(%s, %s, %p, %d) stub\n", wine_dbgstr_longlong(hSession), debugstr_a(SessionName), Properties, control);
199     return ERROR_SUCCESS;
200 }
201
202 /******************************************************************************
203  * FlushTraceA [ADVAPI32.@]
204  */
205 ULONG WINAPI FlushTraceA ( TRACEHANDLE hSession, LPCSTR SessionName, PEVENT_TRACE_PROPERTIES Properties )
206 {
207     return ControlTraceA( hSession, SessionName, Properties, EVENT_TRACE_CONTROL_FLUSH );
208 }
209
210 /******************************************************************************
211  * FlushTraceW [ADVAPI32.@]
212  */
213 ULONG WINAPI FlushTraceW ( TRACEHANDLE hSession, LPCWSTR SessionName, PEVENT_TRACE_PROPERTIES Properties )
214 {
215     return ControlTraceW( hSession, SessionName, Properties, EVENT_TRACE_CONTROL_FLUSH );
216 }
217
218
219 /******************************************************************************
220  * DeregisterEventSource [ADVAPI32.@]
221  * 
222  * Closes a write handle to an event log
223  *
224  * PARAMS
225  *  hEventLog [I/O] Handle of the event log.
226  *
227  * RETURNS
228  *  Success: nonzero
229  *  Failure: zero
230  */
231 BOOL WINAPI DeregisterEventSource( HANDLE hEventLog )
232 {
233     FIXME("(%p) stub\n", hEventLog);
234     return TRUE;
235 }
236
237 /******************************************************************************
238  * EnableTrace [ADVAPI32.@]
239  */
240 ULONG WINAPI EnableTrace( ULONG enable, ULONG flag, ULONG level, LPCGUID guid, TRACEHANDLE hSession )
241 {
242     FIXME("(%d, 0x%x, %d, %s, %s): stub\n", enable, flag, level,
243             debugstr_guid(guid), wine_dbgstr_longlong(hSession));
244
245     return ERROR_SUCCESS;
246 }
247
248 /******************************************************************************
249  * GetEventLogInformation [ADVAPI32.@]
250  *
251  * Retrieve some information about an event log.
252  *
253  * PARAMS
254  *  hEventLog      [I]   Handle to an open event log.
255  *  dwInfoLevel    [I]   Level of information (only EVENTLOG_FULL_INFO)
256  *  lpBuffer       [I/O] The buffer for the returned information
257  *  cbBufSize      [I]   The size of the buffer
258  *  pcbBytesNeeded [O]   The needed bytes to hold the information
259  *
260  * RETURNS
261  *  Success: TRUE. lpBuffer will hold the information and pcbBytesNeeded shows
262  *           the needed buffer size.
263  *  Failure: FALSE.
264  */
265 BOOL WINAPI GetEventLogInformation( HANDLE hEventLog, DWORD dwInfoLevel, LPVOID lpBuffer, DWORD cbBufSize, LPDWORD pcbBytesNeeded)
266 {
267     EVENTLOG_FULL_INFORMATION *efi;
268
269     FIXME("(%p, %d, %p, %d, %p) stub\n", hEventLog, dwInfoLevel, lpBuffer, cbBufSize, pcbBytesNeeded);
270
271     if (dwInfoLevel != EVENTLOG_FULL_INFO)
272     {
273         SetLastError(ERROR_INVALID_LEVEL);
274         return FALSE;
275     }
276
277     if (!hEventLog)
278     {
279         SetLastError(ERROR_INVALID_HANDLE);
280         return FALSE;
281     }
282
283     if (!lpBuffer || !pcbBytesNeeded)
284     {
285         /* FIXME: This will be handled properly when eventlog is moved
286          * to a higher level
287          */
288         SetLastError(RPC_X_NULL_REF_POINTER);
289         return FALSE;
290     }
291
292     *pcbBytesNeeded = sizeof(EVENTLOG_FULL_INFORMATION);
293     if (cbBufSize < sizeof(EVENTLOG_FULL_INFORMATION))
294     {
295         SetLastError(ERROR_INSUFFICIENT_BUFFER);
296         return FALSE;
297     }
298
299     /* Pretend the log is not full */
300     efi = (EVENTLOG_FULL_INFORMATION *)lpBuffer;
301     efi->dwFull = 0;
302
303     return TRUE;
304 }
305
306 /******************************************************************************
307  * GetNumberOfEventLogRecords [ADVAPI32.@]
308  *
309  * Retrieves the number of records in an event log.
310  *
311  * PARAMS
312  *  hEventLog       [I] Handle to an open event log.
313  *  NumberOfRecords [O] Number of records in the log.
314  *
315  * RETURNS
316  *  Success: nonzero. NumberOfRecords will contain the number of records in
317  *           the log.
318  *  Failure: zero
319  */
320 BOOL WINAPI GetNumberOfEventLogRecords( HANDLE hEventLog, PDWORD NumberOfRecords )
321 {
322     FIXME("(%p,%p) stub\n", hEventLog, NumberOfRecords);
323
324     if (!NumberOfRecords)
325     {
326         SetLastError(ERROR_INVALID_PARAMETER);
327         return FALSE;
328     }
329
330     if (!hEventLog)
331     {
332         SetLastError(ERROR_INVALID_HANDLE);
333         return FALSE;
334     }
335
336     *NumberOfRecords = 0;
337
338     return TRUE;
339 }
340
341 /******************************************************************************
342  * GetOldestEventLogRecord [ADVAPI32.@]
343  *
344  * Retrieves the absolute record number of the oldest record in an even log.
345  *
346  * PARAMS
347  *  hEventLog    [I] Handle to an open event log.
348  *  OldestRecord [O] Absolute record number of the oldest record.
349  *
350  * RETURNS
351  *  Success: nonzero. OldestRecord contains the record number of the oldest
352  *           record in the log.
353  *  Failure: zero 
354  */
355 BOOL WINAPI GetOldestEventLogRecord( HANDLE hEventLog, PDWORD OldestRecord )
356 {
357     FIXME("(%p,%p) stub\n", hEventLog, OldestRecord);
358
359     if (!OldestRecord)
360     {
361         SetLastError(ERROR_INVALID_PARAMETER);
362         return FALSE;
363     }
364
365     if (!hEventLog)
366     {
367         SetLastError(ERROR_INVALID_HANDLE);
368         return FALSE;
369     }
370
371     *OldestRecord = 0;
372
373     return TRUE;
374 }
375
376 /******************************************************************************
377  * NotifyChangeEventLog [ADVAPI32.@]
378  *
379  * Enables an application to receive notification when an event is written
380  * to an event log.
381  *
382  * PARAMS
383  *  hEventLog [I] Handle to an event log.
384  *  hEvent    [I] Handle to a manual-reset event object.
385  *
386  * RETURNS
387  *  Success: nonzero
388  *  Failure: zero
389  */
390 BOOL WINAPI NotifyChangeEventLog( HANDLE hEventLog, HANDLE hEvent )
391 {
392         FIXME("(%p,%p) stub\n", hEventLog, hEvent);
393         return TRUE;
394 }
395
396 /******************************************************************************
397  * OpenBackupEventLogA [ADVAPI32.@]
398  *
399  * Opens a handle to a backup event log.
400  *
401  * PARAMS
402  *  lpUNCServerName [I] Universal Naming Convention name of the server on which
403  *                      this will be performed.
404  *  lpFileName      [I] Specifies the name of the backup file.
405  *
406  * RETURNS
407  *  Success: Handle to the backup event log.
408  *  Failure: NULL
409  */
410 HANDLE WINAPI OpenBackupEventLogA( LPCSTR lpUNCServerName, LPCSTR lpFileName )
411 {
412     LPWSTR uncnameW, filenameW;
413     HANDLE handle;
414
415     uncnameW = SERV_dup(lpUNCServerName);
416     filenameW = SERV_dup(lpFileName);
417     handle = OpenBackupEventLogW(uncnameW, filenameW);
418     HeapFree(GetProcessHeap(), 0, uncnameW);
419     HeapFree(GetProcessHeap(), 0, filenameW);
420
421     return handle;
422 }
423
424 /******************************************************************************
425  * OpenBackupEventLogW [ADVAPI32.@]
426  *
427  * See OpenBackupEventLogA.
428  */
429 HANDLE WINAPI OpenBackupEventLogW( LPCWSTR lpUNCServerName, LPCWSTR lpFileName )
430 {
431     FIXME("(%s,%s) stub\n", debugstr_w(lpUNCServerName), debugstr_w(lpFileName));
432
433     if (!lpFileName)
434     {
435         SetLastError(ERROR_INVALID_PARAMETER);
436         return NULL;
437     }
438
439     if (lpUNCServerName && lpUNCServerName[0])
440     {
441         FIXME("Remote server not supported\n");
442         SetLastError(RPC_S_SERVER_UNAVAILABLE);
443         return NULL;
444     }
445
446     if (GetFileAttributesW(lpFileName) == INVALID_FILE_ATTRIBUTES)
447     {
448         SetLastError(ERROR_FILE_NOT_FOUND);
449         return NULL;
450     }
451
452     return (HANDLE)0xcafe4242;
453 }
454
455 /******************************************************************************
456  * OpenEventLogA [ADVAPI32.@]
457  *
458  * Opens a handle to the specified event log.
459  *
460  * PARAMS
461  *  lpUNCServerName [I] UNC name of the server on which the event log is
462  *                      opened.
463  *  lpSourceName    [I] Name of the log.
464  *
465  * RETURNS
466  *  Success: Handle to an event log.
467  *  Failure: NULL
468  */
469 HANDLE WINAPI OpenEventLogA( LPCSTR uncname, LPCSTR source )
470 {
471     LPWSTR uncnameW, sourceW;
472     HANDLE handle;
473
474     uncnameW = SERV_dup(uncname);
475     sourceW = SERV_dup(source);
476     handle = OpenEventLogW(uncnameW, sourceW);
477     HeapFree(GetProcessHeap(), 0, uncnameW);
478     HeapFree(GetProcessHeap(), 0, sourceW);
479
480     return handle;
481 }
482
483 /******************************************************************************
484  * OpenEventLogW [ADVAPI32.@]
485  *
486  * See OpenEventLogA.
487  */
488 HANDLE WINAPI OpenEventLogW( LPCWSTR uncname, LPCWSTR source )
489 {
490     FIXME("(%s,%s) stub\n", debugstr_w(uncname), debugstr_w(source));
491
492     if (!source)
493     {
494         SetLastError(ERROR_INVALID_PARAMETER);
495         return NULL;
496     }
497
498     if (uncname && uncname[0])
499     {
500         FIXME("Remote server not supported\n");
501         SetLastError(RPC_S_SERVER_UNAVAILABLE);
502         return NULL;
503     }
504
505     return (HANDLE)0xcafe4242;
506 }
507
508 /******************************************************************************
509  * QueryAllTracesW [ADVAPI32.@]
510  *
511  * Query information for started event trace sessions
512  *
513  */
514 ULONG WINAPI QueryAllTracesW( PEVENT_TRACE_PROPERTIES * parray, ULONG arraycount, PULONG psessioncount )
515 {
516     FIXME("(%p, %d, %p) stub\n", parray, arraycount, psessioncount);
517
518     if (psessioncount) *psessioncount = 0;
519     return ERROR_SUCCESS;
520 }
521
522 /******************************************************************************
523  * QueryAllTracesA [ADVAPI32.@]
524  *
525  * See QueryAllTracesW.
526  */
527 ULONG WINAPI QueryAllTracesA( PEVENT_TRACE_PROPERTIES * parray, ULONG arraycount, PULONG psessioncount )
528 {
529     FIXME("(%p, %d, %p) stub\n", parray, arraycount, psessioncount);
530
531     if (psessioncount) *psessioncount = 0;
532     return ERROR_SUCCESS;
533 }
534
535 /******************************************************************************
536  * ReadEventLogA [ADVAPI32.@]
537  *
538  * Reads a whole number of entries from an event log.
539  *
540  * PARAMS
541  *  hEventLog                [I] Handle of the event log to read.
542  *  dwReadFlags              [I] see MSDN doc.
543  *  dwRecordOffset           [I] Log-entry record number to start at.
544  *  lpBuffer                 [O] Buffer for the data read.
545  *  nNumberOfBytesToRead     [I] Size of lpBuffer.
546  *  pnBytesRead              [O] Receives number of bytes read.
547  *  pnMinNumberOfBytesNeeded [O] Receives number of bytes required for the
548  *                               next log entry.
549  *
550  * RETURNS
551  *  Success: nonzero
552  *  Failure: zero
553  */
554 BOOL WINAPI ReadEventLogA( HANDLE hEventLog, DWORD dwReadFlags, DWORD dwRecordOffset,
555     LPVOID lpBuffer, DWORD nNumberOfBytesToRead, DWORD *pnBytesRead, DWORD *pnMinNumberOfBytesNeeded )
556 {
557     FIXME("(%p,0x%08x,0x%08x,%p,0x%08x,%p,%p) stub\n", hEventLog, dwReadFlags,
558           dwRecordOffset, lpBuffer, nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
559     return FALSE;
560 }
561
562 /******************************************************************************
563  * ReadEventLogW [ADVAPI32.@]
564  *
565  * See ReadEventLogA.
566  */
567 BOOL WINAPI ReadEventLogW( HANDLE hEventLog, DWORD dwReadFlags, DWORD dwRecordOffset,
568     LPVOID lpBuffer, DWORD nNumberOfBytesToRead, DWORD *pnBytesRead, DWORD *pnMinNumberOfBytesNeeded )
569 {
570     FIXME("(%p,0x%08x,0x%08x,%p,0x%08x,%p,%p) stub\n", hEventLog, dwReadFlags,
571           dwRecordOffset, lpBuffer, nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
572     return FALSE;
573 }
574
575 /******************************************************************************
576  * RegisterEventSourceA [ADVAPI32.@]
577  *
578  * Returns a registered handle to an event log.
579  *
580  * PARAMS
581  *  lpUNCServerName [I] UNC name of the source server.
582  *  lpSourceName    [I] Specifies the name of the event source to retrieve.
583  *
584  * RETURNS
585  *  Success: Handle to the event log.
586  *  Failure: NULL. Returns ERROR_INVALID_HANDLE if lpSourceName specifies the
587  *           Security event log.
588  */
589 HANDLE WINAPI RegisterEventSourceA( LPCSTR lpUNCServerName, LPCSTR lpSourceName )
590 {
591     UNICODE_STRING lpUNCServerNameW;
592     UNICODE_STRING lpSourceNameW;
593     HANDLE ret;
594
595     FIXME("(%s,%s): stub\n", debugstr_a(lpUNCServerName), debugstr_a(lpSourceName));
596
597     RtlCreateUnicodeStringFromAsciiz(&lpUNCServerNameW, lpUNCServerName);
598     RtlCreateUnicodeStringFromAsciiz(&lpSourceNameW, lpSourceName);
599     ret = RegisterEventSourceW(lpUNCServerNameW.Buffer,lpSourceNameW.Buffer);
600     RtlFreeUnicodeString (&lpUNCServerNameW);
601     RtlFreeUnicodeString (&lpSourceNameW);
602     return ret;
603 }
604
605 /******************************************************************************
606  * RegisterEventSourceW [ADVAPI32.@]
607  *
608  * See RegisterEventSourceA.
609  */
610 HANDLE WINAPI RegisterEventSourceW( LPCWSTR lpUNCServerName, LPCWSTR lpSourceName )
611 {
612     FIXME("(%s,%s): stub\n", debugstr_w(lpUNCServerName), debugstr_w(lpSourceName));
613     return (HANDLE)0xcafe4242;
614 }
615
616 /******************************************************************************
617  * ReportEventA [ADVAPI32.@]
618  *
619  * Writes an entry at the end of an event log.
620  *
621  * PARAMS
622  *  hEventLog   [I] Handle of an event log.
623  *  wType       [I] See MSDN doc.
624  *  wCategory   [I] Event category.
625  *  dwEventID   [I] Event identifier.
626  *  lpUserSid   [I] Current user's security identifier.
627  *  wNumStrings [I] Number of insert strings in lpStrings.
628  *  dwDataSize  [I] Size of event-specific raw data to write.
629  *  lpStrings   [I] Buffer containing an array of string to be merged.
630  *  lpRawData   [I] Buffer containing the binary data.
631  *
632  * RETURNS
633  *  Success: nonzero. Entry was written to the log.
634  *  Failure: zero.
635  *
636  * NOTES
637  *  The ReportEvent function adds the time, the entry's length, and the
638  *  offsets before storing the entry in the log. If lpUserSid != NULL, the
639  *  username is also logged.
640  */
641 BOOL WINAPI ReportEventA ( HANDLE hEventLog, WORD wType, WORD wCategory, DWORD dwEventID,
642     PSID lpUserSid, WORD wNumStrings, DWORD dwDataSize, LPCSTR *lpStrings, LPVOID lpRawData)
643 {
644     LPWSTR *wideStrArray;
645     UNICODE_STRING str;
646     int i;
647     BOOL ret;
648
649     FIXME("(%p,0x%04x,0x%04x,0x%08x,%p,0x%04x,0x%08x,%p,%p): stub\n", hEventLog,
650           wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, lpStrings, lpRawData);
651
652     if (wNumStrings == 0) return TRUE;
653     if (!lpStrings) return TRUE;
654
655     wideStrArray = HeapAlloc(GetProcessHeap(), 0, sizeof(LPWSTR) * wNumStrings);
656     for (i = 0; i < wNumStrings; i++)
657     {
658         RtlCreateUnicodeStringFromAsciiz(&str, lpStrings[i]);
659         wideStrArray[i] = str.Buffer;
660     }
661     ret = ReportEventW(hEventLog, wType, wCategory, dwEventID, lpUserSid,
662                        wNumStrings, dwDataSize, (LPCWSTR *)wideStrArray, lpRawData);
663     for (i = 0; i < wNumStrings; i++)
664     {
665         HeapFree( GetProcessHeap(), 0, wideStrArray[i] );
666     }
667     HeapFree(GetProcessHeap(), 0, wideStrArray);
668     return ret;
669 }
670
671 /******************************************************************************
672  * ReportEventW [ADVAPI32.@]
673  *
674  * See ReportEventA.
675  */
676 BOOL WINAPI ReportEventW( HANDLE hEventLog, WORD wType, WORD wCategory, DWORD dwEventID,
677     PSID lpUserSid, WORD wNumStrings, DWORD dwDataSize, LPCWSTR *lpStrings, LPVOID lpRawData )
678 {
679     int i;
680
681     FIXME("(%p,0x%04x,0x%04x,0x%08x,%p,0x%04x,0x%08x,%p,%p): stub\n", hEventLog,
682           wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, lpStrings, lpRawData);
683
684     /* partial stub */
685
686     if (wNumStrings == 0) return TRUE;
687     if (!lpStrings) return TRUE;
688
689     for (i = 0; i < wNumStrings; i++)
690     {
691         switch (wType)
692         {
693         case EVENTLOG_SUCCESS:
694             TRACE_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
695             break;
696         case EVENTLOG_ERROR_TYPE:
697             ERR_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
698             break;
699         case EVENTLOG_WARNING_TYPE:
700             WARN_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
701             break;
702         default:
703             TRACE_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
704             break;
705         }
706     }
707     return TRUE;
708 }
709
710 /******************************************************************************
711  * RegisterTraceGuidsW [ADVAPI32.@]
712  *
713  * Register an event trace provider and the event trace classes that it uses
714  * to generate events.
715  *
716  * PARAMS
717  *  RequestAddress     [I]   ControlCallback function
718  *  RequestContext     [I]   Optional provider-defined context
719  *  ControlGuid        [I]   GUID of the registering provider
720  *  GuidCount          [I]   Number of elements in the TraceGuidReg array
721  *  TraceGuidReg       [I/O] Array of TRACE_GUID_REGISTRATION structures
722  *  MofImagePath       [I]   not supported, set to NULL
723  *  MofResourceNmae    [I]   not supported, set to NULL
724  *  RegistrationHandle [O]   Provider's registration handle
725  *
726  * RETURNS
727  *  Success: ERROR_SUCCESS
728  *  Failure: System error code
729  *
730  * FIXME
731  *  Stub.
732  */
733 ULONG WINAPI RegisterTraceGuidsW( WMIDPREQUEST RequestAddress,
734                 PVOID RequestContext, LPCGUID ControlGuid, ULONG GuidCount,
735                 PTRACE_GUID_REGISTRATION TraceGuidReg, LPCWSTR MofImagePath,
736                 LPCWSTR MofResourceName, PTRACEHANDLE RegistrationHandle )
737 {
738     FIXME("(%p, %p, %s, %u, %p, %s, %s, %p,)\n", RequestAddress, RequestContext,
739           debugstr_guid(ControlGuid), GuidCount, TraceGuidReg, debugstr_w(MofImagePath),
740           debugstr_w(MofResourceName), RegistrationHandle);
741     return ERROR_CALL_NOT_IMPLEMENTED;
742 }
743
744 /******************************************************************************
745  * RegisterTraceGuidsA [ADVAPI32.@]
746  *
747  * See RegisterTraceGuidsW.
748  *
749  * FIXME
750  *  Stub.
751  */
752 ULONG WINAPI RegisterTraceGuidsA( WMIDPREQUEST RequestAddress,
753                 PVOID RequestContext, LPCGUID ControlGuid, ULONG GuidCount,
754                 PTRACE_GUID_REGISTRATION TraceGuidReg, LPCSTR MofImagePath,
755                 LPCSTR MofResourceName, PTRACEHANDLE RegistrationHandle )
756 {
757     FIXME("(%p, %p, %s, %u, %p, %s, %s, %p,)\n", RequestAddress, RequestContext,
758           debugstr_guid(ControlGuid), GuidCount, TraceGuidReg, debugstr_a(MofImagePath),
759           debugstr_a(MofResourceName), RegistrationHandle);
760     return ERROR_CALL_NOT_IMPLEMENTED;
761 }
762
763 /******************************************************************************
764  * StartTraceW [ADVAPI32.@]
765  *
766  * Register and start an event trace session
767  *
768  */
769 ULONG WINAPI StartTraceW( PTRACEHANDLE pSessionHandle, LPCWSTR SessionName, PEVENT_TRACE_PROPERTIES Properties )
770 {
771     FIXME("(%p, %s, %p) stub\n", pSessionHandle, debugstr_w(SessionName), Properties);
772     if (pSessionHandle) *pSessionHandle = 0xcafe4242;
773     return ERROR_SUCCESS;
774 }
775
776 /******************************************************************************
777  * StartTraceA [ADVAPI32.@]
778  *
779  * See StartTraceW.
780  *
781  */
782 ULONG WINAPI StartTraceA( PTRACEHANDLE pSessionHandle, LPCSTR SessionName, PEVENT_TRACE_PROPERTIES Properties )
783 {
784     FIXME("(%p, %s, %p) stub\n", pSessionHandle, debugstr_a(SessionName), Properties);
785     if (pSessionHandle) *pSessionHandle = 0xcafe4242;
786     return ERROR_SUCCESS;
787 }
788
789 /******************************************************************************
790  * TraceEvent [ADVAPI32.@]
791  */
792 ULONG WINAPI TraceEvent( TRACEHANDLE SessionHandle, PEVENT_TRACE_HEADER EventTrace )
793 {
794     FIXME("%s %p\n", wine_dbgstr_longlong(SessionHandle), EventTrace);
795     return ERROR_CALL_NOT_IMPLEMENTED;
796 }
797
798 /******************************************************************************
799  * UnregisterTraceGuids [ADVAPI32.@]
800  *
801  * See RegisterTraceGuids
802  *
803  * FIXME
804  *  Stub.
805  */
806 ULONG WINAPI UnregisterTraceGuids( TRACEHANDLE RegistrationHandle )
807 {
808     FIXME("%s: stub\n", wine_dbgstr_longlong(RegistrationHandle));
809     return ERROR_CALL_NOT_IMPLEMENTED;
810 }
811
812 /******************************************************************************
813  * EventRegister [ADVAPI32.@]
814  */
815 ULONG WINAPI EventRegister( LPCGUID provider, PENABLECALLBACK callback, PVOID context, PREGHANDLE handle )
816 {
817     FIXME("%s, %p, %p, %p\n", debugstr_guid(provider), callback, context, handle);
818     return ERROR_CALL_NOT_IMPLEMENTED;
819 }
820
821 /******************************************************************************
822  * EventEnabled [ADVAPI32.@]
823  *
824  */
825 BOOLEAN WINAPI EventEnabled( REGHANDLE handle, PCEVENT_DESCRIPTOR descriptor )
826 {
827     FIXME("(%s, %p): stub\n", wine_dbgstr_longlong(handle), descriptor);
828     return FALSE;
829 }
830
831 /******************************************************************************
832  * QueryTraceW [ADVAPI32.@]
833  */
834 ULONG WINAPI QueryTraceW( TRACEHANDLE handle, LPCWSTR sessionname, PEVENT_TRACE_PROPERTIES properties )
835 {
836     FIXME("%s %s %p: stub\n", wine_dbgstr_longlong(handle), debugstr_w(sessionname), properties);
837     return ERROR_CALL_NOT_IMPLEMENTED;
838 }