Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Writing to the EventLog (ReportEvent API)
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00829711
Message ID:
00829891
Views:
25
I don't remember who post this first, so my apologies :(, This is the code I promise:
*** test.prg
nEType = 2
nEventID = 1001
nUserID = 0
DIMENSION aMsg[2]
aMsg[1] = 'Something happened'
aMsg[2] = 'This is what happened'

? Report_Event(@aMsg, 2, 'My Application', nEType, nEventID, nUserID) &&.F.

FUNCTION Report_Event(taMsg, tnMsgCount, tcApp, tnEType, tnEventID,
tnUserID)

DECLARE LONG RegisterEventSource IN advapi32.dll ;
 STRING, STRING
DECLARE LONG DeregisterEventSource IN advapi32.dll ;
 LONG

DECLARE INTEGER ReportEvent IN advapi32.dll ;
 INTEGER nES, INTEGER nEType, INTEGER nPtrCat, ;
 INTEGER nEventID, INTEGER nUserID, INTEGER nNumString, ;
 INTEGER nDataSize, INTEGER nPtrMsg, INTEGER nData

DECLARE INTEGER HeapCreate IN Win32Api INTEGER nOptions, ;
 INTEGER nSize, INTEGER nMaxSize
DECLARE INTEGER HeapDestroy IN Win32Api INTEGER nHeap

DECLARE INTEGER HeapAlloc IN Win32Api ;
 INTEGER nHeap, INTEGER nFlags, INTEGER nSize
DECLARE INTEGER HeapFree IN Win32Api ;
 INTEGER nHeap, INTEGER nFlags, INTEGER nAddress

DECLARE RtlMoveMemory IN Win32Api AS CopyMemTo ;
     INTEGER, STRING @, INTEGER
DECLARE RtlMoveMemory IN Win32Api AS CopyMemFrom ;
     STRING @, INTEGER, INTEGER

LOCAL nDataSize, nData, nPtrCat, nPtrArray
*** set to zero for now
STORE 0 TO nDataSize, nData, nPtrCat, nPtrArray

LOCAL i, nMemAlloc, aAddress[1], cMsg, nArraySize, cAddrLst, ;
    nHeap, nPtrMsg, cMsg, nSize
IF tnMsgCount > 0 THEN
 cAddrLst = ''
 nMemAlloc = 0
 FOR i = 1 TO tnMsgCount
  nMemAlloc = nMemAlloc + LEN(taMsg[i]) + 1
 ENDFOR
 nArraySize = tnMsgCount * 4
 nMemAlloc = nMemAlloc + nArraySize + 1024 &&add 1K just in case
 DIMENSION aAddress[tnMsgCount]
 nHeap = HeapCreate(0, nMemAlloc, nMemAlloc)
 FOR i = 1 TO tnMsgCount
  cMsg = taMsg[i] + CHR(0)
  nSize = LEN(cMsg)
  nPtrMsg = HeapAlloc(nHeap, 0, nSize)
  **Save address in array to release later
  aAddress[i] = nPtrMsg
  **Assign string to address
  CopyMemTo(nPtrMsg, cMsg, nSize)

  **build string of binary addresses
  cAddrLst = cAddrLst + NumToDWord(nPtrMsg)
 ENDFOR
 nPtrArray = HeapAlloc(nHeap, 0, nArraySize)
 CopyMemTo(nPtrArray, cAddrLst, nArraySize)
ENDIF

LOCAL nES, nResult
nES = RegisterEventSource('', tcApp)
nResult = ReportEvent(nES, tnEType, nPtrCat, ;
 tnEventID, tnUserID, tnMsgCount, nDataSize, nPtrArray, nData) <> 0
IF nPtrArray > 0 THEN
 **Free the array pointer
 HeapFree(nHeap, 0, nPtrArray)
 FOR i = 1 TO tnMsgCount
  **Free the address of each message string
  HeapFree(nHeap, 0, aAddress[i])
 ENDFOR
 HeapDestroy(nHeap)
ENDIF
DeregisterEventSource(nES)
RETURN nResult
ENDFUNC

FUNCTION NumToDWord(tnVal)
#DEFINE DWORDOFFSET 2147483648
LOCAL cBin
cBin = BINTOC(tnVal - DWORDOFFSET)
RETURN SUBSTR(cBin,4,1) + SUBSTR(cBin,3,1) + ;
 SUBSTR(cBin,2,1) + SUBSTR(cBin,1,1)
ENDFUNC
*** end test.prg
HTH

>Thanks; I was trying to avoid the use of WSH; I managed to get the API call to work in Visual FoxPro...
>-josh

>>Try with this:
>>--- Event Log ---
>>Automate Server administration tasks using the Windows 2000 Event Log from Visual FoxPro.
>>Cleber Ferrari, Coloil / ARC Sul
>>http://www.levelextreme.com/Magazine/August2002/Page33.asp
>>
>>Hope this helps
>>
>>>Does anyone have an examle for the ReportEvent() API call?
Apoya a Visual FoxPro usandolo legalmente
--
¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º
Espartaco Palma Martínez
SysOp PortalFox
http://www.portalfox.com
esparta@portalfox.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform