title: ReadEventLog() API fails with error code 87 on Windows Server 2008 R2 while reading Application/System/Security event logs from system
body: <p>I have an MFC application which reads system (i.e. <em>Application/System/Security</em>) event logs on Windows Server 2008 R2 in WOW64 environment. I am facing a problem with std SDK <strong><em>::ReadEventLog()</em></strong> function in <strong>Windows Server 2008 R2</strong>. Below I have provided the code snippet, but the same code/API works perfectly in Windows XP WOW64 &amp; x64 environment. Error code '87' refers to "The parameter is incorrect" but according me the parameters which I passed to <strong>::ReadEventLog()</strong> function seems to be correct.</p>
  
  <p>[Code]</p>
  
  <p>//BufferSize.
  const int BUFFER_SIZE = 1024*10<br>
  BYTE l_bBufferSize[BUFFER_SIZE];<br>
  EVENTLOGRECORD* l_pEvntLogRecord = NULL;</p>
  
  <p>l_pEvntLogRecord = (EVENTLOGRECORD *) &amp;l_bBufferSize;
  ::SetLastError(0);</p>
  
  <p>/*
  Adjust the 'counter' to read logs. 'l_nReadRecordIndex' is mapped with the list control, e.g. on key down, 'l_nReadRecordIndex' is set as "GetCountPerPage() + 1" this is one case as their are many case.
  */</p>
  
  <p>DWORD l_dwLogCounter = (GetTotalNumberOfRecords() - l_nReadRecordIndex) + 1;</p>
  
  <p>//Read logs as per "nCntToReadRecords".</p>
  
  <p>for(l_dwLogCounter;l_nNoOfRecTobeRead &lt;= nCntToReadRecords;l_dwLogCounter--, l_nNoOfRecTobeRead++)
  {</p>
  
  <p>//Get Actual position to read.</p>
  
  <p>if(0 != ::ReadEventLog( m_hEventLogHandle, EVENTLOG_SEEK_READ|EVENTLOG_FORWARDS_READ,<br>
              l_dwLogCounter, l_pEvntLogRecord, BUFFER_SIZE, 
              &amp;l_dwReadBytes, &amp;l_dwNeedBytes))</p>
  
  <pre><code>{
       DWORD l_dwErrCode = 0;
       l_dwErrCode = ::GetLastError();    //87 is returned
       return FALSE
  }
  </code></pre>
  
  <p>}</p>
  
  <p>//Data population code</p>
  
  <p>If any one is aware of similar problem or worked on the similar issue please let me know the solution. Please refer the above code snippet and let me know the following things,  a) What are the incorrect parameters. b) Is their any another way to read event logs.</p>
  
  <p>Thanks in advance.</p>
  
  <p>--
  Ganesh</p>