[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

API function RegisterEventSource

Posted on 2000-04-13
5
Medium Priority
?
883 Views
Last Modified: 2008-02-26
I need use API function RegisterEventSource. I wrote:

Dim hEvent
hEvent = RegisterEventSource("", "Message")

lReturn = ReportEvent(hEvent, 4, 0, 5, 0, 0, 0, 0, 0)

... but ReportEvent return 0. Why?

0
Comment
Question by:mikibenek
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 4

Expert Comment

by:Nazdor
ID: 2711268
Have you tried to call GetLastError, to see if the system can tell you why?
0
 

Author Comment

by:mikibenek
ID: 2711284
GetLastError() return 0
0
 
LVL 20

Expert Comment

by:hes
ID: 2712151
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2713317
have you ensured that you are getting a valid handle back from the registereventsource call?
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 200 total points
ID: 2713355
heres the full code of a working sample:

Declare Function RegisterEventSource Lib "advapi32.dll" Alias _
        "RegisterEventSourceA" (ByVal lpUNCServerName As String, _
        ByVal lpSourceName As String) As Long

    Declare Function DeregisterEventSource Lib "advapi32.dll" ( _
        ByVal hEventLog As Long) As Long

    Declare Function ReportEvent Lib "advapi32.dll" Alias _
      "ReportEventA" (ByVal hEventLog As Long, ByVal wType As Integer, _
        ByVal wCategory As Integer, ByVal dwEventID As Long, _
        ByVal lpUserSid As Any, ByVal wNumStrings As Integer, _
        ByVal dwDataSize As Long, plpStrings As Long, _
        lpRawData As Any) As Boolean

    Declare Function GetLastError Lib "kernel32" () As Long

    Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
        hpvDest As Any, hpvSource As Any, _
        ByVal cbCopy As Long)

    Declare Function GlobalAlloc Lib "kernel32" ( _
         ByVal wFlags As Long, _
         ByVal dwBytes As Long) As Long

    Declare Function GlobalFree Lib "kernel32" ( _
         ByVal hMem As Long) As Long

    '-- Public Constants
    Public Const EVENTLOG_SUCCESS = 0
    Public Const EVENTLOG_ERROR_TYPE = 1
    Public Const EVENTLOG_WARNING_TYPE = 2
    Public Const EVENTLOG_INFORMATION_TYPE = 4
    Public Const EVENTLOG_AUDIT_SUCCESS = 8
    Public Const EVENTLOG_AUDIT_FAILURE = 10

Public Function WriteToEventLog(sMessage As String, _
                           sSource As String, _
                           iLogType As Integer, _
                           vEventID As Integer) As Boolean

    Dim bRC              As Boolean
    Dim iNumStrings      As Integer
    Dim hEventLog        As Long
    Dim hMsgs            As Long
    Dim cbStringSize     As Long
    Dim iEventID         As Integer

    hEventLog = RegisterEventSource("", sSource)
    cbStringSize = Len(sMessage) + 1
    hMsgs = GlobalAlloc(&H40, cbStringSize)
    CopyMemory ByVal hMsgs, ByVal sMessage, cbStringSize
    iNumStrings = 1

    '-- ReportEvent returns 0 if failed,
    '-- Any other number indicates success
    If ReportEvent(hEventLog, _
       iLogType, 0, _
       iEventID, 0&, _
       iNumStrings, cbStringSize, _
       hMsgs, hMsgs) = 0 Then
        '-- Failed
        WriteToEventLog = False
    Else
        '-- Sucessful
        WriteToEventLog = True
    End If

    Call GlobalFree(hMsgs)
    DeregisterEventSource (hEventLog)
End Function

An example of how to write to the NT EventLog:

Call WriteToEventLog("Warning, file exceeded recommended limit.", _
"Test App", _
EVENTLOG_WARNING_TYPE, 1003)




0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question