Thanks Peter,

I successfully used [DLLImport] with entry points of OpenBackupEventLog,
GetNumberOfEventLogRecords and CloseEventLog. When it comes to
ReadEventLog, my (failing) code is as follows:

// create reference to ReadEventLog in advapi32.dll
[DllImport("advapi32.dll", EntryPoint="ReadEventLog")]
public static extern bool ReadEventLog(
   int iBackupLogRef,
   int iReadFlags,
   int iRecordOffset,
   [MarshalAs(UnmanagedType.LPArray)] byte[] lpBuffer,
   int iNumberOfBytesToRead,
   out int pnBytesRead,
   out int pnMinNumberOfBytesNeeded);

// call ReadEventLog in advapi32.dll
bool success = ReadEventLog(
   iBackupLogRetValue,
   EVENTLOG_SEQUENTIAL_READ,
   iRecordOffset,
   myByteArray,
   myByteArray.Length,
   out iBytesRead,
   out iMinNumberOfBytesNeeded);

// output some data
string strByteArrayAsString = System.Text.ASCIIEncoding.ASCII.GetString
(myByteArray);
System.Console.WriteLine("strByteArrayAsString = " + strByteArrayAsString);

Unfortunately, the boolean "success" is always false and myByteArray is
always empty. Can you see anything obviously wrong?

Regards
Pete

On Fri, 22 Apr 2005 10:07:20 -0400, Peter Ritchie
<[EMAIL PROTECTED]> wrote:

>I think you'll have to use PInvoke and OpenBackupEventLog.
>
>[DllImport("advapi32.dll", EntryPoint="OpenBackupEventLog")] public static
>extern int OpenBackupEventLogA(string lpUNCServerName, string lpFileName)
>
>I believe the log name that you would use with EventLog is "Backup of
>application", or something of that nature.
>
>I haven't tried it; so, I don't knof if it will even work.  You may have to
>avoid EventLog altogether.
>
>Let us know if that works.
>
>-- Peter
>http://www.peterRitchie.com/
>
>On Fri, 22 Apr 2005 06:07:40 -0400, Pete Lutwyche
><[EMAIL PROTECTED]> wrote:
>
>>I've seen lots of examples where the System.Diagnostics.EventLog class is
>>used to read from the current Application, Security or System log on a
>>machine.
>>
>>What I need to do is loop over several hundred saved log files (*.evt file
>>extension, saved in some folder or other) looking for certain information.
>>I wanted to use System.Diagnostics.EventLog to do this, but can't see how.
>>Does anyone have any experience of solving a similar problem?
>
>===================================
>This list is hosted by DevelopMentorŪ  http://www.develop.com
>
>View archives and manage your subscription(s) at http://discuss.develop.com
===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to