Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Event logging with VFP revisited
Message
De
28/03/2002 04:19:47
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00637226
Message ID:
00638298
Vues:
22
Hi Larry,

First off: I really do appreciate the trouble you are taking on helping out on this.

Now, I tried it, and it works, (sort of).

The message makes it through along with another one from SQLSERVERAGENT:
The data portion of event 17055 from MSSQLSERVER is invalid.

The next question of course is, how do I get MyApp as the message source?

Mind you, this is a rethorical question, I really don't expect you to spend any more time on this.

Again, thank you, and have a nice Easter!


>Hi Peter,
>You're snafu is that you don't have a valid MessageFile. If there is no application with that name under Eventlog\Application\< application name > then the event system doesn't know where to look to determine the event ID. Check out the following example:
>#define EVENTLOG_ERROR_TYPE	0x1
>#define EVENTLOG_WARNING_TYPE	0x2
>#define EVENTLOG_INFORMATION_TYPE 0x4
>
>#define EVENT_ID_RECOVERY	0xC000429F
>
>declare integer RegisterEventSource in win32api string cUNCServer, string cRegKey
>declare integer ReportEvent in win32api ;
>	integer nEventlog, ;
>	integer nEventType, ;
>	integer nEventCategory, ;
>	integer nEventID, ;
>	integer nSecurityIdentifier, ;
>	integer nNumberofStrings, ;
>	integer nDataSize, ;
>	integer@ nPtrText, ;
>	integer@ cPtrDatabuffer
>declare integer DeregisterEventSource in win32api integer nEventlog
>declare integer GetLastError in win32api
>
>local lcUNC, lcregkey, lctext, lnptrtext, loheap, lnh
>lcUNC = '\\MyComputer'
>lcregkey = 'MSSQLServer'
>
>loheap = newobject('heap','clsheap.prg')
>
>lctext = 'Event log test text'
>lcbuff = 'Test text'
>lnptrtext = loheap.AllocString(lctext)
>lnbuff = loheap.AllocString(lcbuff)
>
>lnh = RegisterEventSource(lcUNC, lcregkey)
>
>if lnh <> 0 then
>	if ReportEvent(lnh,EVENTLOG_INFORMATION_TYPE, 2, EVENT_ID_RECOVERY, 0, 2, 0, @lnptrtext, 0) = 0 then
>		? 'Error occurred: ', GetLastError()
>	endif
>	DeregisterEventSource(lnh)
>endif
>
>First off, instead of specifying the entire registry hierarchy, you only need the application name. Second, you need a valid value for the EventMessageFile value under the application key. This will most likely contain the name of a resource DLL where the messages/events were compiled. See MSKB#Q166902 for information in troubleshooting why the weird message is displayed.
>
>Next, you need a valid event ID. I chose event ID 17055. This is the event ID for Recovery Complete under SQL Server. In addition to having a valid event ID, you will have to BITOR this with 0xC0000000. The event system expects the event ID to be in the loword and the severity to be in the hiword of the number passed. It parses out the appropriate ID. This was the only way I got it to work (per review of the KB article mentioned above).
>
>The examples in MSDN are all in VC++ and they expect you to have a header message file with the appropriate constants in it. I don't know of a way of listing events/messages from a DLL source file with the IDs broken out.
>
>BTW, I passed 2 as the number of strings to ReportEvent because event 17055 has two parameter strings: %1, %2. If you only pass one string and specify two, only the first string will be displayed and the %2 will not be displayed and a blank will be substituted in its place.
>
>HTH.
>
>>Thank's guys,
>>
>>It seems I'm almost, but not quite there.
>>I downloaded Ed Rauh's program & all, but there's something missing, because in the eventlog, instead of the message 'Test message from Peter Pirker'
>>
>>I get:
>>
>>The description for Event ID ( 0 ) in Source ( HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\EventLog\Application\WinApp) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. The following information is part of the event: Test message from Peter Pirker.
>>
>>Now I don't know what the 'remote computer' talk's all about, I'm running it locally.
>>
>>I don't have a WinApp entry under HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\EventLog\Application\, so I tried with one that's there - but that get's me the same message.
>>
>>I assume I still have to RegisterEventSource() to get a handle & all that?
>>
>>So where's my snafu?
>>
Peter Pirker


Whosoever shall not fall by the sword or by famine, shall fall by pestilence, so why bother shaving?

(Woody Allen)
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform