[ADVAPI32]

ReportEventA/W: Strings must be passed to ElfrReportEventA/W as a pointer to an array of PANSI_STRINGs instead of a pointer to an array of ANSI_STRINGs. Now, strings appear in the event viewer.

svn path=/trunk/; revision=54642
This commit is contained in:
Eric Kohl 2011-12-12 21:54:20 +00:00
parent afac3095f0
commit 2116571788

View file

@ -940,7 +940,7 @@ ReportEventA(IN HANDLE hEventLog,
IN LPVOID lpRawData) IN LPVOID lpRawData)
{ {
NTSTATUS Status; NTSTATUS Status;
ANSI_STRING *Strings; PANSI_STRING *Strings;
ANSI_STRING ComputerName; ANSI_STRING ComputerName;
WORD i; WORD i;
CHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1]; CHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1];
@ -951,8 +951,8 @@ ReportEventA(IN HANDLE hEventLog,
wNumStrings, dwDataSize, lpStrings, lpRawData); wNumStrings, dwDataSize, lpStrings, lpRawData);
Strings = HeapAlloc(GetProcessHeap(), Strings = HeapAlloc(GetProcessHeap(),
0, HEAP_ZERO_MEMORY,
wNumStrings * sizeof(ANSI_STRING)); wNumStrings * sizeof(PANSI_STRING));
if (!Strings) if (!Strings)
{ {
SetLastError(ERROR_NOT_ENOUGH_MEMORY); SetLastError(ERROR_NOT_ENOUGH_MEMORY);
@ -960,7 +960,15 @@ ReportEventA(IN HANDLE hEventLog,
} }
for (i = 0; i < wNumStrings; i++) for (i = 0; i < wNumStrings; i++)
RtlInitAnsiString(&Strings[i], lpStrings[i]); {
Strings[i] = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
sizeof(ANSI_STRING));
if (Strings[i])
{
RtlInitAnsiString(Strings[i], lpStrings[i]);
}
}
dwSize = MAX_COMPUTERNAME_LENGTH + 1; dwSize = MAX_COMPUTERNAME_LENGTH + 1;
GetComputerNameA(szComputerName, &dwSize); GetComputerNameA(szComputerName, &dwSize);
@ -975,9 +983,9 @@ ReportEventA(IN HANDLE hEventLog,
dwEventID, dwEventID,
wNumStrings, wNumStrings,
dwDataSize, dwDataSize,
(PRPC_STRING) &ComputerName, (PRPC_STRING)&ComputerName,
lpUserSid, lpUserSid,
(PRPC_STRING*) &Strings, (PRPC_STRING*)Strings,
lpRawData, lpRawData,
0, 0,
NULL, NULL,
@ -989,6 +997,12 @@ ReportEventA(IN HANDLE hEventLog,
} }
RpcEndExcept; RpcEndExcept;
for (i = 0; i < wNumStrings; i++)
{
if (Strings[i] != NULL)
HeapFree(GetProcessHeap(), 0, Strings[i]);
}
HeapFree(GetProcessHeap(), 0, Strings); HeapFree(GetProcessHeap(), 0, Strings);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
@ -1027,7 +1041,7 @@ ReportEventW(IN HANDLE hEventLog,
IN LPVOID lpRawData) IN LPVOID lpRawData)
{ {
NTSTATUS Status; NTSTATUS Status;
UNICODE_STRING *Strings; PUNICODE_STRING *Strings;
UNICODE_STRING ComputerName; UNICODE_STRING ComputerName;
WORD i; WORD i;
WCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1]; WCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1];
@ -1039,7 +1053,7 @@ ReportEventW(IN HANDLE hEventLog,
Strings = HeapAlloc(GetProcessHeap(), Strings = HeapAlloc(GetProcessHeap(),
0, 0,
wNumStrings * sizeof(UNICODE_STRING)); wNumStrings * sizeof(PUNICODE_STRING));
if (!Strings) if (!Strings)
{ {
SetLastError(ERROR_NOT_ENOUGH_MEMORY); SetLastError(ERROR_NOT_ENOUGH_MEMORY);
@ -1047,7 +1061,15 @@ ReportEventW(IN HANDLE hEventLog,
} }
for (i = 0; i < wNumStrings; i++) for (i = 0; i < wNumStrings; i++)
RtlInitUnicodeString(&Strings[i], lpStrings[i]); {
Strings[i] = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
sizeof(ANSI_STRING));
if (Strings[i])
{
RtlInitUnicodeString(Strings[i], lpStrings[i]);
}
}
dwSize = MAX_COMPUTERNAME_LENGTH + 1; dwSize = MAX_COMPUTERNAME_LENGTH + 1;
GetComputerNameW(szComputerName, &dwSize); GetComputerNameW(szComputerName, &dwSize);
@ -1062,9 +1084,9 @@ ReportEventW(IN HANDLE hEventLog,
dwEventID, dwEventID,
wNumStrings, wNumStrings,
dwDataSize, dwDataSize,
(PRPC_UNICODE_STRING) &ComputerName, (PRPC_UNICODE_STRING)&ComputerName,
lpUserSid, lpUserSid,
(PRPC_UNICODE_STRING*) &Strings, (PRPC_UNICODE_STRING*)Strings,
lpRawData, lpRawData,
0, 0,
NULL, NULL,
@ -1076,6 +1098,12 @@ ReportEventW(IN HANDLE hEventLog,
} }
RpcEndExcept; RpcEndExcept;
for (i = 0; i < wNumStrings; i++)
{
if (Strings[i] != NULL)
HeapFree(GetProcessHeap(), 0, Strings[i]);
}
HeapFree(GetProcessHeap(), 0, Strings); HeapFree(GetProcessHeap(), 0, Strings);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))