This time we use TRACE/WARN/ERR debug Mike Hearn <mike@xxxxxxxxxxxxx> Implement ReportEventA/W --- orig/dlls/advapi32/eventlog.c +++ mod/dlls/advapi32/eventlog.c @@ -1,7 +1,9 @@ /* * Win32 advapi functions * - * Copyright 1995 Sven Verdoolaege, 1998 Juergen Schmied + * Copyright 1995 Sven Verdoolaege + * 1998 Juergen Schmied + * 2003 Mike Hearn * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -29,7 +31,8 @@ #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(advapi); - +WINE_DECLARE_DEBUG_CHANNEL(eventlog); + /****************************************************************************** * BackupEventLogA [ADVAPI32.@] */ @@ -257,8 +260,49 @@ BOOL WINAPI ReportEventA ( HANDLE hEventLog, WORD wType, WORD wCategory, DWORD dwEventID, PSID lpUserSid, WORD wNumStrings, DWORD dwDataSize, LPCSTR *lpStrings, LPVOID lpRawData) { - FIXME("stub\n"); - return TRUE; + LPCWSTR *wideStrArray; + LPCWSTR *wsArrayIndex; + UNICODE_STRING *usArray; + UNICODE_STRING *usIndex; + int i; + BOOL ret; + + if (wNumStrings == 0) return TRUE; + if (!lpStrings) return TRUE; + + /* we need to create widestrings by using the RtlCreateUnicodeString API, but we also need to convert + an entire array of them, while ensuring there are no memory leaks. We have two dynamic arrays, + one of the intermediate UNICODE_STRINGs, and another of the resultant widestrs. + We keep the UNICODE_STRINGs around because they need to be freed after the call to ReportEventW. + + There is probably a better way to do this -mike + */ + + wideStrArray = HeapAlloc(GetProcessHeap(), 0, sizeof(LPCWSTR) * wNumStrings); + usArray = HeapAlloc(GetProcessHeap(), 0, sizeof(UNICODE_STRING) * wNumStrings); + + wsArrayIndex = wideStrArray; + usIndex = usArray; + for (i = 0; i < wNumStrings; i++) { + RtlCreateUnicodeStringFromAsciiz(usIndex, *lpStrings); + *wsArrayIndex = (*usIndex).Buffer; + wsArrayIndex++; + usIndex++; + lpStrings++; + } + + ret = ReportEventW(hEventLog, wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, wideStrArray, lpRawData); + + usIndex = usArray; + for (i = 0; i < wNumStrings; i++) { + RtlFreeUnicodeString(usIndex); + usIndex++; + } + + HeapFree(GetProcessHeap(), 0, wideStrArray); + HeapFree(GetProcessHeap(), 0, usArray); + + return ret; } /****************************************************************************** @@ -280,6 +324,27 @@ DWORD dwEventID, PSID lpUserSid, WORD wNumStrings, DWORD dwDataSize, LPCWSTR *lpStrings, LPVOID lpRawData ) { - FIXME("stub\n"); - return TRUE; + int i; + LPCWSTR str; + + /* partial stub */ + + if (wNumStrings == 0) return TRUE; + if (!lpStrings) return TRUE; + + str = *lpStrings; + for (i = 0; i < wNumStrings; i++) { + if (str) { + switch (wType) { + case EVENTLOG_SUCCESS: TRACE_(eventlog)("EVENT LOG: %s\n", debugstr_w(str)); break; + case EVENTLOG_ERROR_TYPE: ERR_(eventlog)("EVENT LOG: %s\n", debugstr_w(str)); break; + case EVENTLOG_WARNING_TYPE: WARN_(eventlog)("EVENT LOG: %s\n", debugstr_w(str)); break; + default: + TRACE_(eventlog)("EVENT LOG: %s\n", debugstr_w(str)); break; + } + } + str = *(++lpStrings); + } + return TRUE; + }