Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. ReportEvent fails

ReportEvent fails

Scheduled Pinned Locked Moved Visual Basic
help
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alex1205
    wrote on last edited by
    #1

    I was trying to write data in the event log. I found these lines of code somewhere: Dim bRC As Boolean Dim iNumStrings As Integer Dim hEventLog As Long Dim hMsgs As Long Dim cbStringSize As Long Dim iEventID As Integer Dim sMessage As String Dim sSource As String sSource = "ErrLog" sMessage = "Success Message" hEventLog = RegisterEventSource("", sSource) cbStringSize = Len(sMessage) + 1 hMsgs = GlobalAlloc(&H40, cbStringSize) CopyMemory ByVal hMsgs, ByVal sMessage, cbStringSize iNumStrings = 1 If ReportEvent(hEventLog, _ EVENTLOG_SUCCESS, 0, _ EBALOG_SUCCESS, 0&, _ iNumStrings, cbStringSize, _ hMsgs, hMsgs) = 0 Then MsgBox "FAILED" Else '-- Sucessful MsgBox "Success" End If Call GlobalFree(hMsgs) DeregisterEventSource (hEventLog) But it doesn't work, The function always returns 0. And it doesn't write anything on the log. please help. SDE

    D 1 Reply Last reply
    0
    • A alex1205

      I was trying to write data in the event log. I found these lines of code somewhere: Dim bRC As Boolean Dim iNumStrings As Integer Dim hEventLog As Long Dim hMsgs As Long Dim cbStringSize As Long Dim iEventID As Integer Dim sMessage As String Dim sSource As String sSource = "ErrLog" sMessage = "Success Message" hEventLog = RegisterEventSource("", sSource) cbStringSize = Len(sMessage) + 1 hMsgs = GlobalAlloc(&H40, cbStringSize) CopyMemory ByVal hMsgs, ByVal sMessage, cbStringSize iNumStrings = 1 If ReportEvent(hEventLog, _ EVENTLOG_SUCCESS, 0, _ EBALOG_SUCCESS, 0&, _ iNumStrings, cbStringSize, _ hMsgs, hMsgs) = 0 Then MsgBox "FAILED" Else '-- Sucessful MsgBox "Success" End If Call GlobalFree(hMsgs) DeregisterEventSource (hEventLog) But it doesn't work, The function always returns 0. And it doesn't write anything on the log. please help. SDE

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      The return value is zero because there was a failure. Use GetLastError to get the error number, then look that up here[^]. This is the System Error Codes list on MSDN. You might want to check the value returned by RegisterEventSource first. It looks like your not getting a good EventLog handle returned here. Your passing in an empty string instead of a 0 (which means NULL). This is where I think your problem is. If you change the call to this, it might work:

      hEventLog = RegisterEventSource("." & chr$(0), sSource)

      Again, if you get back a zero for either RegisterEventSource or ReportEvent, then use GetLastError to find out what the error was. RageInTheMachine9532

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups