rmaniac / omnithreadlibrary

Automatically exported from code.google.com/p/omnithreadlibrary
0 stars 0 forks source link

DSiWin32.DSiClassWndProc is not protected from exceptions #70

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
DSiClassWndProc has stdcall calling convention and it is used as message 
dispatcher. It invokes many event handlers, including user-defined (via 
TOmniEventMonitor.WndProc and TOmniEventMonitor.WndProc.ProcessMessages). 

However, there is no try/except blocks in the above mentioned routines. This 
means that any exception during processing OTL messages will pop up to the 
caller of message pumping cycle. 

As a general rule, Win32 code doesn't worry too much about recovering from 
exceptions (see: 
http://blogs.msdn.com/b/oldnewthing/archive/2012/09/10/10347674.aspx ). 
Therefore, let exception escape your Win32-callbacks is a very bad idea. For 
example, if you are using exception tracer, then exception tracer may use 
DialogBoxParam to display error dialog UI. If you receive, say, 
OnTaskMessage(WM_STOP) in quick succession and both rause exception (as "failed 
data/result validation") - the error dialog from first exception will be 
interrupted by second exception. Second exception will abort DialogBoxParam 
function.

VCL.Forms wraps message dispatcher in try/except block and calls 
Application.HandleException routine to handle exception before returning 
control to system. If you are not going to use VCL.Forms unit, then you can use 
Classes.ApplicationHandleException routine.

BTW, the signature of DSiClassWndProc is incorrect. It uses 4-bytes W- and 
LParams - even on 64-bits. Correct signature:

function DSiClassWndProc(Window: HWND; Message: UINT; AWParam: WPARAM; ALParam: 
LPARAM): LRESULT; stdcall;

Typecasts to W- and LParams inside code of DSiClassWndProc are not needed.

Original issue reported on code.google.com by randomcl...@gmail.com on 13 Oct 2014 at 1:25

GoogleCodeExporter commented 8 years ago
Thanks for the detailed report. I agree with everything you wrote and I'll fix 
the code.

Original comment by gabr42 on 13 Oct 2014 at 5:20

GoogleCodeExporter commented 8 years ago
We need this fix urgently. When will this fix be released?

Original comment by DanielBa...@gmail.com on 9 Apr 2015 at 12:33

GoogleCodeExporter commented 8 years ago

Original comment by gabr42 on 17 Apr 2015 at 6:04