RegisterEventSource返回997 I / O PENDING

时间:2011-07-13 10:47:49

标签: delphi event-log

在调用时,如何处理错误:997(io pending):RegisterEventSource?

感谢您的帮助!

procedure TForm1.Button111Click(Sender: TObject);
var
  StringToAdd: String;
  hEventLog: THandle;
  p: PChar;
  EventID: Word;
  CategoryID: Word;
  wynik: Boolean;
  errnumber: cardinal;
begin
  hEventLog := RegisterEventSource(nil, PChar('app'));

  errnumber := 0;
  errnumber := GetLastError();  //<==997
  showmessage (IntToStr(errnumber));

  if hEventLog > 0 then
  begin
    p := PChar('Test');
    wynik :=
    ReportEvent(
    hEventLog,
    EVENTLOG_INFORMATION_TYPE, // Event Type
    22, // Event Category ID
    500, // Event ID
    nil, // User SID (optional)
    1, // Number of strings
    0, // Size of Binary Data
    @p, // String to be merged with Text in Ressource DLL 
    nil // Address of Binary Data
    );
    errnumber := GetLastError(); //<==997
    showmessage (IntToStr(errnumber));

    DeRegisterEventSource(hEventLog);
  end;
end;

1 个答案:

答案 0 :(得分:3)

在调用hEventLog之前,您没有测试NULL是否为GetLastError。如果API调用失败,您应该只调用GetLastError,如文档中所述。

我的猜测是RegisterEventSource实际上是成功的,并且您从程序执行早期发生的另一个API调用失败中获取错误代码。