//TH-Header //***************************************************************************************** // Copyright (c) 2004 COMTECH EDV-Organisations GmbH // All rights reserved. // // $FileName : l:\epshared\cEventlog.pkg // $ProjectName : // $Author : Bernhard Ponemayr // $Created : 29.07.2004 14:00 // // Contents: ReportEventLog // // Type: Global Procedure // // Arguments: String sApplicationName: The desired Application Name that should be displayed in the Eventlog // Integer iEventType: The desired Eventtype. Can be one of EVENTLOG_SUCCESS, EVENTLOG_ERROR_TYPE, EVENTLOG_WARNING_TYPE, EVENTLOG_INFORMATION_TYPE, EVENTLOG_AUDIT_SUCCESS or EVENTLOG_AUDIT_FAILURE // integer iEventNum: The Eventnumber to use // string sText: The text for the Event // // Description: The global Procedure ReportToEventlog writes an Entry to the Windows Application // Eventlog on Windows NT, Windows 2000, Windows 2003 and Windows XP. // // Remarks: Normaly Eventlog Information Strings are displayed based on a String-Ressource that is embedded // in a program dll or exe. The Application Name and the Event Number are used to find the desired // Event Text in the dll or exe. Such ressource Strings can have Placeholders (%1, %2...) which are // then replaced with the delivered text. All defined Applications that use the Eventlog are registered // under the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog Registry Key. // // Unfortunately it is not easily possible to add strings to a VDF Exe. But it is possible to // use an Application Name that is not defined under the Registry-Key mentioned above. In this case // the EventLog automatically uses the Application Eventlog and add a Information to the entry, that the // Event-Number can not be translated to a Event Text for this application. After this information, // the first string delivered to the Eventlog is also added to the entry. This way it is possible // to add Informations to the Eventlog without the need to register your Application in the Eventlog // and without any Ressources added to a Exe or DLL. // // For more Informations about the Eventlog take a look at MSDN. // // Sample: Send ReportToEventlog "MyApplication" EVENTLOG_INFORMATION_TYPE 1 "This is a Information Event with the Event ID 1" // Send ReportToEventlog "MyApplication" EVENTLOG_WARNING_TYPE 2 "This is a Warning Event with the Event ID 2" // Send ReportToEventlog "MyApplication" EVENTLOG_ERROR_TYPE 3 "This is a Error Event with the Event ID 3" //***************************************************************************************** //TH-RevisionStart // 29.07.2004 14:26 Initial Revision BP APBP //TH-RevisionEnd Use dll Define EVENTLOG_SUCCESS FOR |CI$0000 Define EVENTLOG_ERROR_TYPE FOR |CI$0001 Define EVENTLOG_WARNING_TYPE FOR |CI$0002 Define EVENTLOG_INFORMATION_TYPE FOR |CI$0004 Define EVENTLOG_AUDIT_SUCCESS FOR |CI$0008 Define EVENTLOG_AUDIT_FAILURE FOR |CI$0010 external_function RegisterEventSourceEf "RegisterEventSourceA" advapi32.dll Pointer pServer Pointer pApp Returns Handle external_function DeregisterEventSourceEf "DeregisterEventSource" advapi32.dll Handle hEventlog Returns Integer external_function ReportEventEf "ReportEventA" advapi32.dll Handle hEventlog Integer wType Integer wCategory Integer dwEventId Pointer pUserSid Integer dwNumStrings Integer dwDataSize Pointer pString Pointer pRawData Returns Integer Procedure ReportToEventlog GLOBAL String sApp Integer iType Integer iEventNum String sText Handle hEvent String sData Pointer pApp pText pData Integer iRet iCou Move (sApp + (Character(0))) to sApp getaddress Of sApp to pApp Move (OemToAnsi(pApp,pApp)) to iRet Move (RegisterEventSourceEf(0,pApp)) to hEvent If (hEvent<>0) Begin Move ("\n\n"+ sText) to sText Move (Replaces("\n",sText,((Character(13))+(Character(10))))) to sText If (length(sText)>32000) Move (Left(sText,32000)) to sText Move (sText + (Character(0)) ) to sText getaddress Of sText to pText Move (OemToAnsi(pText,pText)) to iRet Move (DwordToBytes(pText)) to sData getaddress Of sData to pData Move (ReportEventEf(hEvent,iType,0,iEventNum,0,1,0,pData,0)) to iRet Move (DeregisterEventSourceEf(hEvent)) to hEvent End End_Procedure