What can i do with the error: 997 (io pending) when invoking: RegisterEventSource?
Thanks for help!
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;
You aren’t testing whether or not
hEventLogisNULLbefore callingGetLastError. You should only callGetLastErrorif the API call failed, as described in the documentation.My guess is that
RegisterEventSourceactually succeeds and you are getting the error code from the failure of another API call that happened earlier in the execution of your program.