1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
procedure TEventLogger.LogMessage(Message: String; EventType: DWord;
Category: Word; ID: DWord);
{$IF DEFINED(CLR)}
var
P, PP: IntPtr;
begin
if FEventLog = 0 then
FEventLog := RegisterEventSource(nil, FName);
P := Marshal.StringToHGlobalAuto(Message);
try
PP := Marshal.AllocHGlobal(SizeOf(IntPtr));
try
Marshal.WriteIntPtr(PP, P);
ReportEvent(FEventLog, EventType, Category, ID, nil, 1, 0, PP, nil);
finally
Marshal.FreeHGlobal(PP);
end;
finally
Marshal.FreeHGlobal(P);
end;
end;
{$ELSE}
var
P: Pointer;
begin
P := PChar(Message);
if FEventLog = 0 then
FEventLog := RegisterEventSource(nil, PChar(FName));
ReportEvent(FEventLog, EventType, Category, ID, nil, 1, 0, @P, nil);
end;
{$ENDIF} |
Partager