Happy birthday, my little blog. ;)
Transmission Terminated
1 week ago
Esprit curieux
void ReadLastEntryByInstanceId(QString sourceName, int instanceId) { HANDLE eventLogHandle; BYTE entryBuffer[16384]; DWORD dwRead, dwNeeded; DWORD eventsNumber; EVENTLOGRECORD *entry; bool isFound = false; eventLogHandle = OpenEventLog(NULL, sourceName.toAscii().data()); if (eventLogHandle == NULL) return false; entry = (EVENTLOGRECORD*)&entryBuffer; GetNumberOfEventLogRecords(eventLogHandle, &eventsNumber); while (ReadEventLog(eventLogHandle, EVENTLOG_BACKWARDS_READ | EVENTLOG_SEQUENTIAL_READ, eventsNumber, entry, 16384, &dwRead, &dwNeeded) && (isFound == false)) { while (dwRead > 0) { if (entry->EventID == instanceId && isFound == false) { isFound = true; QString strings; QByteArray stringsBytes; stringsBytes.append((char*)entry + entry->StringOffset, entry->DataOffset - entry->StringOffset); strings = QString::fromWCharArray((wchar_t*)stringsBytes.data(), stringsBytes.size() / 2 - 1); // Split strings QStringList stringsList = strings.split(QString(1, '\0')); // Use stringsList } dwRead -= entry->Length; entry = (EVENTLOGRECORD*)((LPBYTE)entry + entry->Length); } entry = (EVENTLOGRECORD*)&entryBuffer; } CloseEventLog(eventLogHandle); }