Logging Events to the NT Event Log from VFP 
Author Message
 Logging Events to the NT Event Log from VFP

Quick and dirty trick is with the Scripting Host:

#DEFINE TARGET_SYSTEM SUBSTR(SYS(0),1,ATC('#',SYS(0))-1)
#DEFINE SUCCESS 0
#DEFINE ERROR 1
#DEFINE WARNING 2
#DEFINE INFORMATION 4
#DEFINE AUDIT_SUCCESS 8
#DEFINE AUDIT_FAILURE 16
WshShell = CreateObject("WScript.Shell")
*!* Logevent returns .t. for SUCCESS for .f. for FAILURE
?WshShell.LogEvent(SUCCESS, "Logon Script Completed Successfully")
WshShell.LogEvent(ERROR, "Logon Script Completed Successfully")
WshShell.LogEvent(WARNING, "We are getting low on disk space!!")
WshShell.LogEvent(INFORMATION, "Start nightly backup")
WshShell.LogEvent(AUDIT_SUCCESS, "Checksum Success!!")
WshShell.LogEvent(AUDIT_FAILURE, "Checksum Failure")
WshShell.LogEvent(AUDIT_FAILURE, "Checksum Failure",TARGET_SYSTEM)
WshShell=.NULL.

This code is from article Q257541 from http://www.*-*-*.com/

--
Eric den Doop
www.foxite.com - The Home Of The Visual FoxPro Experts


Quote:
> Hey guys,

> I was wondering if anyone had any code that would log events to the NT
event
> log from Fox. I wrote a VB component that I've been using from my VFP code
> that seems to work fine, but I thought if I could find some code in VFP,
it
> would be nicer to build it directly into my framework. I tried converting
> the VB code to VFP, but VFP is having trouble accessing the CopyMemory API
> call. Here's the VB code if you're interested:

> MODULE1.BAS

> Declare Function RegisterEventSource Lib "advapi32.dll" Alias _
>   "RegisterEventSourceA" (ByVal lpUNCServerName As String, _
>   ByVal lpSourceName As String) As Long

> Declare Function DeregisterEventSource Lib "advapi32.dll" ( _
>   ByVal hEventLog As Long) As Long

> Declare Function ReportEvent Lib "advapi32.dll" Alias _
> "ReportEventA" ( _
>   ByVal hEventLog As Long, ByVal wType As Integer, _
>   ByVal wCategory As Integer, ByVal dwEventID As Long, _
>   ByVal lpUserSid As Any, ByVal wNumStrings As Integer, _
>   ByVal dwDataSize As Long, plpStrings As Long, _
>   lpRawData As Any) As Boolean

> Declare Function GetLastError Lib "kernel32" () As Long

> Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
>   hpvDest As Any, hpvSource As Any, _
>   ByVal cbCopy As Long)

> Declare Function GlobalAlloc Lib "kernel32" ( _
>    ByVal wFlags As Long, _
>    ByVal dwBytes As Long) As Long

> Declare Function GlobalFree Lib "kernel32" ( _
>    ByVal hMem As Long) As Long

> CLASS1.CLS:

> Public Enum EventType
>     EVENTLOG_SUCCESS = 0
>     EVENTLOG_ERROR_TYPE = 1
>     EVENTLOG_WARNING_TYPE = 2
>     EVENTLOG_INFORMATION_TYPE = 4
>     EVENTLOG_AUDIT_SUCCESS = 8
>     EVENTLOG_AUDIT_FAILURE = 10
> End Enum

>   Public Function LogNTEvent(sAppName As String, sMessage As String, _
>                              iLogType As EventType, iEventID As Long)
>         Dim bRC As Boolean
>         Dim iNumStrings As Integer
>         Dim hEventLog As Long
>         Dim hMsgs As Long
>         Dim cbStringSize As Long
>         Dim bRetVal As Boolean

>         bRetVal = True

>         hEventLog = RegisterEventSource("", sAppName)
>         cbStringSize = Len(sMessage) + 1
>         hMsgs = GlobalAlloc(&H40, cbStringSize)
>         CopyMemory ByVal hMsgs, ByVal sMessage, cbStringSize
>         iNumStrings = 1

>         If ReportEvent(hEventLog, iLogType, 0, iEventID, 0&, iNumStrings,
_
>                         cbStringSize, hMsgs, hMsgs) = 0 Then
>            bRetVal = False
>         End If

>         Call GlobalFree(hMsgs)
>         DeregisterEventSource (hEventLog)

>         LogNTEvent = bRetVal

>   End Function

> TIA,
> -B



Wed, 12 Nov 2003 04:22:42 GMT  
 Logging Events to the NT Event Log from VFP
Hey guys,

I was wondering if anyone had any code that would log events to the NT event
log from Fox. I wrote a VB component that I've been using from my VFP code
that seems to work fine, but I thought if I could find some code in VFP, it
would be nicer to build it directly into my framework. I tried converting
the VB code to VFP, but VFP is having trouble accessing the CopyMemory API
call. Here's the VB code if you're interested:

MODULE1.BAS

Declare Function RegisterEventSource Lib "advapi32.dll" Alias _
  "RegisterEventSourceA" (ByVal lpUNCServerName As String, _
  ByVal lpSourceName As String) As Long

Declare Function DeregisterEventSource Lib "advapi32.dll" ( _
  ByVal hEventLog As Long) As Long

Declare Function ReportEvent Lib "advapi32.dll" Alias _
"ReportEventA" ( _
  ByVal hEventLog As Long, ByVal wType As Integer, _
  ByVal wCategory As Integer, ByVal dwEventID As Long, _
  ByVal lpUserSid As Any, ByVal wNumStrings As Integer, _
  ByVal dwDataSize As Long, plpStrings As Long, _
  lpRawData As Any) As Boolean

Declare Function GetLastError Lib "kernel32" () As Long

Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
  hpvDest As Any, hpvSource As Any, _
  ByVal cbCopy As Long)

Declare Function GlobalAlloc Lib "kernel32" ( _
   ByVal wFlags As Long, _
   ByVal dwBytes As Long) As Long

Declare Function GlobalFree Lib "kernel32" ( _
   ByVal hMem As Long) As Long

CLASS1.CLS:

Public Enum EventType
    EVENTLOG_SUCCESS = 0
    EVENTLOG_ERROR_TYPE = 1
    EVENTLOG_WARNING_TYPE = 2
    EVENTLOG_INFORMATION_TYPE = 4
    EVENTLOG_AUDIT_SUCCESS = 8
    EVENTLOG_AUDIT_FAILURE = 10
End Enum

  Public Function LogNTEvent(sAppName As String, sMessage As String, _
                             iLogType As EventType, iEventID As Long)
        Dim bRC As Boolean
        Dim iNumStrings As Integer
        Dim hEventLog As Long
        Dim hMsgs As Long
        Dim cbStringSize As Long
        Dim bRetVal As Boolean

        bRetVal = True

        hEventLog = RegisterEventSource("", sAppName)
        cbStringSize = Len(sMessage) + 1
        hMsgs = GlobalAlloc(&H40, cbStringSize)
        CopyMemory ByVal hMsgs, ByVal sMessage, cbStringSize
        iNumStrings = 1

        If ReportEvent(hEventLog, iLogType, 0, iEventID, 0&, iNumStrings, _
                        cbStringSize, hMsgs, hMsgs) = 0 Then
           bRetVal = False
        End If

        Call GlobalFree(hMsgs)
        DeregisterEventSource (hEventLog)

        LogNTEvent = bRetVal

  End Function

TIA,
-B



Wed, 12 Nov 2003 04:15:52 GMT  
 Logging Events to the NT Event Log from VFP
Ya, thanks. I saw this one in the KB. I don't like it because you can't
control the source name or event ID in the event log and our production
support monitoring scans for the name of our application in the source.

Thanks,
-B



Quote:
> Quick and dirty trick is with the Scripting Host:

> #DEFINE TARGET_SYSTEM SUBSTR(SYS(0),1,ATC('#',SYS(0))-1)
> #DEFINE SUCCESS 0
> #DEFINE ERROR 1
> #DEFINE WARNING 2
> #DEFINE INFORMATION 4
> #DEFINE AUDIT_SUCCESS 8
> #DEFINE AUDIT_FAILURE 16
> WshShell = CreateObject("WScript.Shell")
> *!* Logevent returns .t. for SUCCESS for .f. for FAILURE
> ?WshShell.LogEvent(SUCCESS, "Logon Script Completed Successfully")
> WshShell.LogEvent(ERROR, "Logon Script Completed Successfully")
> WshShell.LogEvent(WARNING, "We are getting low on disk space!!")
> WshShell.LogEvent(INFORMATION, "Start nightly backup")
> WshShell.LogEvent(AUDIT_SUCCESS, "Checksum Success!!")
> WshShell.LogEvent(AUDIT_FAILURE, "Checksum Failure")
> WshShell.LogEvent(AUDIT_FAILURE, "Checksum Failure",TARGET_SYSTEM)
> WshShell=.NULL.

> This code is from article Q257541 from http://msdn.microsoft.com

> --
> Eric den Doop
> www.foxite.com - The Home Of The Visual FoxPro Experts



> > Hey guys,

> > I was wondering if anyone had any code that would log events to the NT
> event
> > log from Fox. I wrote a VB component that I've been using from my VFP
code
> > that seems to work fine, but I thought if I could find some code in VFP,
> it
> > would be nicer to build it directly into my framework. I tried
converting
> > the VB code to VFP, but VFP is having trouble accessing the CopyMemory
API
> > call. Here's the VB code if you're interested:

> > MODULE1.BAS

> > Declare Function RegisterEventSource Lib "advapi32.dll" Alias _
> >   "RegisterEventSourceA" (ByVal lpUNCServerName As String, _
> >   ByVal lpSourceName As String) As Long

> > Declare Function DeregisterEventSource Lib "advapi32.dll" ( _
> >   ByVal hEventLog As Long) As Long

> > Declare Function ReportEvent Lib "advapi32.dll" Alias _
> > "ReportEventA" ( _
> >   ByVal hEventLog As Long, ByVal wType As Integer, _
> >   ByVal wCategory As Integer, ByVal dwEventID As Long, _
> >   ByVal lpUserSid As Any, ByVal wNumStrings As Integer, _
> >   ByVal dwDataSize As Long, plpStrings As Long, _
> >   lpRawData As Any) As Boolean

> > Declare Function GetLastError Lib "kernel32" () As Long

> > Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
> >   hpvDest As Any, hpvSource As Any, _
> >   ByVal cbCopy As Long)

> > Declare Function GlobalAlloc Lib "kernel32" ( _
> >    ByVal wFlags As Long, _
> >    ByVal dwBytes As Long) As Long

> > Declare Function GlobalFree Lib "kernel32" ( _
> >    ByVal hMem As Long) As Long

> > CLASS1.CLS:

> > Public Enum EventType
> >     EVENTLOG_SUCCESS = 0
> >     EVENTLOG_ERROR_TYPE = 1
> >     EVENTLOG_WARNING_TYPE = 2
> >     EVENTLOG_INFORMATION_TYPE = 4
> >     EVENTLOG_AUDIT_SUCCESS = 8
> >     EVENTLOG_AUDIT_FAILURE = 10
> > End Enum

> >   Public Function LogNTEvent(sAppName As String, sMessage As String, _
> >                              iLogType As EventType, iEventID As Long)
> >         Dim bRC As Boolean
> >         Dim iNumStrings As Integer
> >         Dim hEventLog As Long
> >         Dim hMsgs As Long
> >         Dim cbStringSize As Long
> >         Dim bRetVal As Boolean

> >         bRetVal = True

> >         hEventLog = RegisterEventSource("", sAppName)
> >         cbStringSize = Len(sMessage) + 1
> >         hMsgs = GlobalAlloc(&H40, cbStringSize)
> >         CopyMemory ByVal hMsgs, ByVal sMessage, cbStringSize
> >         iNumStrings = 1

> >         If ReportEvent(hEventLog, iLogType, 0, iEventID, 0&,
iNumStrings,
> _
> >                         cbStringSize, hMsgs, hMsgs) = 0 Then
> >            bRetVal = False
> >         End If

> >         Call GlobalFree(hMsgs)
> >         DeregisterEventSource (hEventLog)

> >         LogNTEvent = bRetVal

> >   End Function

> > TIA,
> > -B



Wed, 12 Nov 2003 04:45:44 GMT  
 Logging Events to the NT Event Log from VFP
You know VB, so how about a vfp rewrite of the code listed in Q154576? I'd
like a copy!

--
Eric den Doop
www.foxite.com - The Home Of The Visual FoxPro Experts


Quote:
> Ya, thanks. I saw this one in the KB. I don't like it because you can't
> control the source name or event ID in the event log and our production
> support monitoring scans for the name of our application in the source.

> Thanks,
> -B



> > Quick and dirty trick is with the Scripting Host:

> > #DEFINE TARGET_SYSTEM SUBSTR(SYS(0),1,ATC('#',SYS(0))-1)
> > #DEFINE SUCCESS 0
> > #DEFINE ERROR 1
> > #DEFINE WARNING 2
> > #DEFINE INFORMATION 4
> > #DEFINE AUDIT_SUCCESS 8
> > #DEFINE AUDIT_FAILURE 16
> > WshShell = CreateObject("WScript.Shell")
> > *!* Logevent returns .t. for SUCCESS for .f. for FAILURE
> > ?WshShell.LogEvent(SUCCESS, "Logon Script Completed Successfully")
> > WshShell.LogEvent(ERROR, "Logon Script Completed Successfully")
> > WshShell.LogEvent(WARNING, "We are getting low on disk space!!")
> > WshShell.LogEvent(INFORMATION, "Start nightly backup")
> > WshShell.LogEvent(AUDIT_SUCCESS, "Checksum Success!!")
> > WshShell.LogEvent(AUDIT_FAILURE, "Checksum Failure")
> > WshShell.LogEvent(AUDIT_FAILURE, "Checksum Failure",TARGET_SYSTEM)
> > WshShell=.NULL.

> > This code is from article Q257541 from http://msdn.microsoft.com

> > --
> > Eric den Doop
> > www.foxite.com - The Home Of The Visual FoxPro Experts



> > > Hey guys,

> > > I was wondering if anyone had any code that would log events to the NT
> > event
> > > log from Fox. I wrote a VB component that I've been using from my VFP
> code
> > > that seems to work fine, but I thought if I could find some code in
VFP,
> > it
> > > would be nicer to build it directly into my framework. I tried
> converting
> > > the VB code to VFP, but VFP is having trouble accessing the CopyMemory
> API
> > > call. Here's the VB code if you're interested:

> > > MODULE1.BAS

> > > Declare Function RegisterEventSource Lib "advapi32.dll" Alias _
> > >   "RegisterEventSourceA" (ByVal lpUNCServerName As String, _
> > >   ByVal lpSourceName As String) As Long

> > > Declare Function DeregisterEventSource Lib "advapi32.dll" ( _
> > >   ByVal hEventLog As Long) As Long

> > > Declare Function ReportEvent Lib "advapi32.dll" Alias _
> > > "ReportEventA" ( _
> > >   ByVal hEventLog As Long, ByVal wType As Integer, _
> > >   ByVal wCategory As Integer, ByVal dwEventID As Long, _
> > >   ByVal lpUserSid As Any, ByVal wNumStrings As Integer, _
> > >   ByVal dwDataSize As Long, plpStrings As Long, _
> > >   lpRawData As Any) As Boolean

> > > Declare Function GetLastError Lib "kernel32" () As Long

> > > Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
> > >   hpvDest As Any, hpvSource As Any, _
> > >   ByVal cbCopy As Long)

> > > Declare Function GlobalAlloc Lib "kernel32" ( _
> > >    ByVal wFlags As Long, _
> > >    ByVal dwBytes As Long) As Long

> > > Declare Function GlobalFree Lib "kernel32" ( _
> > >    ByVal hMem As Long) As Long

> > > CLASS1.CLS:

> > > Public Enum EventType
> > >     EVENTLOG_SUCCESS = 0
> > >     EVENTLOG_ERROR_TYPE = 1
> > >     EVENTLOG_WARNING_TYPE = 2
> > >     EVENTLOG_INFORMATION_TYPE = 4
> > >     EVENTLOG_AUDIT_SUCCESS = 8
> > >     EVENTLOG_AUDIT_FAILURE = 10
> > > End Enum

> > >   Public Function LogNTEvent(sAppName As String, sMessage As String, _
> > >                              iLogType As EventType, iEventID As Long)
> > >         Dim bRC As Boolean
> > >         Dim iNumStrings As Integer
> > >         Dim hEventLog As Long
> > >         Dim hMsgs As Long
> > >         Dim cbStringSize As Long
> > >         Dim bRetVal As Boolean

> > >         bRetVal = True

> > >         hEventLog = RegisterEventSource("", sAppName)
> > >         cbStringSize = Len(sMessage) + 1
> > >         hMsgs = GlobalAlloc(&H40, cbStringSize)
> > >         CopyMemory ByVal hMsgs, ByVal sMessage, cbStringSize
> > >         iNumStrings = 1

> > >         If ReportEvent(hEventLog, iLogType, 0, iEventID, 0&,
> iNumStrings,
> > _
> > >                         cbStringSize, hMsgs, hMsgs) = 0 Then
> > >            bRetVal = False
> > >         End If

> > >         Call GlobalFree(hMsgs)
> > >         DeregisterEventSource (hEventLog)

> > >         LogNTEvent = bRetVal

> > >   End Function

> > > TIA,
> > > -B



Wed, 12 Nov 2003 04:55:21 GMT  
 Logging Events to the NT Event Log from VFP
I did try already. But as I said before, VFP is having trouble accessing the
CopyMemory function.

-B



Quote:
> You know VB, so how about a vfp rewrite of the code listed in Q154576? I'd
> like a copy!

> --
> Eric den Doop
> www.foxite.com - The Home Of The Visual FoxPro Experts



> > Ya, thanks. I saw this one in the KB. I don't like it because you can't
> > control the source name or event ID in the event log and our production
> > support monitoring scans for the name of our application in the source.

> > Thanks,
> > -B



> > > Quick and dirty trick is with the Scripting Host:

> > > #DEFINE TARGET_SYSTEM SUBSTR(SYS(0),1,ATC('#',SYS(0))-1)
> > > #DEFINE SUCCESS 0
> > > #DEFINE ERROR 1
> > > #DEFINE WARNING 2
> > > #DEFINE INFORMATION 4
> > > #DEFINE AUDIT_SUCCESS 8
> > > #DEFINE AUDIT_FAILURE 16
> > > WshShell = CreateObject("WScript.Shell")
> > > *!* Logevent returns .t. for SUCCESS for .f. for FAILURE
> > > ?WshShell.LogEvent(SUCCESS, "Logon Script Completed Successfully")
> > > WshShell.LogEvent(ERROR, "Logon Script Completed Successfully")
> > > WshShell.LogEvent(WARNING, "We are getting low on disk space!!")
> > > WshShell.LogEvent(INFORMATION, "Start nightly backup")
> > > WshShell.LogEvent(AUDIT_SUCCESS, "Checksum Success!!")
> > > WshShell.LogEvent(AUDIT_FAILURE, "Checksum Failure")
> > > WshShell.LogEvent(AUDIT_FAILURE, "Checksum Failure",TARGET_SYSTEM)
> > > WshShell=.NULL.

> > > This code is from article Q257541 from http://msdn.microsoft.com

> > > --
> > > Eric den Doop
> > > www.foxite.com - The Home Of The Visual FoxPro Experts



> > > > Hey guys,

> > > > I was wondering if anyone had any code that would log events to the
NT
> > > event
> > > > log from Fox. I wrote a VB component that I've been using from my
VFP
> > code
> > > > that seems to work fine, but I thought if I could find some code in
> VFP,
> > > it
> > > > would be nicer to build it directly into my framework. I tried
> > converting
> > > > the VB code to VFP, but VFP is having trouble accessing the
CopyMemory
> > API
> > > > call. Here's the VB code if you're interested:

> > > > MODULE1.BAS

> > > > Declare Function RegisterEventSource Lib "advapi32.dll" Alias _
> > > >   "RegisterEventSourceA" (ByVal lpUNCServerName As String, _
> > > >   ByVal lpSourceName As String) As Long

> > > > Declare Function DeregisterEventSource Lib "advapi32.dll" ( _
> > > >   ByVal hEventLog As Long) As Long

> > > > Declare Function ReportEvent Lib "advapi32.dll" Alias _
> > > > "ReportEventA" ( _
> > > >   ByVal hEventLog As Long, ByVal wType As Integer, _
> > > >   ByVal wCategory As Integer, ByVal dwEventID As Long, _
> > > >   ByVal lpUserSid As Any, ByVal wNumStrings As Integer, _
> > > >   ByVal dwDataSize As Long, plpStrings As Long, _
> > > >   lpRawData As Any) As Boolean

> > > > Declare Function GetLastError Lib "kernel32" () As Long

> > > > Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
> > > >   hpvDest As Any, hpvSource As Any, _
> > > >   ByVal cbCopy As Long)

> > > > Declare Function GlobalAlloc Lib "kernel32" ( _
> > > >    ByVal wFlags As Long, _
> > > >    ByVal dwBytes As Long) As Long

> > > > Declare Function GlobalFree Lib "kernel32" ( _
> > > >    ByVal hMem As Long) As Long

> > > > CLASS1.CLS:

> > > > Public Enum EventType
> > > >     EVENTLOG_SUCCESS = 0
> > > >     EVENTLOG_ERROR_TYPE = 1
> > > >     EVENTLOG_WARNING_TYPE = 2
> > > >     EVENTLOG_INFORMATION_TYPE = 4
> > > >     EVENTLOG_AUDIT_SUCCESS = 8
> > > >     EVENTLOG_AUDIT_FAILURE = 10
> > > > End Enum

> > > >   Public Function LogNTEvent(sAppName As String, sMessage As String,
_
> > > >                              iLogType As EventType, iEventID As
Long)
> > > >         Dim bRC As Boolean
> > > >         Dim iNumStrings As Integer
> > > >         Dim hEventLog As Long
> > > >         Dim hMsgs As Long
> > > >         Dim cbStringSize As Long
> > > >         Dim bRetVal As Boolean

> > > >         bRetVal = True

> > > >         hEventLog = RegisterEventSource("", sAppName)
> > > >         cbStringSize = Len(sMessage) + 1
> > > >         hMsgs = GlobalAlloc(&H40, cbStringSize)
> > > >         CopyMemory ByVal hMsgs, ByVal sMessage, cbStringSize
> > > >         iNumStrings = 1

> > > >         If ReportEvent(hEventLog, iLogType, 0, iEventID, 0&,
> > iNumStrings,
> > > _
> > > >                         cbStringSize, hMsgs, hMsgs) = 0 Then
> > > >            bRetVal = False
> > > >         End If

> > > >         Call GlobalFree(hMsgs)
> > > >         DeregisterEventSource (hEventLog)

> > > >         LogNTEvent = bRetVal

> > > >   End Function

> > > > TIA,
> > > > -B



Wed, 12 Nov 2003 05:01:57 GMT  
 Logging Events to the NT Event Log from VFP
Is it a structure in the parameters?  If so, try the universalthread for a
structure class that lets you use some structures in VFP.


Quote:
> I did try already. But as I said before, VFP is having trouble accessing
the
> CopyMemory function.

> -B



> > You know VB, so how about a vfp rewrite of the code listed in Q154576?
I'd
> > like a copy!

> > --
> > Eric den Doop
> > www.foxite.com - The Home Of The Visual FoxPro Experts



> > > Ya, thanks. I saw this one in the KB. I don't like it because you
can't
> > > control the source name or event ID in the event log and our
production
> > > support monitoring scans for the name of our application in the
source.

> > > Thanks,
> > > -B



> > > > Quick and dirty trick is with the Scripting Host:

> > > > #DEFINE TARGET_SYSTEM SUBSTR(SYS(0),1,ATC('#',SYS(0))-1)
> > > > #DEFINE SUCCESS 0
> > > > #DEFINE ERROR 1
> > > > #DEFINE WARNING 2
> > > > #DEFINE INFORMATION 4
> > > > #DEFINE AUDIT_SUCCESS 8
> > > > #DEFINE AUDIT_FAILURE 16
> > > > WshShell = CreateObject("WScript.Shell")
> > > > *!* Logevent returns .t. for SUCCESS for .f. for FAILURE
> > > > ?WshShell.LogEvent(SUCCESS, "Logon Script Completed Successfully")
> > > > WshShell.LogEvent(ERROR, "Logon Script Completed Successfully")
> > > > WshShell.LogEvent(WARNING, "We are getting low on disk space!!")
> > > > WshShell.LogEvent(INFORMATION, "Start nightly backup")
> > > > WshShell.LogEvent(AUDIT_SUCCESS, "Checksum Success!!")
> > > > WshShell.LogEvent(AUDIT_FAILURE, "Checksum Failure")
> > > > WshShell.LogEvent(AUDIT_FAILURE, "Checksum Failure",TARGET_SYSTEM)
> > > > WshShell=.NULL.

> > > > This code is from article Q257541 from http://msdn.microsoft.com

> > > > --
> > > > Eric den Doop
> > > > www.foxite.com - The Home Of The Visual FoxPro Experts



> > > > > Hey guys,

> > > > > I was wondering if anyone had any code that would log events to
the
> NT
> > > > event
> > > > > log from Fox. I wrote a VB component that I've been using from my
> VFP
> > > code
> > > > > that seems to work fine, but I thought if I could find some code
in
> > VFP,
> > > > it
> > > > > would be nicer to build it directly into my framework. I tried
> > > converting
> > > > > the VB code to VFP, but VFP is having trouble accessing the
> CopyMemory
> > > API
> > > > > call. Here's the VB code if you're interested:

> > > > > MODULE1.BAS

> > > > > Declare Function RegisterEventSource Lib "advapi32.dll" Alias _
> > > > >   "RegisterEventSourceA" (ByVal lpUNCServerName As String, _
> > > > >   ByVal lpSourceName As String) As Long

> > > > > Declare Function DeregisterEventSource Lib "advapi32.dll" ( _
> > > > >   ByVal hEventLog As Long) As Long

> > > > > Declare Function ReportEvent Lib "advapi32.dll" Alias _
> > > > > "ReportEventA" ( _
> > > > >   ByVal hEventLog As Long, ByVal wType As Integer, _
> > > > >   ByVal wCategory As Integer, ByVal dwEventID As Long, _
> > > > >   ByVal lpUserSid As Any, ByVal wNumStrings As Integer, _
> > > > >   ByVal dwDataSize As Long, plpStrings As Long, _
> > > > >   lpRawData As Any) As Boolean

> > > > > Declare Function GetLastError Lib "kernel32" () As Long

> > > > > Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
> > > > >   hpvDest As Any, hpvSource As Any, _
> > > > >   ByVal cbCopy As Long)

> > > > > Declare Function GlobalAlloc Lib "kernel32" ( _
> > > > >    ByVal wFlags As Long, _
> > > > >    ByVal dwBytes As Long) As Long

> > > > > Declare Function GlobalFree Lib "kernel32" ( _
> > > > >    ByVal hMem As Long) As Long

> > > > > CLASS1.CLS:

> > > > > Public Enum EventType
> > > > >     EVENTLOG_SUCCESS = 0
> > > > >     EVENTLOG_ERROR_TYPE = 1
> > > > >     EVENTLOG_WARNING_TYPE = 2
> > > > >     EVENTLOG_INFORMATION_TYPE = 4
> > > > >     EVENTLOG_AUDIT_SUCCESS = 8
> > > > >     EVENTLOG_AUDIT_FAILURE = 10
> > > > > End Enum

> > > > >   Public Function LogNTEvent(sAppName As String, sMessage As
String,
> _
> > > > >                              iLogType As EventType, iEventID As
> Long)
> > > > >         Dim bRC As Boolean
> > > > >         Dim iNumStrings As Integer
> > > > >         Dim hEventLog As Long
> > > > >         Dim hMsgs As Long
> > > > >         Dim cbStringSize As Long
> > > > >         Dim bRetVal As Boolean

> > > > >         bRetVal = True

> > > > >         hEventLog = RegisterEventSource("", sAppName)
> > > > >         cbStringSize = Len(sMessage) + 1
> > > > >         hMsgs = GlobalAlloc(&H40, cbStringSize)
> > > > >         CopyMemory ByVal hMsgs, ByVal sMessage, cbStringSize
> > > > >         iNumStrings = 1

> > > > >         If ReportEvent(hEventLog, iLogType, 0, iEventID, 0&,
> > > iNumStrings,
> > > > _
> > > > >                         cbStringSize, hMsgs, hMsgs) = 0 Then
> > > > >            bRetVal = False
> > > > >         End If

> > > > >         Call GlobalFree(hMsgs)
> > > > >         DeregisterEventSource (hEventLog)

> > > > >         LogNTEvent = bRetVal

> > > > >   End Function

> > > > > TIA,
> > > > > -B



Wed, 12 Nov 2003 05:56:40 GMT  
 Logging Events to the NT Event Log from VFP
Actually the problem is in the DECLARE statement in VFP. It was giving me
the error "Entry Point Not Found". I will check on the UT.

Thanks,
-B


Quote:
> Is it a structure in the parameters?  If so, try the universalthread for a
> structure class that lets you use some structures in VFP.



> > I did try already. But as I said before, VFP is having trouble accessing
> the
> > CopyMemory function.

> > -B



> > > You know VB, so how about a vfp rewrite of the code listed in Q154576?
> I'd
> > > like a copy!

> > > --
> > > Eric den Doop
> > > www.foxite.com - The Home Of The Visual FoxPro Experts



> > > > Ya, thanks. I saw this one in the KB. I don't like it because you
> can't
> > > > control the source name or event ID in the event log and our
> production
> > > > support monitoring scans for the name of our application in the
> source.

> > > > Thanks,
> > > > -B



> > > > > Quick and dirty trick is with the Scripting Host:

> > > > > #DEFINE TARGET_SYSTEM SUBSTR(SYS(0),1,ATC('#',SYS(0))-1)
> > > > > #DEFINE SUCCESS 0
> > > > > #DEFINE ERROR 1
> > > > > #DEFINE WARNING 2
> > > > > #DEFINE INFORMATION 4
> > > > > #DEFINE AUDIT_SUCCESS 8
> > > > > #DEFINE AUDIT_FAILURE 16
> > > > > WshShell = CreateObject("WScript.Shell")
> > > > > *!* Logevent returns .t. for SUCCESS for .f. for FAILURE
> > > > > ?WshShell.LogEvent(SUCCESS, "Logon Script Completed Successfully")
> > > > > WshShell.LogEvent(ERROR, "Logon Script Completed Successfully")
> > > > > WshShell.LogEvent(WARNING, "We are getting low on disk space!!")
> > > > > WshShell.LogEvent(INFORMATION, "Start nightly backup")
> > > > > WshShell.LogEvent(AUDIT_SUCCESS, "Checksum Success!!")
> > > > > WshShell.LogEvent(AUDIT_FAILURE, "Checksum Failure")
> > > > > WshShell.LogEvent(AUDIT_FAILURE, "Checksum Failure",TARGET_SYSTEM)
> > > > > WshShell=.NULL.

> > > > > This code is from article Q257541 from http://msdn.microsoft.com

> > > > > --
> > > > > Eric den Doop
> > > > > www.foxite.com - The Home Of The Visual FoxPro Experts



> > > > > > Hey guys,

> > > > > > I was wondering if anyone had any code that would log events to
> the
> > NT
> > > > > event
> > > > > > log from Fox. I wrote a VB component that I've been using from
my
> > VFP
> > > > code
> > > > > > that seems to work fine, but I thought if I could find some code
> in
> > > VFP,
> > > > > it
> > > > > > would be nicer to build it directly into my framework. I tried
> > > > converting
> > > > > > the VB code to VFP, but VFP is having trouble accessing the
> > CopyMemory
> > > > API
> > > > > > call. Here's the VB code if you're interested:

> > > > > > MODULE1.BAS

> > > > > > Declare Function RegisterEventSource Lib "advapi32.dll" Alias _
> > > > > >   "RegisterEventSourceA" (ByVal lpUNCServerName As String, _
> > > > > >   ByVal lpSourceName As String) As Long

> > > > > > Declare Function DeregisterEventSource Lib "advapi32.dll" ( _
> > > > > >   ByVal hEventLog As Long) As Long

> > > > > > Declare Function ReportEvent Lib "advapi32.dll" Alias _
> > > > > > "ReportEventA" ( _
> > > > > >   ByVal hEventLog As Long, ByVal wType As Integer, _
> > > > > >   ByVal wCategory As Integer, ByVal dwEventID As Long, _
> > > > > >   ByVal lpUserSid As Any, ByVal wNumStrings As Integer, _
> > > > > >   ByVal dwDataSize As Long, plpStrings As Long, _
> > > > > >   lpRawData As Any) As Boolean

> > > > > > Declare Function GetLastError Lib "kernel32" () As Long

> > > > > > Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
> > > > > >   hpvDest As Any, hpvSource As Any, _
> > > > > >   ByVal cbCopy As Long)

> > > > > > Declare Function GlobalAlloc Lib "kernel32" ( _
> > > > > >    ByVal wFlags As Long, _
> > > > > >    ByVal dwBytes As Long) As Long

> > > > > > Declare Function GlobalFree Lib "kernel32" ( _
> > > > > >    ByVal hMem As Long) As Long

> > > > > > CLASS1.CLS:

> > > > > > Public Enum EventType
> > > > > >     EVENTLOG_SUCCESS = 0
> > > > > >     EVENTLOG_ERROR_TYPE = 1
> > > > > >     EVENTLOG_WARNING_TYPE = 2
> > > > > >     EVENTLOG_INFORMATION_TYPE = 4
> > > > > >     EVENTLOG_AUDIT_SUCCESS = 8
> > > > > >     EVENTLOG_AUDIT_FAILURE = 10
> > > > > > End Enum

> > > > > >   Public Function LogNTEvent(sAppName As String, sMessage As
> String,
> > _
> > > > > >                              iLogType As EventType, iEventID As
> > Long)
> > > > > >         Dim bRC As Boolean
> > > > > >         Dim iNumStrings As Integer
> > > > > >         Dim hEventLog As Long
> > > > > >         Dim hMsgs As Long
> > > > > >         Dim cbStringSize As Long
> > > > > >         Dim bRetVal As Boolean

> > > > > >         bRetVal = True

> > > > > >         hEventLog = RegisterEventSource("", sAppName)
> > > > > >         cbStringSize = Len(sMessage) + 1
> > > > > >         hMsgs = GlobalAlloc(&H40, cbStringSize)
> > > > > >         CopyMemory ByVal hMsgs, ByVal sMessage, cbStringSize
> > > > > >         iNumStrings = 1

> > > > > >         If ReportEvent(hEventLog, iLogType, 0, iEventID, 0&,
> > > > iNumStrings,
> > > > > _
> > > > > >                         cbStringSize, hMsgs, hMsgs) = 0 Then
> > > > > >            bRetVal = False
> > > > > >         End If

> > > > > >         Call GlobalFree(hMsgs)
> > > > > >         DeregisterEventSource (hEventLog)

> > > > > >         LogNTEvent = bRetVal

> > > > > >   End Function

> > > > > > TIA,
> > > > > > -B



Wed, 12 Nov 2003 06:12:33 GMT  
 Logging Events to the NT Event Log from VFP
Christof Lange created a class that handles calls to API functions that
require pointers to simple and complex data types, including structures.

ftp://ftp.prolib.de/public/vfp/struct.zip


Quote:
> Hey guys,

> I was wondering if anyone had any code that would log events to the NT
event
> log from Fox. I wrote a VB component that I've been using from my VFP code
> that seems to work fine, but I thought if I could find some code in VFP,
it
> would be nicer to build it directly into my framework. I tried converting
> the VB code to VFP, but VFP is having trouble accessing the CopyMemory API
> call. Here's the VB code if you're interested:

> MODULE1.BAS

> Declare Function RegisterEventSource Lib "advapi32.dll" Alias _
>   "RegisterEventSourceA" (ByVal lpUNCServerName As String, _
>   ByVal lpSourceName As String) As Long

> Declare Function DeregisterEventSource Lib "advapi32.dll" ( _
>   ByVal hEventLog As Long) As Long

> Declare Function ReportEvent Lib "advapi32.dll" Alias _
> "ReportEventA" ( _
>   ByVal hEventLog As Long, ByVal wType As Integer, _
>   ByVal wCategory As Integer, ByVal dwEventID As Long, _
>   ByVal lpUserSid As Any, ByVal wNumStrings As Integer, _
>   ByVal dwDataSize As Long, plpStrings As Long, _
>   lpRawData As Any) As Boolean

> Declare Function GetLastError Lib "kernel32" () As Long

> Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
>   hpvDest As Any, hpvSource As Any, _
>   ByVal cbCopy As Long)

> Declare Function GlobalAlloc Lib "kernel32" ( _
>    ByVal wFlags As Long, _
>    ByVal dwBytes As Long) As Long

> Declare Function GlobalFree Lib "kernel32" ( _
>    ByVal hMem As Long) As Long

> CLASS1.CLS:

> Public Enum EventType
>     EVENTLOG_SUCCESS = 0
>     EVENTLOG_ERROR_TYPE = 1
>     EVENTLOG_WARNING_TYPE = 2
>     EVENTLOG_INFORMATION_TYPE = 4
>     EVENTLOG_AUDIT_SUCCESS = 8
>     EVENTLOG_AUDIT_FAILURE = 10
> End Enum

>   Public Function LogNTEvent(sAppName As String, sMessage As String, _
>                              iLogType As EventType, iEventID As Long)
>         Dim bRC As Boolean
>         Dim iNumStrings As Integer
>         Dim hEventLog As Long
>         Dim hMsgs As Long
>         Dim cbStringSize As Long
>         Dim bRetVal As Boolean

>         bRetVal = True

>         hEventLog = RegisterEventSource("", sAppName)
>         cbStringSize = Len(sMessage) + 1
>         hMsgs = GlobalAlloc(&H40, cbStringSize)
>         CopyMemory ByVal hMsgs, ByVal sMessage, cbStringSize
>         iNumStrings = 1

>         If ReportEvent(hEventLog, iLogType, 0, iEventID, 0&, iNumStrings,
_
>                         cbStringSize, hMsgs, hMsgs) = 0 Then
>            bRetVal = False
>         End If

>         Call GlobalFree(hMsgs)
>         DeregisterEventSource (hEventLog)

>         LogNTEvent = bRetVal

>   End Function

> TIA,
> -B



Wed, 12 Nov 2003 06:37:45 GMT  
 Logging Events to the NT Event Log from VFP
Hi Beth,

This is from the Universal Thread....  It seems you put the Rtl before the
MoveMemory or CopyMemory and it works fine...Lemme know if that fixes your
problem!

How do I read or write to memory locations May 16, 1999 10:22
The following functions use the API calls RtlMoveMemory() and lstrcpyn() to
allow you to read from or write into memory at a known linear 32 bit
address. Be aware that writing to, and in some cases reading from, an
illegal address (either a memory address that doesn't exist with VFP's
address space, or that the VFP process doesn't have the proper read or write
permission to access) will cause an operating system level error that isn't
trappable within VFP - VFP can and will crash precipitously in these cases.
FUNCTION SetMem
LPARAMETERS tnPtr, tcSource
*  Copy cSource to the memory location specified by nPtr
*  ReDECLARE RtlMoveMemory to make copy parameters easy
*  tnPtr is not validated
DECLARE RtlMoveMemory IN WIN32API AS RtlCopy ;
   INTEGER nDestBuffer, ;

   INTEGER nLength

RtlCopy(tnPtr, ;
        tcSource, ;
        LEN(tcSource))
RETURN .T.

FUNCTION GetMem
LPARAMETERS tnPtr, tnLen
*  Copy the content of a memory block at nPtr for nLen bytes back to a VFP
string
*  Note that we ReDECLARE RtlMoveMemory to make passing things easier
*  tnPtr is not validated
DECLARE RtlMoveMemory IN WIN32API AS RtlCopy ;

   INTEGER pVoidSource, ;
   INTEGER nLength
LOCAL luBuffer
* Allocate a buffer in VFP big enough to receive the block
luBuffer = REPL(CHR(0),tnLen)

         tnPtr, ;
         tnLen)
RETURN luBuffer

FUNCTION GetMemString
LPARAMETERS tnPtr
*  Copy the string at location nPtr into a VFP string
*  We're going to use lstrcpyn rather than RtlMoveMemory to copy up to a
terminating null
*  tnPtr is not validated
DECLARE INTEGER lstrcpyn IN WIN32API AS StrCpyN ;

   INTEGER lpSource, ;
   INTEGER nMaxLength
LOCAL luBuffer
*  Allocate a buffer big enough to receive the data
luBuffer = REPL(CHR(0), 512)

   luBuffer = LEFT(luBuffer, MAX(0,AT(CHR(0),luBuffer) - 1))
ELSE
   luBuffer = NULL
ENDIF
RETURN luBuffer


Quote:
> Actually the problem is in the DECLARE statement in VFP. It was giving me
> the error "Entry Point Not Found". I will check on the UT.

> Thanks,
> -B



> > Is it a structure in the parameters?  If so, try the universalthread for
a
> > structure class that lets you use some structures in VFP.



> > > I did try already. But as I said before, VFP is having trouble
accessing
> > the
> > > CopyMemory function.

> > > -B



> > > > You know VB, so how about a vfp rewrite of the code listed in
Q154576?
> > I'd
> > > > like a copy!

> > > > --
> > > > Eric den Doop
> > > > www.foxite.com - The Home Of The Visual FoxPro Experts



> > > > > Ya, thanks. I saw this one in the KB. I don't like it because you
> > can't
> > > > > control the source name or event ID in the event log and our
> > production
> > > > > support monitoring scans for the name of our application in the
> > source.

> > > > > Thanks,
> > > > > -B



> > > > > > Quick and dirty trick is with the Scripting Host:

> > > > > > #DEFINE TARGET_SYSTEM SUBSTR(SYS(0),1,ATC('#',SYS(0))-1)
> > > > > > #DEFINE SUCCESS 0
> > > > > > #DEFINE ERROR 1
> > > > > > #DEFINE WARNING 2
> > > > > > #DEFINE INFORMATION 4
> > > > > > #DEFINE AUDIT_SUCCESS 8
> > > > > > #DEFINE AUDIT_FAILURE 16
> > > > > > WshShell = CreateObject("WScript.Shell")
> > > > > > *!* Logevent returns .t. for SUCCESS for .f. for FAILURE
> > > > > > ?WshShell.LogEvent(SUCCESS, "Logon Script Completed
Successfully")
> > > > > > WshShell.LogEvent(ERROR, "Logon Script Completed Successfully")
> > > > > > WshShell.LogEvent(WARNING, "We are getting low on disk space!!")
> > > > > > WshShell.LogEvent(INFORMATION, "Start nightly backup")
> > > > > > WshShell.LogEvent(AUDIT_SUCCESS, "Checksum Success!!")
> > > > > > WshShell.LogEvent(AUDIT_FAILURE, "Checksum Failure")
> > > > > > WshShell.LogEvent(AUDIT_FAILURE, "Checksum

Failure",TARGET_SYSTEM)

- Show quoted text -

Quote:
> > > > > > WshShell=.NULL.

> > > > > > This code is from article Q257541 from http://msdn.microsoft.com

> > > > > > --
> > > > > > Eric den Doop
> > > > > > www.foxite.com - The Home Of The Visual FoxPro Experts



> > > > > > > Hey guys,

> > > > > > > I was wondering if anyone had any code that would log events
to
> > the
> > > NT
> > > > > > event
> > > > > > > log from Fox. I wrote a VB component that I've been using from
> my
> > > VFP
> > > > > code
> > > > > > > that seems to work fine, but I thought if I could find some
code
> > in
> > > > VFP,
> > > > > > it
> > > > > > > would be nicer to build it directly into my framework. I tried
> > > > > converting
> > > > > > > the VB code to VFP, but VFP is having trouble accessing the
> > > CopyMemory
> > > > > API
> > > > > > > call. Here's the VB code if you're interested:

> > > > > > > MODULE1.BAS

> > > > > > > Declare Function RegisterEventSource Lib "advapi32.dll" Alias
_
> > > > > > >   "RegisterEventSourceA" (ByVal lpUNCServerName As String, _
> > > > > > >   ByVal lpSourceName As String) As Long

> > > > > > > Declare Function DeregisterEventSource Lib "advapi32.dll" ( _
> > > > > > >   ByVal hEventLog As Long) As Long

> > > > > > > Declare Function ReportEvent Lib "advapi32.dll" Alias _
> > > > > > > "ReportEventA" ( _
> > > > > > >   ByVal hEventLog As Long, ByVal wType As Integer, _
> > > > > > >   ByVal wCategory As Integer, ByVal dwEventID As Long, _
> > > > > > >   ByVal lpUserSid As Any, ByVal wNumStrings As Integer, _
> > > > > > >   ByVal dwDataSize As Long, plpStrings As Long, _
> > > > > > >   lpRawData As Any) As Boolean

> > > > > > > Declare Function GetLastError Lib "kernel32" () As Long

> > > > > > > Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory"
( _
> > > > > > >   hpvDest As Any, hpvSource As Any, _
> > > > > > >   ByVal cbCopy As Long)

> > > > > > > Declare Function GlobalAlloc Lib "kernel32" ( _
> > > > > > >    ByVal wFlags As Long, _
> > > > > > >    ByVal dwBytes As Long) As Long

> > > > > > > Declare Function GlobalFree Lib "kernel32" ( _
> > > > > > >    ByVal hMem As Long) As Long

> > > > > > > CLASS1.CLS:

> > > > > > > Public Enum EventType
> > > > > > >     EVENTLOG_SUCCESS = 0
> > > > > > >     EVENTLOG_ERROR_TYPE = 1
> > > > > > >     EVENTLOG_WARNING_TYPE = 2
> > > > > > >     EVENTLOG_INFORMATION_TYPE = 4
> > > > > > >     EVENTLOG_AUDIT_SUCCESS = 8
> > > > > > >     EVENTLOG_AUDIT_FAILURE = 10
> > > > > > > End Enum

> > > > > > >   Public Function LogNTEvent(sAppName As String, sMessage As
> > String,
> > > _
> > > > > > >                              iLogType As EventType, iEventID
As
> > > Long)
> > > > > > >         Dim bRC As Boolean
> > > > > > >         Dim iNumStrings As Integer
> > > > > > >         Dim hEventLog As Long
> > > > > > >         Dim hMsgs As Long
> > > > > > >         Dim cbStringSize As Long
> > > > > > >         Dim bRetVal As Boolean

> > > > > > >         bRetVal = True

> > > > > > >         hEventLog = RegisterEventSource("", sAppName)
> > > > > > >         cbStringSize = Len(sMessage) + 1
> > > > > > >         hMsgs = GlobalAlloc(&H40, cbStringSize)
> > > > > > >         CopyMemory ByVal hMsgs, ByVal sMessage, cbStringSize
> > > > > > >         iNumStrings = 1

> > > > > > >         If ReportEvent(hEventLog, iLogType, 0, iEventID, 0&,
> > > > > iNumStrings,
> > > > > > _
> > > > > > >                         cbStringSize, hMsgs, hMsgs) = 0 Then
> > > > > > >            bRetVal = False
> > > > > > >         End If

> > > > > > >         Call GlobalFree(hMsgs)
> > > > > > >         DeregisterEventSource (hEventLog)

> > > > > > >         LogNTEvent = bRetVal

> > > > > > >   End Function

> > > > > > > TIA,
> > > > > > > -B

begin 666 next.gif

M\/SR[_KMZ/KKYOKJY?GGX??AV?;:T?76S/31QO+*O?'(NO'&N/##M.VWI>FE

M)-!!$L] $,\_#\X]#,PS````````````````````````````````````````
M`````````````````````````````````"'Y! $`````+ `````*``H```8A

%,C P`#L`
`
end


Wed, 12 Nov 2003 06:36:21 GMT  
 Logging Events to the NT Event Log from VFP
*******
first, the ALIAS keyword in VB means something totally different than in VFP
*******

~doc reference~

When working with Windows API procedures that use strings, you'll need to
add an Alias clause to your declare statements to specify the correct
character set. Windows API functions that contain strings actually exist in
two formats: ANSI and Unicode. In the Windows header files, therefore,
you'll get both ANSI and Unicode versions of each function that contains a
string.
For example, following are the two C-language descriptions for the
SetWindowText function. You'll note that the first description defines the
function as SetWindowTextA, where the trailing "A" identifies it as an ANSI
function:

WINUSERAPI
BOOL
WINAPI
SetWindowTextA(
   HWND hWnd,
   LPCSTR lpString);

The second description defines it as SetWindowTextW, where the trailing "W"
identifies it as a wide, or Unicode function:

WINUSERAPI
BOOL
WINAPI
SetWindowTextW(
   HWND hWnd,
   LPCWSTR lpString);

Because neither function is actually named "SetWindowText," you need to add
an Alias clause to the declare to point to the function you want to
reference

**************
the  CopyMemory API funtion doesn't really exist, here is some excerpts from
the docs...
**************

~doc reference~
CopyMemory: A Strange and Terrible Saga
Experienced Basic API programmers have come to know, if not love, the
hmemcpy function. When C's weak data typing and Basic's strong data typing
meet in the Windows API, hmemcpy is frequently called on to mediate. The h
in the name indicates that hmemcpy can handle huge memory (greater than 64K
bytes), but Basic programmers rarely need it for such large chunks.
Unfortunately, if you look for hmemcpy in the Win32 documentation, you'll
come up with nothing - not even a note saying that the function is obsolete.

But you might happen to run across the Win32 CopyMemory function, which has
exactly the same arguments and in fact looks like the same procedure. The h
has disappeared because all memory in 32-bit mode is huge. If you write a
Declare statement for CopyMemory, however, giving KERNEL32.DLL as the most
likely library, you'll get nothing but an error indicating that no such
function exists. In fact, you can search all the 32-bit DLLs with the
DumpBin utility, but you won't find any containing CopyMemory.

But a careful search of Win32 C include files turns up the following in
WINBASE.H:

   #define CopyMemory RtlCopyMemory
   #define MoveMemory RtlMoveMemory
   #define ZeroMemory RtlZeroMemory

This C equivalent of an alias indicates that CopyMemory is another name for
a function called RtlCopyMemory. Don't ask why; just check for RtlCopyMemory
in KERNEL32.DLL.

Again, nothing. A little more sleuthing in Win32 include files reveals the
reason. WINNT.H contains something like this:

   #define RtlCopyMemory(dst, src, len) memcpy(dst, src, len)

In other words, RtlCopyMemory is an alias for the C memcpy function, but you
can't use memcpy or any other C library function from Basic. If it's not
exported from a DLL, you can't call it.

But KERNEL32.DLL does contain an entry for RtlMoveMemory. If you check the
Win32 documentation, you'll see that MoveMemory does the same thing as
CopyMemory except that it handles overlapped memory differently. I can't
imagine a situation in which a Basic programmer would be copying overlapped
memory. No reason not to use MoveMemory instead. Because CopyMemory is more
intelligible than hmemcpy, I alias this name for both 16-bit and 32-bit
versions:


Quote:
> Hey guys,

> I was wondering if anyone had any code that would log events to the NT
event
> log from Fox. I wrote a VB component that I've been using from my VFP code
> that seems to work fine, but I thought if I could find some code in VFP,
it
> would be nicer to build it directly into my framework. I tried converting
> the VB code to VFP, but VFP is having trouble accessing the CopyMemory API
> call. Here's the VB code if you're interested:

> MODULE1.BAS

> Declare Function RegisterEventSource Lib "advapi32.dll" Alias _
>   "RegisterEventSourceA" (ByVal lpUNCServerName As String, _
>   ByVal lpSourceName As String) As Long

> Declare Function DeregisterEventSource Lib "advapi32.dll" ( _
>   ByVal hEventLog As Long) As Long

> Declare Function ReportEvent Lib "advapi32.dll" Alias _
> "ReportEventA" ( _
>   ByVal hEventLog As Long, ByVal wType As Integer, _
>   ByVal wCategory As Integer, ByVal dwEventID As Long, _
>   ByVal lpUserSid As Any, ByVal wNumStrings As Integer, _
>   ByVal dwDataSize As Long, plpStrings As Long, _
>   lpRawData As Any) As Boolean

> Declare Function GetLastError Lib "kernel32" () As Long

> Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
>   hpvDest As Any, hpvSource As Any, _
>   ByVal cbCopy As Long)

> Declare Function GlobalAlloc Lib "kernel32" ( _
>    ByVal wFlags As Long, _
>    ByVal dwBytes As Long) As Long

> Declare Function GlobalFree Lib "kernel32" ( _
>    ByVal hMem As Long) As Long

> CLASS1.CLS:

> Public Enum EventType
>     EVENTLOG_SUCCESS = 0
>     EVENTLOG_ERROR_TYPE = 1
>     EVENTLOG_WARNING_TYPE = 2
>     EVENTLOG_INFORMATION_TYPE = 4
>     EVENTLOG_AUDIT_SUCCESS = 8
>     EVENTLOG_AUDIT_FAILURE = 10
> End Enum

>   Public Function LogNTEvent(sAppName As String, sMessage As String, _
>                              iLogType As EventType, iEventID As Long)
>         Dim bRC As Boolean
>         Dim iNumStrings As Integer
>         Dim hEventLog As Long
>         Dim hMsgs As Long
>         Dim cbStringSize As Long
>         Dim bRetVal As Boolean

>         bRetVal = True

>         hEventLog = RegisterEventSource("", sAppName)
>         cbStringSize = Len(sMessage) + 1
>         hMsgs = GlobalAlloc(&H40, cbStringSize)
>         CopyMemory ByVal hMsgs, ByVal sMessage, cbStringSize
>         iNumStrings = 1

>         If ReportEvent(hEventLog, iLogType, 0, iEventID, 0&, iNumStrings,
_
>                         cbStringSize, hMsgs, hMsgs) = 0 Then
>            bRetVal = False
>         End If

>         Call GlobalFree(hMsgs)
>         DeregisterEventSource (hEventLog)

>         LogNTEvent = bRetVal

>   End Function

> TIA,
> -B



Wed, 12 Nov 2003 19:54:13 GMT  
 Logging Events to the NT Event Log from VFP
here is a sample of how the event log can be written to via VFP
HTH

*// port of Write to the Windows NT Event Log from Visual Basic into VFP
*// from MS KB artical Q154576

#define GMEM_ZEROINIT           0x0040   && flag for GlobalAlloc() to
initialize memory to zero
#define EVENTLOG_SUCCESS        0
#define EVENTLOG_ERROR_TYPE     1
#define EVENTLOG_WARNING_TYPE    2
#define EVENTLOG_INFORMATION_TYPE   4
#define EVENTLOG_AUDIT_SUCCESS    8
#define EVENTLOG_AUDIT_FAILURE    10

* sample function calls
 cApplicationName = "VFP IDE"
 LogNTEvent("Information from " + cApplicationName,
EVENTLOG_INFORMATION_TYPE, 1001)
 LogNTEvent("Warning from "   + cApplicationName, EVENTLOG_WARNING_TYPE,
1002)
 LogNTEvent("Error from "    + cApplicationName, EVENTLOG_ERROR_TYPE, 1003)

FUNCTION LogNTEvent(sString, iLogType, iEventID)

 *// define constant for error handler routine
 #define MB_ICONINFORMATION      64      && Information message
 #define MB_OK                   0       && OK button only
 #define CR             CHR(13) && Carriage Return
 #define ERROR_SUCCESS          0  && Success error code from WINERROR.H
 #define FORMAT_MESSAGE_FROM_SYSTEM  0x00001000 && Value for use with
FormatMessage API. From WINBASE.H

  *// declare API dll's
    *-registers an application as an event source, if you create message
files
    *-this has to be the name you registered in the system registry
      declare long RegisterEventSource in ADVAPI32.DLL ;
          string lpUNCServerName, string lpSourceName

   *- this is obvious
      declare long DeregisterEventSource in ADVAPI32.DLL ;
           long hEventLog

      *- this is the function that writes to the event log
      declare integer ReportEvent in ADVAPI32.DLL ;
        integer hEventLog, integer wType, integer wCategory, ;
        integer dwEventID, integer lpUserSid, integer wNumStrings, ;
        integer dwDataSize, integer plpStrings, integer lpRawData

      *-error handler routines
      declare long GetLastError in KERNEL32.DLL

   *-function to return text message from system error code.
   declare integer FormatMessage IN kernel32.DLL ;


    integer Arguments

   *-this was a little puzzling in the VB call, but this is
   *- how to implement it in VFP
   declare RtlMoveMemory in WIN32API as CopyMemory ;
     integer , string , integer

      *- memory handling routines
      declare long GlobalAlloc in KERNEL32.DLL ;
        long , long

      declare long GlobalFree in KERNEL32.DLL ;
         long

 *// declare local vars
 local sString, iLogType, iEventID, ;
   iNumStrings, hEventLog, cbStringSize, ;
   lpUserSid, lnReturnCode, lpStrings, lpRawData

 *// initialize local vars

  *-length of binary data
   cbStringSize = 0

   *-string count
  iNumStrings = 1

  *-user security Id, not implemented!
  lpUserSid = 0

  * category for the message, only used if you create message file
  wCategory = 0

  *-pointer to the message buffer, limit of 32K characters
  lpStrings  = 0

  *-pointer to the raw data (binary) buffer
  lpRawData = 0

   *// register the application as the event source
   hEventLog = RegisterEventSource("", sString)

    cbStringSize = Len(sString) + 1

    *// this creates a pointer to a contiguous block of memory of nBytes
long
    lpStrings = GlobalAlloc(GMEM_ZEROINIT, cbStringSize)

  *// copy the data to the block of memory for use by the Api call
    CopyMemory(lpStrings , sString, cbStringSize)

   lpRawData = lpStrings

  *// make the log entry
   lnReturnCode = ReportEvent(hEventLog, iLogType, wCategory, ;
                  iEventID, lpUserSid, 0, ;
                  cbStringSize, lpStrings, lpRawData)

  *// this error handler is for debugging only
  IF lnReturnCode =  0
   lpBuffer  = SPACE(128)
   lnError = GetLastError()
   =FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, ;

   =MESSAGEBOX("System error has occurred." + CR + ;
    "System Error code: " + ALLTRIM(STR(lnError)) + CR + ;
    "System Error message:
"+ALLT(lpBuffer),MB_ICONINFORMATION+MB_OK,"ERROR")
  ENDIF

    *//release the memory used for the pointer
    GlobalFree(lpStrings)

    *// finally unregister the app as the source
    DeregisterEventSource (hEventLog)

return lnReturnCode


Quote:
> *******
> first, the ALIAS keyword in VB means something totally different than in
VFP
> *******

> ~doc reference~

> When working with Windows API procedures that use strings, you'll need to
> add an Alias clause to your declare statements to specify the correct
> character set. Windows API functions that contain strings actually exist
in
> two formats: ANSI and Unicode. In the Windows header files, therefore,
> you'll get both ANSI and Unicode versions of each function that contains a
> string.
> For example, following are the two C-language descriptions for the
> SetWindowText function. You'll note that the first description defines the
> function as SetWindowTextA, where the trailing "A" identifies it as an
ANSI
> function:

> WINUSERAPI
> BOOL
> WINAPI
> SetWindowTextA(
>    HWND hWnd,
>    LPCSTR lpString);

> The second description defines it as SetWindowTextW, where the trailing
"W"
> identifies it as a wide, or Unicode function:

> WINUSERAPI
> BOOL
> WINAPI
> SetWindowTextW(
>    HWND hWnd,
>    LPCWSTR lpString);

> Because neither function is actually named "SetWindowText," you need to
add
> an Alias clause to the declare to point to the function you want to
> reference

> **************
> the  CopyMemory API funtion doesn't really exist, here is some excerpts
from
> the docs...
> **************

> ~doc reference~
> CopyMemory: A Strange and Terrible Saga
> Experienced Basic API programmers have come to know, if not love, the
> hmemcpy function. When C's weak data typing and Basic's strong data typing
> meet in the Windows API, hmemcpy is frequently called on to mediate. The h
> in the name indicates that hmemcpy can handle huge memory (greater than
64K
> bytes), but Basic programmers rarely need it for such large chunks.
> Unfortunately, if you look for hmemcpy in the Win32 documentation, you'll
> come up with nothing - not even a note saying that the function is
obsolete.

> But you might happen to run across the Win32 CopyMemory function, which
has
> exactly the same arguments and in fact looks like the same procedure. The
h
> has disappeared because all memory in 32-bit mode is huge. If you write a
> Declare statement for CopyMemory, however, giving KERNEL32.DLL as the most
> likely library, you'll get nothing but an error indicating that no such
> function exists. In fact, you can search all the 32-bit DLLs with the
> DumpBin utility, but you won't find any containing CopyMemory.

> But a careful search of Win32 C include files turns up the following in
> WINBASE.H:

>    #define CopyMemory RtlCopyMemory
>    #define MoveMemory RtlMoveMemory
>    #define ZeroMemory RtlZeroMemory

> This C equivalent of an alias indicates that CopyMemory is another name
for
> a function called RtlCopyMemory. Don't ask why; just check for
RtlCopyMemory
> in KERNEL32.DLL.

> Again, nothing. A little more sleuthing in Win32 include files reveals the
> reason. WINNT.H contains something like this:

>    #define RtlCopyMemory(dst, src, len) memcpy(dst, src, len)

> In other words, RtlCopyMemory is an alias for the C memcpy function, but
you
> can't use memcpy or any other C library function from Basic. If it's not
> exported from a DLL, you can't call it.

> But KERNEL32.DLL does contain an entry for RtlMoveMemory. If you check the
> Win32 documentation, you'll see that MoveMemory does the same thing as
> CopyMemory except that it handles overlapped memory differently. I can't
> imagine a situation in which a Basic programmer would be copying
overlapped
> memory. No reason not to use MoveMemory instead. Because CopyMemory is
more
> intelligible than hmemcpy, I alias this name for both 16-bit and 32-bit
> versions:



> > Hey guys,

> > I was wondering if anyone had any code that would log events to the NT
> event
> > log from Fox. I wrote a VB component that I've been using from my VFP
code
> > that seems to work fine, but I thought if I could find some code in VFP,
> it
> > would be nicer to build it directly into my framework. I tried
converting
> > the VB code to VFP, but VFP is having trouble accessing the CopyMemory
API
> > call. Here's the VB code if you're interested:

> > MODULE1.BAS

> > Declare Function RegisterEventSource Lib "advapi32.dll" Alias _
> >   "RegisterEventSourceA" (ByVal lpUNCServerName As String, _
> >   ByVal lpSourceName As String) As Long

> > Declare Function DeregisterEventSource Lib "advapi32.dll" ( _
> >   ByVal hEventLog As Long) As Long

> > Declare Function ReportEvent Lib "advapi32.dll" Alias _
> > "ReportEventA" ( _
> >   ByVal hEventLog As Long, ByVal wType As Integer, _
> >   ByVal wCategory As Integer, ByVal dwEventID As Long, _
> >   ByVal lpUserSid As Any, ByVal wNumStrings As Integer, _
> >   ByVal dwDataSize As Long, plpStrings As Long, _
> >   lpRawData As Any) As Boolean

> > Declare Function GetLastError Lib "kernel32" () As Long

> > Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
> >   hpvDest As Any, hpvSource As Any, _
> >   ByVal cbCopy As Long)

> > Declare Function GlobalAlloc Lib "kernel32" ( _
> >    ByVal wFlags As Long, _
> >    ByVal dwBytes As Long) As Long

> > Declare Function GlobalFree Lib "kernel32" ( _
> >    ByVal hMem As Long) As Long

> > CLASS1.CLS:

> > Public Enum EventType
> >     EVENTLOG_SUCCESS = 0
> >     EVENTLOG_ERROR_TYPE = 1

...

read more »



Wed, 12 Nov 2003 22:09:39 GMT  
 Logging Events to the NT Event Log from VFP
Thanks Gene, that did the trick. I definately had that particular declare
statement wrong.

Thanks again,
-B


Quote:
> here is a sample of how the event log can be written to via VFP
> HTH

> *// port of Write to the Windows NT Event Log from Visual Basic into VFP
> *// from MS KB artical Q154576

> #define GMEM_ZEROINIT           0x0040   && flag for GlobalAlloc() to
> initialize memory to zero
> #define EVENTLOG_SUCCESS        0
> #define EVENTLOG_ERROR_TYPE     1
> #define EVENTLOG_WARNING_TYPE    2
> #define EVENTLOG_INFORMATION_TYPE   4
> #define EVENTLOG_AUDIT_SUCCESS    8
> #define EVENTLOG_AUDIT_FAILURE    10

> * sample function calls
>  cApplicationName = "VFP IDE"
>  LogNTEvent("Information from " + cApplicationName,
> EVENTLOG_INFORMATION_TYPE, 1001)
>  LogNTEvent("Warning from "   + cApplicationName, EVENTLOG_WARNING_TYPE,
> 1002)
>  LogNTEvent("Error from "    + cApplicationName, EVENTLOG_ERROR_TYPE,
1003)

> FUNCTION LogNTEvent(sString, iLogType, iEventID)

>  *// define constant for error handler routine
>  #define MB_ICONINFORMATION      64      && Information message
>  #define MB_OK                   0       && OK button only
>  #define CR             CHR(13) && Carriage Return
>  #define ERROR_SUCCESS          0  && Success error code from WINERROR.H
>  #define FORMAT_MESSAGE_FROM_SYSTEM  0x00001000 && Value for use with
> FormatMessage API. From WINBASE.H

>   *// declare API dll's
>     *-registers an application as an event source, if you create message
> files
>     *-this has to be the name you registered in the system registry
>       declare long RegisterEventSource in ADVAPI32.DLL ;
>           string lpUNCServerName, string lpSourceName

>    *- this is obvious
>       declare long DeregisterEventSource in ADVAPI32.DLL ;
>            long hEventLog

>       *- this is the function that writes to the event log
>       declare integer ReportEvent in ADVAPI32.DLL ;
>         integer hEventLog, integer wType, integer wCategory, ;
>         integer dwEventID, integer lpUserSid, integer wNumStrings, ;
>         integer dwDataSize, integer plpStrings, integer lpRawData

>       *-error handler routines
>       declare long GetLastError in KERNEL32.DLL

>    *-function to return text message from system error code.
>    declare integer FormatMessage IN kernel32.DLL ;


>     integer Arguments

>    *-this was a little puzzling in the VB call, but this is
>    *- how to implement it in VFP
>    declare RtlMoveMemory in WIN32API as CopyMemory ;
>      integer , string , integer

>       *- memory handling routines
>       declare long GlobalAlloc in KERNEL32.DLL ;
>         long , long

>       declare long GlobalFree in KERNEL32.DLL ;
>          long

>  *// declare local vars
>  local sString, iLogType, iEventID, ;
>    iNumStrings, hEventLog, cbStringSize, ;
>    lpUserSid, lnReturnCode, lpStrings, lpRawData

>  *// initialize local vars

>   *-length of binary data
>    cbStringSize = 0

>    *-string count
>   iNumStrings = 1

>   *-user security Id, not implemented!
>   lpUserSid = 0

>   * category for the message, only used if you create message file
>   wCategory = 0

>   *-pointer to the message buffer, limit of 32K characters
>   lpStrings  = 0

>   *-pointer to the raw data (binary) buffer
>   lpRawData = 0

>    *// register the application as the event source
>    hEventLog = RegisterEventSource("", sString)

>     cbStringSize = Len(sString) + 1

>     *// this creates a pointer to a contiguous block of memory of nBytes
> long
>     lpStrings = GlobalAlloc(GMEM_ZEROINIT, cbStringSize)

>   *// copy the data to the block of memory for use by the Api call
>     CopyMemory(lpStrings , sString, cbStringSize)

>    lpRawData = lpStrings

>   *// make the log entry
>    lnReturnCode = ReportEvent(hEventLog, iLogType, wCategory, ;
>                   iEventID, lpUserSid, 0, ;
>                   cbStringSize, lpStrings, lpRawData)

>   *// this error handler is for debugging only
>   IF lnReturnCode =  0
>    lpBuffer  = SPACE(128)
>    lnError = GetLastError()
>    =FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, ;

>    =MESSAGEBOX("System error has occurred." + CR + ;
>     "System Error code: " + ALLTRIM(STR(lnError)) + CR + ;
>     "System Error message:
> "+ALLT(lpBuffer),MB_ICONINFORMATION+MB_OK,"ERROR")
>   ENDIF

>     *//release the memory used for the pointer
>     GlobalFree(lpStrings)

>     *// finally unregister the app as the source
>     DeregisterEventSource (hEventLog)

> return lnReturnCode



> > *******
> > first, the ALIAS keyword in VB means something totally different than in
> VFP
> > *******

> > ~doc reference~

> > When working with Windows API procedures that use strings, you'll need
to
> > add an Alias clause to your declare statements to specify the correct
> > character set. Windows API functions that contain strings actually exist
> in
> > two formats: ANSI and Unicode. In the Windows header files, therefore,
> > you'll get both ANSI and Unicode versions of each function that contains
a
> > string.
> > For example, following are the two C-language descriptions for the
> > SetWindowText function. You'll note that the first description defines
the
> > function as SetWindowTextA, where the trailing "A" identifies it as an
> ANSI
> > function:

> > WINUSERAPI
> > BOOL
> > WINAPI
> > SetWindowTextA(
> >    HWND hWnd,
> >    LPCSTR lpString);

> > The second description defines it as SetWindowTextW, where the trailing
> "W"
> > identifies it as a wide, or Unicode function:

> > WINUSERAPI
> > BOOL
> > WINAPI
> > SetWindowTextW(
> >    HWND hWnd,
> >    LPCWSTR lpString);

> > Because neither function is actually named "SetWindowText," you need to
> add
> > an Alias clause to the declare to point to the function you want to
> > reference

> > **************
> > the  CopyMemory API funtion doesn't really exist, here is some excerpts
> from
> > the docs...
> > **************

> > ~doc reference~
> > CopyMemory: A Strange and Terrible Saga
> > Experienced Basic API programmers have come to know, if not love, the
> > hmemcpy function. When C's weak data typing and Basic's strong data
typing
> > meet in the Windows API, hmemcpy is frequently called on to mediate. The
h
> > in the name indicates that hmemcpy can handle huge memory (greater than
> 64K
> > bytes), but Basic programmers rarely need it for such large chunks.
> > Unfortunately, if you look for hmemcpy in the Win32 documentation,
you'll
> > come up with nothing - not even a note saying that the function is
> obsolete.

> > But you might happen to run across the Win32 CopyMemory function, which
> has
> > exactly the same arguments and in fact looks like the same procedure.
The
> h
> > has disappeared because all memory in 32-bit mode is huge. If you write
a
> > Declare statement for CopyMemory, however, giving KERNEL32.DLL as the
most
> > likely library, you'll get nothing but an error indicating that no such
> > function exists. In fact, you can search all the 32-bit DLLs with the
> > DumpBin utility, but you won't find any containing CopyMemory.

> > But a careful search of Win32 C include files turns up the following in
> > WINBASE.H:

> >    #define CopyMemory RtlCopyMemory
> >    #define MoveMemory RtlMoveMemory
> >    #define ZeroMemory RtlZeroMemory

> > This C equivalent of an alias indicates that CopyMemory is another name
> for
> > a function called RtlCopyMemory. Don't ask why; just check for
> RtlCopyMemory
> > in KERNEL32.DLL.

> > Again, nothing. A little more sleuthing in Win32 include files reveals
the
> > reason. WINNT.H contains something like this:

> >    #define RtlCopyMemory(dst, src, len) memcpy(dst, src, len)

> > In other words, RtlCopyMemory is an alias for the C memcpy function, but
> you
> > can't use memcpy or any other C library function from Basic. If it's not
> > exported from a DLL, you can't call it.

> > But KERNEL32.DLL does contain an entry for RtlMoveMemory. If you check
the
> > Win32 documentation, you'll see that MoveMemory does the same thing as
> > CopyMemory except that it handles overlapped memory differently. I can't
> > imagine a situation in which a Basic programmer would be copying
> overlapped
> > memory. No reason not to use MoveMemory instead. Because CopyMemory is
> more
> > intelligible than hmemcpy, I alias this name for both 16-bit and 32-bit
> > versions:



> > > Hey guys,

> > > I was wondering if anyone had any code that would log events to the NT
> > event
> > > log from Fox. I wrote a VB component that I've been using from my VFP
> code
> > > that seems to work fine, but I thought if I could find some code in
VFP,
> > it
> > > would be nicer to build it directly into my framework. I tried
> converting
> > > the VB code to VFP, but VFP is having trouble accessing the CopyMemory
> API
> > > call. Here's the VB code if you're interested:

> > > MODULE1.BAS

> > > Declare Function RegisterEventSource Lib "advapi32.dll" Alias _
> > >   "RegisterEventSourceA" (ByVal lpUNCServerName As String, _
> > >   ByVal lpSourceName As String) As Long

> > > Declare Function DeregisterEventSource Lib "advapi32.dll" ( _
> > >   ByVal hEventLog As Long) As Long

> > > Declare Function ReportEvent Lib "advapi32.dll" Alias _
> > > "ReportEventA" ( _
> > >   ByVal hEventLog As Long, ByVal wType As Integer, _
> > >   ByVal wCategory As Integer,

...

read more »



Sun, 16 Nov 2003 01:29:16 GMT  
 Logging Events to the NT Event Log from VFP
Hi Gene,

Thanks for your code. It does seem to work except that the Error message is
not being written, just the application name. I notice that you set
iNumstrings to 1 and then never send it into ReportEvent, instead you send a
0. So it seemed that was the issue, however, when I send the iNumstrings set
to 1 into ReportEvent, I get an error.

iNumstrings = 1
lnReturnCode = ReportEvent(hEventLog, iLogType, wCategory, ;
                  iEventID, lpUserSid, iNumStrings, ;
                  cbStringSize, lpStrings, lpRawData)

This doesn't run. Any ideas?

TIA,
-B


Quote:
> here is a sample of how the event log can be written to via VFP
> HTH

> *// port of Write to the Windows NT Event Log from Visual Basic into VFP
> *// from MS KB artical Q154576

> #define GMEM_ZEROINIT           0x0040   && flag for GlobalAlloc() to
> initialize memory to zero
> #define EVENTLOG_SUCCESS        0
> #define EVENTLOG_ERROR_TYPE     1
> #define EVENTLOG_WARNING_TYPE    2
> #define EVENTLOG_INFORMATION_TYPE   4
> #define EVENTLOG_AUDIT_SUCCESS    8
> #define EVENTLOG_AUDIT_FAILURE    10

> * sample function calls
>  cApplicationName = "VFP IDE"
>  LogNTEvent("Information from " + cApplicationName,
> EVENTLOG_INFORMATION_TYPE, 1001)
>  LogNTEvent("Warning from "   + cApplicationName, EVENTLOG_WARNING_TYPE,
> 1002)
>  LogNTEvent("Error from "    + cApplicationName, EVENTLOG_ERROR_TYPE,
1003)

> FUNCTION LogNTEvent(sString, iLogType, iEventID)

>  *// define constant for error handler routine
>  #define MB_ICONINFORMATION      64      && Information message
>  #define MB_OK                   0       && OK button only
>  #define CR             CHR(13) && Carriage Return
>  #define ERROR_SUCCESS          0  && Success error code from WINERROR.H
>  #define FORMAT_MESSAGE_FROM_SYSTEM  0x00001000 && Value for use with
> FormatMessage API. From WINBASE.H

>   *// declare API dll's
>     *-registers an application as an event source, if you create message
> files
>     *-this has to be the name you registered in the system registry
>       declare long RegisterEventSource in ADVAPI32.DLL ;
>           string lpUNCServerName, string lpSourceName

>    *- this is obvious
>       declare long DeregisterEventSource in ADVAPI32.DLL ;
>            long hEventLog

>       *- this is the function that writes to the event log
>       declare integer ReportEvent in ADVAPI32.DLL ;
>         integer hEventLog, integer wType, integer wCategory, ;
>         integer dwEventID, integer lpUserSid, integer wNumStrings, ;
>         integer dwDataSize, integer plpStrings, integer lpRawData

>       *-error handler routines
>       declare long GetLastError in KERNEL32.DLL

>    *-function to return text message from system error code.
>    declare integer FormatMessage IN kernel32.DLL ;


>     integer Arguments

>    *-this was a little puzzling in the VB call, but this is
>    *- how to implement it in VFP
>    declare RtlMoveMemory in WIN32API as CopyMemory ;
>      integer , string , integer

>       *- memory handling routines
>       declare long GlobalAlloc in KERNEL32.DLL ;
>         long , long

>       declare long GlobalFree in KERNEL32.DLL ;
>          long

>  *// declare local vars
>  local sString, iLogType, iEventID, ;
>    iNumStrings, hEventLog, cbStringSize, ;
>    lpUserSid, lnReturnCode, lpStrings, lpRawData

>  *// initialize local vars

>   *-length of binary data
>    cbStringSize = 0

>    *-string count
>   iNumStrings = 1

>   *-user security Id, not implemented!
>   lpUserSid = 0

>   * category for the message, only used if you create message file
>   wCategory = 0

>   *-pointer to the message buffer, limit of 32K characters
>   lpStrings  = 0

>   *-pointer to the raw data (binary) buffer
>   lpRawData = 0

>    *// register the application as the event source
>    hEventLog = RegisterEventSource("", sString)

>     cbStringSize = Len(sString) + 1

>     *// this creates a pointer to a contiguous block of memory of nBytes
> long
>     lpStrings = GlobalAlloc(GMEM_ZEROINIT, cbStringSize)

>   *// copy the data to the block of memory for use by the Api call
>     CopyMemory(lpStrings , sString, cbStringSize)

>    lpRawData = lpStrings

>   *// make the log entry
>    lnReturnCode = ReportEvent(hEventLog, iLogType, wCategory, ;
>                   iEventID, lpUserSid, 0, ;
>                   cbStringSize, lpStrings, lpRawData)

>   *// this error handler is for debugging only
>   IF lnReturnCode =  0
>    lpBuffer  = SPACE(128)
>    lnError = GetLastError()
>    =FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, ;

>    =MESSAGEBOX("System error has occurred." + CR + ;
>     "System Error code: " + ALLTRIM(STR(lnError)) + CR + ;
>     "System Error message:
> "+ALLT(lpBuffer),MB_ICONINFORMATION+MB_OK,"ERROR")
>   ENDIF

>     *//release the memory used for the pointer
>     GlobalFree(lpStrings)

>     *// finally unregister the app as the source
>     DeregisterEventSource (hEventLog)

> return lnReturnCode



> > *******
> > first, the ALIAS keyword in VB means something totally different than in
> VFP
> > *******

> > ~doc reference~

> > When working with Windows API procedures that use strings, you'll need
to
> > add an Alias clause to your declare statements to specify the correct
> > character set. Windows API functions that contain strings actually exist
> in
> > two formats: ANSI and Unicode. In the Windows header files, therefore,
> > you'll get both ANSI and Unicode versions of each function that contains
a
> > string.
> > For example, following are the two C-language descriptions for the
> > SetWindowText function. You'll note that the first description defines
the
> > function as SetWindowTextA, where the trailing "A" identifies it as an
> ANSI
> > function:

> > WINUSERAPI
> > BOOL
> > WINAPI
> > SetWindowTextA(
> >    HWND hWnd,
> >    LPCSTR lpString);

> > The second description defines it as SetWindowTextW, where the trailing
> "W"
> > identifies it as a wide, or Unicode function:

> > WINUSERAPI
> > BOOL
> > WINAPI
> > SetWindowTextW(
> >    HWND hWnd,
> >    LPCWSTR lpString);

> > Because neither function is actually named "SetWindowText," you need to
> add
> > an Alias clause to the declare to point to the function you want to
> > reference

> > **************
> > the  CopyMemory API funtion doesn't really exist, here is some excerpts
> from
> > the docs...
> > **************

> > ~doc reference~
> > CopyMemory: A Strange and Terrible Saga
> > Experienced Basic API programmers have come to know, if not love, the
> > hmemcpy function. When C's weak data typing and Basic's strong data
typing
> > meet in the Windows API, hmemcpy is frequently called on to mediate. The
h
> > in the name indicates that hmemcpy can handle huge memory (greater than
> 64K
> > bytes), but Basic programmers rarely need it for such large chunks.
> > Unfortunately, if you look for hmemcpy in the Win32 documentation,
you'll
> > come up with nothing - not even a note saying that the function is
> obsolete.

> > But you might happen to run across the Win32 CopyMemory function, which
> has
> > exactly the same arguments and in fact looks like the same procedure.
The
> h
> > has disappeared because all memory in 32-bit mode is huge. If you write
a
> > Declare statement for CopyMemory, however, giving KERNEL32.DLL as the
most
> > likely library, you'll get nothing but an error indicating that no such
> > function exists. In fact, you can search all the 32-bit DLLs with the
> > DumpBin utility, but you won't find any containing CopyMemory.

> > But a careful search of Win32 C include files turns up the following in
> > WINBASE.H:

> >    #define CopyMemory RtlCopyMemory
> >    #define MoveMemory RtlMoveMemory
> >    #define ZeroMemory RtlZeroMemory

> > This C equivalent of an alias indicates that CopyMemory is another name
> for
> > a function called RtlCopyMemory. Don't ask why; just check for
> RtlCopyMemory
> > in KERNEL32.DLL.

> > Again, nothing. A little more sleuthing in Win32 include files reveals
the
> > reason. WINNT.H contains something like this:

> >    #define RtlCopyMemory(dst, src, len) memcpy(dst, src, len)

> > In other words, RtlCopyMemory is an alias for the C memcpy function, but
> you
> > can't use memcpy or any other C library function from Basic. If it's not
> > exported from a DLL, you can't call it.

> > But KERNEL32.DLL does contain an entry for RtlMoveMemory. If you check
the
> > Win32 documentation, you'll see that MoveMemory does the same thing as
> > CopyMemory except that it handles overlapped memory differently. I can't
> > imagine a situation in which a Basic programmer would be copying
> overlapped
> > memory. No reason not to use MoveMemory instead. Because CopyMemory is
> more
> > intelligible than hmemcpy, I alias this name for both 16-bit and 32-bit
> > versions:



> > > Hey guys,

> > > I was wondering if anyone had any code that would log events to the NT
> > event
> > > log from Fox. I wrote a VB component that I've been using from my VFP
> code
> > > that seems to work fine, but I thought if I could find some code in
VFP,
> > it
> > > would be nicer to build it directly into my framework. I tried
> converting
> > > the VB code to VFP, but VFP is having trouble accessing the CopyMemory
> API
> > > call. Here's the VB code if you're interested:

> > > MODULE1.BAS

> > > Declare Function

...

read more »



Sun, 16 Nov 2003 03:36:05 GMT  
 Logging Events to the NT Event Log from VFP
I'm running into the same problem.  My code uses HeapCreate/HeapDestroy
which is recommended over GlobalAlloc/GlobalFree.

***test.prg
nEType = 2
nEventID = 1000
nUserID = 0
cMsg = 'Something happened' + CHR(0)

? Report_Event(cMsg, 'My Application', nEType, nEventID, nUserID) &&.F.

cMsg = ''
? Report_Event(cMsg, 'My Application', nEType, nEventID, nUserID) &&.T.

FUNCTION Report_Event(tcMsg, tcApp, tnEType, tnEventID, tnUserID)
LOCAL nES, nSize, nPtrMsg, nHeap, nPtrCat, ;
 nNumString, nDataSize, nData, cNewString, nResult

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 ;

DECLARE RtlMoveMemory IN Win32Api AS CopyMemFrom ;

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

nNumString = OCCURS(CHR(0),tcMsg)

nHeap = HeapCreate(0,32768,32768)
nSize = LEN(tcMsg)
nPtrMsg = HeapAlloc(nHeap, 0, nSize)

nES = RegisterEventSource('', tcApp)
nResult = ReportEvent(nES, tnEType, nPtrCat, ;
 tnEventID, tnUserID, nNumString, nDataSize, nPtrMsg, nData) <> 0
HeapFree(nHeap, 0, nPtrMsg)
HeapDestroy(nHeap)
DeregisterEventSource(nES)
RETURN nResult
ENDFUNC
*** end test.prg


Quote:
> Hi Gene,

> Thanks for your code. It does seem to work except that the Error message
is
> not being written, just the application name. I notice that you set
> iNumstrings to 1 and then never send it into ReportEvent, instead you send
a
> 0. So it seemed that was the issue, however, when I send the iNumstrings
set
> to 1 into ReportEvent, I get an error.

> iNumstrings = 1
> lnReturnCode = ReportEvent(hEventLog, iLogType, wCategory, ;
>                   iEventID, lpUserSid, iNumStrings, ;
>                   cbStringSize, lpStrings, lpRawData)

> This doesn't run. Any ideas?

> TIA,
> -B



> > here is a sample of how the event log can be written to via VFP
> > HTH

> > *// port of Write to the Windows NT Event Log from Visual Basic into VFP
> > *// from MS KB artical Q154576

> > #define GMEM_ZEROINIT           0x0040   && flag for GlobalAlloc() to
> > initialize memory to zero
> > #define EVENTLOG_SUCCESS        0
> > #define EVENTLOG_ERROR_TYPE     1
> > #define EVENTLOG_WARNING_TYPE    2
> > #define EVENTLOG_INFORMATION_TYPE   4
> > #define EVENTLOG_AUDIT_SUCCESS    8
> > #define EVENTLOG_AUDIT_FAILURE    10

> > * sample function calls
> >  cApplicationName = "VFP IDE"
> >  LogNTEvent("Information from " + cApplicationName,
> > EVENTLOG_INFORMATION_TYPE, 1001)
> >  LogNTEvent("Warning from "   + cApplicationName, EVENTLOG_WARNING_TYPE,
> > 1002)
> >  LogNTEvent("Error from "    + cApplicationName, EVENTLOG_ERROR_TYPE,
> 1003)

> > FUNCTION LogNTEvent(sString, iLogType, iEventID)

> >  *// define constant for error handler routine
> >  #define MB_ICONINFORMATION      64      && Information message
> >  #define MB_OK                   0       && OK button only
> >  #define CR             CHR(13) && Carriage Return
> >  #define ERROR_SUCCESS          0  && Success error code from WINERROR.H
> >  #define FORMAT_MESSAGE_FROM_SYSTEM  0x00001000 && Value for use with
> > FormatMessage API. From WINBASE.H

> >   *// declare API dll's
> >     *-registers an application as an event source, if you create message
> > files
> >     *-this has to be the name you registered in the system registry
> >       declare long RegisterEventSource in ADVAPI32.DLL ;
> >           string lpUNCServerName, string lpSourceName

> >    *- this is obvious
> >       declare long DeregisterEventSource in ADVAPI32.DLL ;
> >            long hEventLog

> >       *- this is the function that writes to the event log
> >       declare integer ReportEvent in ADVAPI32.DLL ;
> >         integer hEventLog, integer wType, integer wCategory, ;
> >         integer dwEventID, integer lpUserSid, integer wNumStrings, ;
> >         integer dwDataSize, integer plpStrings, integer lpRawData

> >       *-error handler routines
> >       declare long GetLastError in KERNEL32.DLL

> >    *-function to return text message from system error code.
> >    declare integer FormatMessage IN kernel32.DLL ;


> >     integer Arguments

> >    *-this was a little puzzling in the VB call, but this is
> >    *- how to implement it in VFP
> >    declare RtlMoveMemory in WIN32API as CopyMemory ;
> >      integer , string , integer

> >       *- memory handling routines
> >       declare long GlobalAlloc in KERNEL32.DLL ;
> >         long , long

> >       declare long GlobalFree in KERNEL32.DLL ;
> >          long

> >  *// declare local vars
> >  local sString, iLogType, iEventID, ;
> >    iNumStrings, hEventLog, cbStringSize, ;
> >    lpUserSid, lnReturnCode, lpStrings, lpRawData

> >  *// initialize local vars

> >   *-length of binary data
> >    cbStringSize = 0

> >    *-string count
> >   iNumStrings = 1

> >   *-user security Id, not implemented!
> >   lpUserSid = 0

> >   * category for the message, only used if you create message file
> >   wCategory = 0

> >   *-pointer to the message buffer, limit of 32K characters
> >   lpStrings  = 0

> >   *-pointer to the raw data (binary) buffer
> >   lpRawData = 0

> >    *// register the application as the event source
> >    hEventLog = RegisterEventSource("", sString)

> >     cbStringSize = Len(sString) + 1

> >     *// this creates a pointer to a contiguous block of memory of nBytes
> > long
> >     lpStrings = GlobalAlloc(GMEM_ZEROINIT, cbStringSize)

> >   *// copy the data to the block of memory for use by the Api call
> >     CopyMemory(lpStrings , sString, cbStringSize)

> >    lpRawData = lpStrings

> >   *// make the log entry
> >    lnReturnCode = ReportEvent(hEventLog, iLogType, wCategory, ;
> >                   iEventID, lpUserSid, 0, ;
> >                   cbStringSize, lpStrings, lpRawData)

> >   *// this error handler is for debugging only
> >   IF lnReturnCode =  0
> >    lpBuffer  = SPACE(128)
> >    lnError = GetLastError()
> >    =FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, ;

> >    =MESSAGEBOX("System error has occurred." + CR + ;
> >     "System Error code: " + ALLTRIM(STR(lnError)) + CR + ;
> >     "System Error message:
> > "+ALLT(lpBuffer),MB_ICONINFORMATION+MB_OK,"ERROR")
> >   ENDIF

> >     *//release the memory used for the pointer
> >     GlobalFree(lpStrings)

> >     *// finally unregister the app as the source
> >     DeregisterEventSource (hEventLog)

> > return lnReturnCode



> > > *******
> > > first, the ALIAS keyword in VB means something totally different than
in
> > VFP
> > > *******

> > > ~doc reference~

> > > When working with Windows API procedures that use strings, you'll need
> to
> > > add an Alias clause to your declare statements to specify the correct
> > > character set. Windows API functions that contain strings actually
exist
> > in
> > > two formats: ANSI and Unicode. In the Windows header files, therefore,
> > > you'll get both ANSI and Unicode versions of each function that
contains
> a
> > > string.
> > > For example, following are the two C-language descriptions for the
> > > SetWindowText function. You'll note that the first description defines
> the
> > > function as SetWindowTextA, where the trailing "A" identifies it as an
> > ANSI
> > > function:

> > > WINUSERAPI
> > > BOOL
> > > WINAPI
> > > SetWindowTextA(
> > >    HWND hWnd,
> > >    LPCSTR lpString);

> > > The second description defines it as SetWindowTextW, where the
trailing
> > "W"
> > > identifies it as a wide, or Unicode function:

> > > WINUSERAPI
> > > BOOL
> > > WINAPI
> > > SetWindowTextW(
> > >    HWND hWnd,
> > >    LPCWSTR lpString);

> > > Because neither function is actually named "SetWindowText," you need
to
> > add
> > > an Alias clause to the declare to point to the function you want to
> > > reference

> > > **************
> > > the  CopyMemory API funtion doesn't really exist, here is some
excerpts
> > from
> > > the docs...
> > > **************

> > > ~doc reference~
> > > CopyMemory: A Strange and Terrible Saga
> > > Experienced Basic API programmers have come to know, if not love, the
> > > hmemcpy function. When C's weak data typing and Basic's strong data
> typing
> > > meet in the Windows API, hmemcpy is frequently called on to mediate.
The
> h
> > > in the name indicates that hmemcpy can handle huge memory (greater
than
> > 64K
> > > bytes), but Basic programmers rarely need it for such large chunks.
> > > Unfortunately, if you look for hmemcpy in the Win32 documentation,
> you'll
> > > come up with nothing - not even a note saying that the function is
> > obsolete.

> > > But you might happen to run across the Win32 CopyMemory function,
which
> > has
> > > exactly the same arguments and in fact

...

read more »



Sun, 16 Nov 2003 05:45:57 GMT  
 Logging Events to the NT Event Log from VFP
Don't forget that API declarations are case sensitive.  You MUST use the
exact case that is used in the API documentation (contrary to the rest of
windows) <grin>

--
Cy Welch
Senior Programmer
MetSYS Inc
http://metsys.metsysinc.com

Quote:
> Actually the problem is in the DECLARE statement in VFP. It was giving me
> the error "Entry Point Not Found". I will check on the UT.

> Thanks,
> -B



> > Is it a structure in the parameters?  If so, try the universalthread for
a
> > structure class that lets you use some structures in VFP.



> > > I did try already. But as I said before, VFP is having trouble
accessing
> > the
> > > CopyMemory function.

> > > -B



> > > > You know VB, so how about a vfp rewrite of the code listed in
Q154576?
> > I'd
> > > > like a copy!

> > > > --
> > > > Eric den Doop
> > > > www.foxite.com - The Home Of The Visual FoxPro Experts



> > > > > Ya, thanks. I saw this one in the KB. I don't like it because you
> > can't
> > > > > control the source name or event ID in the event log and our
> > production
> > > > > support monitoring scans for the name of our application in the
> > source.

> > > > > Thanks,
> > > > > -B



> > > > > > Quick and dirty trick is with the Scripting Host:

> > > > > > #DEFINE TARGET_SYSTEM SUBSTR(SYS(0),1,ATC('#',SYS(0))-1)
> > > > > > #DEFINE SUCCESS 0
> > > > > > #DEFINE ERROR 1
> > > > > > #DEFINE WARNING 2
> > > > > > #DEFINE INFORMATION 4
> > > > > > #DEFINE AUDIT_SUCCESS 8
> > > > > > #DEFINE AUDIT_FAILURE 16
> > > > > > WshShell = CreateObject("WScript.Shell")
> > > > > > *!* Logevent returns .t. for SUCCESS for .f. for FAILURE
> > > > > > ?WshShell.LogEvent(SUCCESS, "Logon Script Completed
Successfully")
> > > > > > WshShell.LogEvent(ERROR, "Logon Script Completed Successfully")
> > > > > > WshShell.LogEvent(WARNING, "We are getting low on disk space!!")
> > > > > > WshShell.LogEvent(INFORMATION, "Start nightly backup")
> > > > > > WshShell.LogEvent(AUDIT_SUCCESS, "Checksum Success!!")
> > > > > > WshShell.LogEvent(AUDIT_FAILURE, "Checksum Failure")
> > > > > > WshShell.LogEvent(AUDIT_FAILURE, "Checksum

Failure",TARGET_SYSTEM)

- Show quoted text -

Quote:
> > > > > > WshShell=.NULL.

> > > > > > This code is from article Q257541 from http://msdn.microsoft.com

> > > > > > --
> > > > > > Eric den Doop
> > > > > > www.foxite.com - The Home Of The Visual FoxPro Experts



> > > > > > > Hey guys,

> > > > > > > I was wondering if anyone had any code that would log events
to
> > the
> > > NT
> > > > > > event
> > > > > > > log from Fox. I wrote a VB component that I've been using from
> my
> > > VFP
> > > > > code
> > > > > > > that seems to work fine, but I thought if I could find some
code
> > in
> > > > VFP,
> > > > > > it
> > > > > > > would be nicer to build it directly into my framework. I tried
> > > > > converting
> > > > > > > the VB code to VFP, but VFP is having trouble accessing the
> > > CopyMemory
> > > > > API
> > > > > > > call. Here's the VB code if you're interested:

> > > > > > > MODULE1.BAS

> > > > > > > Declare Function RegisterEventSource Lib "advapi32.dll" Alias
_
> > > > > > >   "RegisterEventSourceA" (ByVal lpUNCServerName As String, _
> > > > > > >   ByVal lpSourceName As String) As Long

> > > > > > > Declare Function DeregisterEventSource Lib "advapi32.dll" ( _
> > > > > > >   ByVal hEventLog As Long) As Long

> > > > > > > Declare Function ReportEvent Lib "advapi32.dll" Alias _
> > > > > > > "ReportEventA" ( _
> > > > > > >   ByVal hEventLog As Long, ByVal wType As Integer, _
> > > > > > >   ByVal wCategory As Integer, ByVal dwEventID As Long, _
> > > > > > >   ByVal lpUserSid As Any, ByVal wNumStrings As Integer, _
> > > > > > >   ByVal dwDataSize As Long, plpStrings As Long, _
> > > > > > >   lpRawData As Any) As Boolean

> > > > > > > Declare Function GetLastError Lib "kernel32" () As Long

> > > > > > > Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory"
( _
> > > > > > >   hpvDest As Any, hpvSource As Any, _
> > > > > > >   ByVal cbCopy As Long)

> > > > > > > Declare Function GlobalAlloc Lib "kernel32" ( _
> > > > > > >    ByVal wFlags As Long, _
> > > > > > >    ByVal dwBytes As Long) As Long

> > > > > > > Declare Function GlobalFree Lib "kernel32" ( _
> > > > > > >    ByVal hMem As Long) As Long

> > > > > > > CLASS1.CLS:

> > > > > > > Public Enum EventType
> > > > > > >     EVENTLOG_SUCCESS = 0
> > > > > > >     EVENTLOG_ERROR_TYPE = 1
> > > > > > >     EVENTLOG_WARNING_TYPE = 2
> > > > > > >     EVENTLOG_INFORMATION_TYPE = 4
> > > > > > >     EVENTLOG_AUDIT_SUCCESS = 8
> > > > > > >     EVENTLOG_AUDIT_FAILURE = 10
> > > > > > > End Enum

> > > > > > >   Public Function LogNTEvent(sAppName As String, sMessage As
> > String,
> > > _
> > > > > > >                              iLogType As EventType, iEventID
As
> > > Long)
> > > > > > >         Dim bRC As Boolean
> > > > > > >         Dim iNumStrings As Integer
> > > > > > >         Dim hEventLog As Long
> > > > > > >         Dim hMsgs As Long
> > > > > > >         Dim cbStringSize As Long
> > > > > > >         Dim bRetVal As Boolean

> > > > > > >         bRetVal = True

> > > > > > >         hEventLog = RegisterEventSource("", sAppName)
> > > > > > >         cbStringSize = Len(sMessage) + 1
> > > > > > >         hMsgs = GlobalAlloc(&H40, cbStringSize)
> > > > > > >         CopyMemory ByVal hMsgs, ByVal sMessage, cbStringSize
> > > > > > >         iNumStrings = 1

> > > > > > >         If ReportEvent(hEventLog, iLogType, 0, iEventID, 0&,
> > > > > iNumStrings,
> > > > > > _
> > > > > > >                         cbStringSize, hMsgs, hMsgs) = 0 Then
> > > > > > >            bRetVal = False
> > > > > > >         End If

> > > > > > >         Call GlobalFree(hMsgs)
> > > > > > >         DeregisterEventSource (hEventLog)

> > > > > > >         LogNTEvent = bRetVal

> > > > > > >   End Function

> > > > > > > TIA,
> > > > > > > -B



Sun, 16 Nov 2003 05:59:01 GMT  
 
 [ 27 post ]  Go to page: [1] [2]

 Relevant Pages 

1. writing to the nt event log

2. Sending data to the event log on Windows NT

3. Accessing Windows event log

4. Outlook entries in Exchange event log.

5. log in to server via VFP?

6. SVRANY, VFP and Service surviving log-off

7. VFP Debug Log?

8. Event doesn't honor Class Event?

9. Read Events And Clear Events

10. Event tracking doesn't show refresh events...?

11. read events / clear events

12. Logging users off unattended workstations

 

 
Powered by phpBB® Forum Software