Ticket #11480: win32_api.hpp.patch

File win32_api.hpp.patch, 2.3 KB (added by Valentin Shtronda <valiko.ua@…>, 6 years ago)

The patch with my fix/workaround to apply on top of version 1.60. Note that this fix will not compile on Windows prior to Vista or Server 2008, which do not have GetTickCount64.

  • win32_api.hpp

     
    2626#include <cstring>
    2727#include <cstdlib>
    2828#include <cstdio>
     29#include <ctime>
    2930
    3031#include <boost/assert.hpp>
    3132#include <string>
     
    851852   , interprocess_filetime *lpUserTime );
    852853extern "C" __declspec(dllimport) void __stdcall Sleep(unsigned long);
    853854extern "C" __declspec(dllimport) unsigned long __stdcall GetTickCount(void);
     855extern "C" __declspec(dllimport) unsigned long long __stdcall GetTickCount64(void);
    854856extern "C" __declspec(dllimport) int __stdcall SwitchToThread();
    855857extern "C" __declspec(dllimport) unsigned long __stdcall GetLastError();
    856858extern "C" __declspec(dllimport) void __stdcall SetLastError(unsigned long);
     
    22082210   unsigned long dwBytesToRead = 0;
    22092211   unsigned long dwBytesRead = 0;
    22102212   unsigned long dwMinimumBytesToRead = 0;
     2213   char stamp_str[sizeof(unsigned long long) * 3 + 1];
    22112214
    22122215   // The source name (provider) must exist as a subkey of Application.
    22132216   void *hEventLog = OpenEventLogA(0, source_name);
     
    22392242                  dwBytesToRead = dwMinimumBytesToRead;
    22402243                  heap_deleter.realloc_mem(dwMinimumBytesToRead);
    22412244                  if (!heap_deleter.get()){
    2242                      return false;
     2245                     break;
    22432246                  }
    22442247               }
    22452248               else{  //Not found or EOF
    2246                   return false;
     2249                   break;
    22472250               }
    22482251            }
    22492252            else
     
    22512254               interprocess_eventlogrecord *pTypedRecord;
    22522255               // Print the contents of each record in the buffer.
    22532256               if(find_record_in_buffer(heap_deleter.get(), dwBytesRead, provider_name, event_id, pTypedRecord)){
    2254                   char stamp_str[sizeof(unsigned long)*3+1];
    22552257                  std::sprintf(&stamp_str[0], "%u", ((unsigned int)pTypedRecord->TimeGenerated));
    22562258                  stamp = stamp_str;
    2257                   break;
     2259                  return true;
    22582260               }
    22592261            }
    22602262         }
    22612263      }
    22622264   }
     2265
     2266   std::sprintf(&stamp_str[0], "%llu", std::time(nullptr) - GetTickCount64() / 1000); // Seconds since 1-1-1970
     2267   stamp = stamp_str;
    22632268   return true;
    22642269}
    22652270