Page 1 of 1

Time for a chalenge - EventLog on windows Vista Ultimate

Posted: Mon Jan 05, 2009 8:30 pm
by reisve
I'm working in a project which I intended to do in VB6. Didn't like much that dependencies from Net. Framework and decided to look for something better. Found PB. The project is going more or less OK with the help of this comunity. But... I need to write to windows EventLog and can't get a way to do it. My last atempt was to adapt a piece of code from MSDN even without knowing a thing about C++. Here is the result:

Code: Select all

; ** Facility codes.
#FACILITY_SYSTEM = $0
#FACILITY_STUBS = $3
#FACILITY_RUNTIME = $2
#FACILITY_IO_ERROR_CODE = $4


; ** Severity codes.
#STATUS_SEVERITY_WARNING = $2
#STATUS_SEVERITY_SUCCESS = $0
#STATUS_SEVERITY_INFORMATIONAL = $1
#STATUS_SEVERITY_ERROR = $3

; ** Event Types
#EVENTLOG_SUCCESS = $0000                           ; Information event
#EVENTLOG_AUDIT_FAILURE = $0010                     ; Failure Audit event
#EVENTLOG_AUDIT_SUCCESS = $0008                     ; Success Audit event
#EVENTLOG_ERROR_TYPE = $0001                        ; Error event
#EVENTLOG_INFORMATION_TYPE = $0004                  ; Information event
#EVENTLOG_WARNING_TYPE = $0002                      ; Warning event
 
sourceName.s = "NetTax"                      ; The event source name.
dwEventID.w = 0                              ; The event identifier.
cInserts.w = 1                               ; The count of insert strings.
szMsg.s = "insertString"                     ; The insert strings.

evHdl = RegisterEventSource_(#Null, sourceName) 
If evHdl = #Null 
    MessageRequester("", "Couldn't register event source")
EndIf

Result = ReportEvent_(evHdl, #EVENTLOG_SUCCESS, 0, dwEventID, #Null, cInserts, 0, @szMsg, #Null)
If Result = 0
    MessageRequester("", "Couldn't report the event. Failed with error " + Str(GetLastError_()))
EndIf
DeregisterEventSource_(evHdl) 
But it gives me an error 87: Invalid parameter

All the other examples arround the forum, do not write the message.

So the chalenge is... Can anyone get a snipet of code that enters an enter in the eventlog in windows vista?

Posted: Tue Jan 06, 2009 9:49 am
by jpd
Hi Reisve,

here a link to one library written by Progi1984,

Permits you to read and write in the Windows EventLog.

is written for PB 4.1x but works with PB 4.2x,

I'm not know if this works with 4.30

http://www.purebasic.fr/english/viewtop ... 684#177684

http://purebasic.myftp.org/?filename=fi ... g_4_10.zip

best
jpd

Posted: Tue Jan 06, 2009 11:28 am
by reisve
Help is missing and the include files in the examples are missing. Will keep trying.
But, Thanks anyway

Posted: Tue Jan 06, 2009 4:17 pm
by reisve
No heroes here (not you JPD)??

Posted: Wed Jan 07, 2009 10:47 am
by jpd
Hi reisve,

I'm sorry but I have give you false information.

the lib does not works properly on 4.20

here your code with some changes,

the event is generated but the message that for this event no description exist... remain

Code: Select all

; ** Facility codes. 
#FACILITY_SYSTEM = $0 
#FACILITY_STUBS = $3 
#FACILITY_RUNTIME = $2 
#FACILITY_IO_ERROR_CODE = $4 


; ** Severity codes. 
#STATUS_SEVERITY_WARNING = $2 
#STATUS_SEVERITY_SUCCESS = $0 
#STATUS_SEVERITY_INFORMATIONAL = $1 
#STATUS_SEVERITY_ERROR = $3 

; ** Event Types 
#EVENTLOG_SUCCESS = $0000                           ; Information event 
#EVENTLOG_AUDIT_FAILURE = $0010                     ; Failure Audit event 
#EVENTLOG_AUDIT_SUCCESS = $0008                     ; Success Audit event 
#EVENTLOG_ERROR_TYPE = $0001                        ; Error event 
#EVENTLOG_INFORMATION_TYPE = $0004                  ; Information event 
#EVENTLOG_WARNING_TYPE = $0002                      ; Warning event 

Dim szMsg.s(0)  
sourceName.s = "NetTax"                      ; The event source name. 
dwEventID.w = 333                          ; The event identifier. 
cInserts.w = 2                         ; The count of insert strings. 
ReDim szMsg.s(cInserts) 
szMsg.s(0) = "insertString"                     ; The insert strings. 
szMsg.s(1)="another string"

evHdl = RegisterEventSource_("", sourceName) 
;evHdl=OpenEventLog_("", sourceName)
If evHdl = #Null 
    MessageRequester("", "Couldn't register event source") 
EndIf 

Result = ReportEvent_(evHdl, #EVENTLOG_INFORMATION_TYPE , 0, dwEventID, #Null, cInserts, 0, szMsg(), #Null) 
;lReturnX = ReportEvent_(lLogAPIRetVal,#EVENTLOG_INFORMATION_TYPE ,0, CMessageTyp, 0,wNumStrings, rawdata, lparray,lprawdata)        
 
If Result = 0 
    MessageRequester("", "Couldn't report the event. Failed with error " + Str(GetLastError_())) 
EndIf 
DeregisterEventSource_(evHdl) 
best
jpd

Posted: Wed Jan 07, 2009 7:35 pm
by reisve
Thanks JPD. That is exactely my problem with the libs existing arround. The event gets registered but with no message...

What surprises me, is with all these gurus arround, aparentely with a very good knowleadge of C++, the M$ choice for the examples these days, and even some of them wrote libs to do this in PB and no one respound... Getting disapointed with PB and the comunity

Posted: Wed Jan 07, 2009 8:05 pm
by Fluid Byte
reisve wrote:Getting disapointed with PB and the comunity
Are you stoned? :?

You are not really telling us that because you don't get your lollipop PB and it's community are bad, don't you? It just shows that you are impatient. And besides, this is no ****ing service hotline!

Posted: Wed Jan 07, 2009 8:41 pm
by LuCiFeR[SD]
[Rant]changed my mind about ranting.... ignore me[/Rant]

Posted: Wed Jan 07, 2009 10:53 pm
by blueznl
What surprises me, is with all these gurus arround, aparentely with a very good knowleadge of C++, the M$ choice for the examples these days, and even some of them wrote libs to do this in PB and no one respound... Getting disapointed with PB and the comunity
Jeeez... my coach wouldn't call that exactly 'highly encouraging'...

I was tempted to write something like 'what surprises me is the lack of patience and the pitfyfull reliance on other people's work with a little blaming others whilst self being unable to even come up with a decent attempt'...

But then I thought better of it and decided not to. It's hard to distinguish flames and stupidity. Where's the icebox?

Posted: Thu Jan 08, 2009 12:05 am
by SFSxOI
reisve wrote:Thanks JPD. That is exactely my problem with the libs existing arround. The event gets registered but with no message...

What surprises me, is with all these gurus arround, aparentely with a very good knowleadge of C++, the M$ choice for the examples these days, and even some of them wrote libs to do this in PB and no one respound... Getting disapointed with PB and the comunity
That was just ...rude, uncalled for, and just plain disrespectful.

Posted: Thu Jan 08, 2009 2:02 am
by pdwyer
:lol:

I'm sure we'll all be rushing to service your requests now that you've made a comment like that! :D

Maybe it's just that "Gurus don't use Vista" so seeing that keyword in the title kept them all away 8)

Either way, you've only been here two months so we won't miss you :twisted: