Partially implement advapi.ReportEvent

Mike Hearn mike at theoretic.com
Sun Oct 19 06:58:12 CDT 2003


This implementation is obviously not complete, but it prints out the
event log strings using MESSAGE, which is good enough for now. This is
handy because MSI uses this API when it gets into trouble, so we can now
see what it thinks is going on.

ChangeLog:
Partially implement advapi.ReportEventA/W

Index: dlls/advapi32/eventlog.c
===================================================================
RCS file: /home/wine/wine/dlls/advapi32/eventlog.c,v
retrieving revision 1.19
diff -u -r1.19 eventlog.c
--- dlls/advapi32/eventlog.c    5 Sep 2003 23:08:44 -0000       1.19
+++ dlls/advapi32/eventlog.c    19 Oct 2003 11:51:01 -0000
@@ -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
@@ -257,8 +259,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 +323,19 @@
                 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) MESSAGE("EVENT LOG: %s\n", debugstr_w(str));
+       str = *(++lpStrings);
+    }
+    return TRUE;
+
 }





More information about the wine-patches mailing list