Форум: "WinAPI";
Текущий архив: 2002.04.11;
Скачать: [xml.tar.bz2];
ВнизEventLog Найти похожие ветки
← →
Vladimir_Shk (2002-02-07 11:00) [0]Привет All!
Нарисовалась такая проблемка.
Я написал сервис, который раз в неделю удаляет файлы из одной из папок на сервере.
Я хочу, чтобы успешные или неуспешные попытки фисксировались.
Я написал следующий код:
procedure TDelFreeSrv.ProcessDelete;
var hHandle : THandle;
begin
hHandle:=RegisterEventSource(nil,EvtPath);
if ClearDir(FPath,FALSE) then
ReportEvent(hHandle,EVENTLOG_INFORMATION_TYPE,0,EvtID,nil,1,0,PChar(lpMsgOK),nil);
else
ReportEvent(hHandle,EVENTLOG_WARNING_TYPE,0,EvtID,nil,1,0,PChar(lpMsgFail),nil);
DeRegisterEventSource(hHandle);
end;
Все уперлось в параметр EvtID. Как я понял из MSDN - "event identifier" и его структура должны находиться в message-file"е сервиса.
Как этот файл создается? Можно ли его создать в формате rc?
← →
VuDZ (2002-02-07 12:31) [1]Reporting an Event
After you have added a source name to the registry, use the RegisterEventSource function to get a handle to the Application event log. The following example obtains the handle and then adds an event to the log using the ReportEvent function.
void MyReportEvent(LPSTR szMsg)
{
HANDLE h;
h = RegisterEventSource(NULL, // uses local computer
"SamplApp"); // source name
if (h == NULL)
ErrorExit("Could not register the event source.");
if (!ReportEvent(h, // event log handle
EVENTLOG_ERROR_TYPE, // event type
0, // category zero
MSG_ERR_EXIST, // event identifier
NULL, // no user security identifier
1, // one substitution string
0, // no data
(LPTSTR *) szMsg, // pointer to string array
NULL)) // pointer to data
ErrorExit("Could not report the event.");
DeregisterEventSource(h);
}
Recall that your header file contains the event identifiers. For this example, the following event identifier was used:
//
// MessageId: MSG_ERR_EXIST
// MessageText:
// File %1 does not exist.
//
#define MSG_ERR_EXIST ((DWORD)0xC0000004L)
← →
Vladimir_Shk (2002-02-07 14:53) [2]Вообще-то у меня именно так и написано. Это что - отвечу, что знаю, а не по вопросу? Проблема, решение которой мне требуется - включить в exe мессаджи в бинарном виде (наверное в виде какого-то ресурса). На Visual C++ решение простое, мне нужно то же самое для Делфи.
← →
VuDZ (2002-02-07 15:02) [3]#define MSG_ERR_EXIST ((DWORD)0xC0000004L) ?
определи константу типа integer и всё...
фактически то же самое и сделано в этом примере
← →
Vladimir_Shk (2002-02-07 16:43) [4]Тогда я вообще ничего не понял. Что даст определение абстрактной константы? На какую запись она ссылается? Насколько я понимаю, в ресурсе exe-файла должна существовать реальная запись сообщения с реальным ID.
Страницы: 1 вся ветка
Форум: "WinAPI";
Текущий архив: 2002.04.11;
Скачать: [xml.tar.bz2];
Память: 0.45 MB
Время: 0.007 c