Time for a chalenge - EventLog on windows Vista Ultimate

Just starting out? Need help? Post your questions and find answers here.
reisve
User
User
Posts: 86
Joined: Sat Nov 08, 2008 4:52 pm
Location: Luanda, Angola

Time for a chalenge - EventLog on windows Vista Ultimate

Post 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?
jpd
Enthusiast
Enthusiast
Posts: 167
Joined: Fri May 21, 2004 3:31 pm

Post 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
PB 5.10 Windows 7 x64 SP1
reisve
User
User
Posts: 86
Joined: Sat Nov 08, 2008 4:52 pm
Location: Luanda, Angola

Post by reisve »

Help is missing and the include files in the examples are missing. Will keep trying.
But, Thanks anyway
reisve
User
User
Posts: 86
Joined: Sat Nov 08, 2008 4:52 pm
Location: Luanda, Angola

Post by reisve »

No heroes here (not you JPD)??
jpd
Enthusiast
Enthusiast
Posts: 167
Joined: Fri May 21, 2004 3:31 pm

Post 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
PB 5.10 Windows 7 x64 SP1
reisve
User
User
Posts: 86
Joined: Sat Nov 08, 2008 4:52 pm
Location: Luanda, Angola

Post 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
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post 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!
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
LuCiFeR[SD]
666
666
Posts: 1033
Joined: Mon Sep 01, 2003 2:33 pm

Post by LuCiFeR[SD] »

[Rant]changed my mind about ranting.... ignore me[/Rant]
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post 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?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post 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.
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post 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:
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Post Reply