• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 636
  • Last Modified:

Exceptions in Listview's NM_DBLCLK lock Listview

I have a listview. In the handler for it's NM_DBLCLK, I throw an exception, which is to be caught in the primary message loop of the application. The exception handler shows a dialog box and allows message loop to continue getting/dispatching message.

The problem is that after the dialog box is shown, the listview locks - the scroll bars of the list view work, but no clicking or keyboarding seems to work on it (and no, it's not disabled).

I use VC++ 5 (Service Pack 2) under WinNT/Win95 (explorer 3 or 4) with MFC.

My reasoning is that the listview is not exception safe (remember, C++ exceptions are also Win32 exceptions).

So - is there a workaround, or am I doing something wrong? (and I know that doing the try/catch inside the NM_DBLCLK will probably work, but I'll save that as a last resort, because I do want to handle all my exceptions in a central place)
0
giltayar
Asked:
giltayar
1 Solution
 
galkinCommented:
I think the problem is that you must return a value when handling NM_DBCLICK since this message is sent in WM_NOTIFY form. Throwning an exeption causes leaving handler fuction without a retun value.
0
 
alexoCommented:
Also, C++ exceptions are *not* Win32 exceptions.  VC just has a mechanism to handle them in a similar fasion.
0
 
giltayarAuthor Commented:
galkin, the Win32 SDK specifically says that NM_DBLCLK's return value is ignored, but thanks anyway.

I think alexo has the right answer. But... It doesn't help (through no fault of his).

My question is: can I throw a *C++* exception so that it will be caught by both SEH handlers and C++ handlers? This way, the listview will catch the exception and probably rethrow it, and then I will catch it and handle it correctly.

I have wracked my brains (and searched the MSDN) in search of an answer, and have come up with none.

BTW, Alexo's answer should be given an A, but I got two answers at the same time, and the grading page asked me only about one of them.

0
 
Tommy HuiCommented:
WM_NOTIFY messages are sent by the list control. When you throw an exception, you are unwinding the stack for the control as well. You shouldn't throw C++ exceptions across messages. So what you would want to do is post yourself a message and then throw the exception during that message. This will allow the control to unwind its stack correctly first and then you can throw the exception.

0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Tackle projects and never again get stuck behind a technical roadblock.
Join Now