RegisterEventSource API

  • Thread starter david epsom dot com dot au
  • Start date
D

david epsom dot com dot au

I'm trying to use the ReportEvent API in VBA.

I am unable to register an event source. I'm trying to use event sources
like Com and Office, but I just get "The RPC server is unavailable". I
thought that perhaps "If the source name cannot be found, the event logging
service uses the Application log;" but I just get "The handle is invalid"

http://msdn.microsoft.com/library/d...y/en-us/eventlog/base/registereventsource.asp


http://msdn.microsoft.com/library/default.asp?url=/library/en-us/eventlog/base/reportevent.asp


Does anyone see what I am doing wrong? Can anyone suggest a better place to
ask this question?

(david)


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

'HANDLE RegisterEventSource(
' LPCTSTR lpUNCServerName,
' LPCTSTR lpSourceName
');



Public Declare Function ReportEvent Lib "Advapi32.dll" Alias "ReportEventA"
(ByVal hEventLog As Long, ByVal wType As Long, ByVal wCategory As Long,
ByVal dwEventID As Long, ByVal lpUserSid As Long, ByVal wNumStrings As Long,
ByVal dwDataSize As Long, ByVal LPCTSTR As Long, ByVal lpRawData As Long) As
Long


Public Declare Function FormatMessage Lib "Kernel32.dll" Alias
"FormatMessageA" (ByVal dwflags As Long, ByVal lpSource As Long, ByVal
dwMessageID As Long, ByVal dwLanguageID As Long, ByVal lpBuffer As String,
ByVal nSize As Long, args As Any) As Long



Sub r3w()
Dim v
Dim h As Long
Dim s As String


s = String(255, vbNullChar)

h = RegisterEventSource(0, "MICROSOFT OFFICE 10" & vbNullChar)

v = FormatMessage(&H12FF, 0, Err.LastDllError, 0, s, Len(s), 0)
If v > 0 Then MsgBox left(s, v)

v = ReportEvent(h, 0, 0, 0, 0, 0, 0, 0, 0)

If v = 0 Then
s = String(255, vbNullChar)
v = FormatMessage(&H12FF, 0, Err.LastDllError, 0, s, Len(s), 0)
If v > 0 Then MsgBox left(s, v)
End If


End Sub
 
D

david epsom dot com dot au

Douglas J Steele said:
You might try microsoft.public.vb.api




No answer there at all (or anywhere else)

Found it eventually though.

Sample at
http://support.microsoft.com/?kbid=154576

I was trying to pass Null to the API like this:

RegisterEventSource(0


The sample does this:
RegisterEventSource(" "

I'm now using this:
RegisterEventSource(vbNullString




(david)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top