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