check out this link:
-------------------------------------
Accessing the NT Event Logging functions from PowerScript
Occasionally it is handy for a PowerBuilder application to store information in the Windows NT "event logging" database. These strings are then usable by the NT system "Event Viewer" (typically under the "Administrative Tools" folder). Share
Introduction Occasionally it is handy for a PowerBuilder application to store information in the Windows NT "event logging" database. These strings are then usable by the NT system "Event Viewer" (typically under the "Administrative Tools" folder). Using the event logging facility is not well documented, but is simple once you see an example.
This document provides example code to access the Win32 API's for these functions.
For details about the various parameters, refer to the Win32 API under "event logging".
A note for PowerBuilder 7 and later
If your component is using PowerBuilder 7 or later, then there is the "ErrorLogging" class which is much simpler to use.
This class provides easy access to the same Win32 event log with all data going into the "application" event log.
Additionally, if the component is running in Sybase "Enterprise Application Server" (aka Jaguar-CTS) then the log file is automatically redirected to the Jaguar log rather than the Win32 event log.
This class is not covered in this document, refer to your PowerBuilder online help.
Keywords
Event Logging, Event Viewer, RegisterEventSource, DeregisterEventSource, ReportEvent, ErrorLogging
Declare the global external functions
function long RegisterEventSource( string pszServerName, string pszSourceName ) &
LIBRARY "ADVAPI32.DLL" &
alias for "RegisterEventSourceA"
function boolean DeregisterEventSource( long hEventLog ) &
LIBRARY "ADVAPI32.DLL" &
alias for "DeregisterEventSource"
function boolean ReportEvent( long hEventLog, integer wType, integer wCategory, &
long dwEventID, long pUserSID, integer wNumStrings, &
long dwDataSize, string pStringArray[], long pRawData ) &
LIBRARY "ADVAPI32.DLL" &
alias for "ReportEventA"
Declare the constants
// The types of events that can be logged.
// Copied out of WINNT.H
constant integer EVENTLOG_SUCCESS = 0 // 0X0000
constant integer EVENTLOG_ERROR_TYPE = 1 // 0x0001
constant integer EVENTLOG_WARNING_TYPE = 2 // 0x0002
constant integer EVENTLOG_INFORMATION_TYPE = 4 // 0x0004
constant integer EVENTLOG_AUDIT_SUCCESS = 8 // 0x0008
constant integer EVENTLOG_AUDIT_FAILURE = 16 // 0x0010
Sample Usage
string sTmp[3]
string sServer
long hEventSrc // handle to WIN32 event logging system
boolean bResult
// I'm using 3 strings only to show it need not be one string...
sTmp[1] = "1: Hello Sailor from PowerBuilder"
sTmp[2] = "2: meow meow"
sTmp[3] = "3: woof woof"
//-----------------------------------
// Notice: the "sServer" being un-initialized means this computer
// the "fubar.app" can be anything you want.
hEventSrc = RegisterEventSource( sServer, "fubar.app" )
IF hEventSrc = 0 THEN
// whoops - something failed
Return 0
END IF
MessageBox( "RegisterEventSource", "returns: " + string(hEventSrc) )
//-----------------------------------
bResult = ReportEvent( hEventSrc, &
EVENTLOG_INFORMATION_TYPE, &
123, /* category (anything) */ &
0, /* msg file entry */ &
0, /* SID */ &
3, /* qty strings */ &
0, /* qty raw data */ &
sTmp, /* strings */ &
0 /* raw data */ &
)
MessageBox( "ReportEvent", "returns: " + string(bResult) )
//-----------------------------------
DeregisterEventSource( hEventSrc )
Availability
Windows NT4.0 or later
regards,
Miguel L.