Here is a little more detail:
- IETW_Acquire calls IETW_ModalEventLoop.
- IETW_ModalEventLoop calls IETW_MessageHook.
- While handling the MSG_XFERREADY message, fAborting is True, so IETW_DisableSource is called (with no exception occurring).
- However, IETW_DS(..., MSG_DISABLEDS, ...) returns False so nState is left at 5. But no exception occurs during this call to IETW_DisableSource.
- Once IETW_ModalEventLoop exits, IETW_Acquire calls IETW_DisableSource.
- Since nState = 5, IETW_DS(..., MSG_DISABLEDS, ...) is called again, and this time the external exception occurs.
In IETW_DisableSource, I changed the code to set nState := 4 even if the call to IETW_DS returns False. So this:
if (nState = 5) and (IETW_DS(grec, DG_CONTROL, DAT_USERINTERFACE, MSG_DISABLEDS, @twUI)) then
nState := 4;
is now this:
if nState = 5 then begin
IETW_DS(grec, DG_CONTROL, DAT_USERINTERFACE, MSG_DISABLEDS, @twUI);
nState := 4;
end;
IETW_DisableSource no longer sends MSG_DISABLEDS to the driver twice and I no longer receive the external exception.
Now the scan silently fails and I get a black image, which is better than the previous experience. Now I need to see if I can detect whether something is loaded in the scanner before calling Acquire.
Jon