Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: base/win/wrapped_window_proc.h

Issue 6697004: Add an exception wrapper to the WindowProc functions so... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Provides a way to handle exceptions that happen while a WindowProc is
6 // running. The behavior of exceptions generated inside a WindowProc is OS
7 // dependent, but it is possible that the OS just ignores the exception and
8 // continues execution, which leads to unpredictable behavior for Chrome.
9
10 #ifndef BASE_WIN_WRAPPED_WINDOW_PROC_H_
11 #define BASE_WIN_WRAPPED_WINDOW_PROC_H_
12 #pragma once
13
14 #include <windows.h>
15
16 namespace base {
17 namespace win {
18
19 // An exception filter for a WindowProc. The return value determines how the
20 // exception should be handled, following standard SEH rules. However, the
21 // expected behavior for this function is to not return, instead of returning
22 // EXCEPTION_EXECUTE_HANDLER or similar, given that in general we are not
23 // prepared to handle exceptions.
24 typedef int (__cdecl *WinProcExceptionFilter)(EXCEPTION_POINTERS* info);
25
26 // Sets the filter to deal with exceptions inside a WindowProc. Returns the old
27 // exception filter, if any.
28 // This function should be called before any window is created.
29 WinProcExceptionFilter SetWinProcExceptionFilter(WinProcExceptionFilter filter);
30
31 // Calls the registered exception filter.
32 int CallExceptionFilter(EXCEPTION_POINTERS* info);
33
34 // Wrapper that supplies a standard exception frame for the provided WindowProc.
35 // The normal usage is something like this:
36 //
37 // LRESULT CALLBACK MyWinProc(HWND hwnd, UINT message,
38 // WPARAM wparam, LPARAM lparam) {
39 // // Do Something.
40 // }
41 //
42 // ...
43 //
44 // WNDCLASSEX wc = {0};
45 // wc.lpfnWndProc = WrappedWindowProc<MyWinProc>;
46 // wc.lpszClassName = class_name;
47 // ...
48 // RegisterClassEx(&wc);
49 //
50 // CreateWindowW(class_name, window_name, ...
51 //
52 template <WNDPROC proc>
cpu_(ooo_6.6-7.5) 2011/03/16 00:12:37 it feels that we could do template <WNDPROC proc,
rvargas (doing something else) 2011/03/16 00:25:07 The idea is that the filter is not provided by the
53 LRESULT CALLBACK WrappedWindowProc(HWND hwnd, UINT message,
54 WPARAM wparam, LPARAM lparam) {
55 LRESULT rv = 0;
56 __try {
57 rv = proc(hwnd, message, wparam, lparam);
58 } __except(CallExceptionFilter(GetExceptionInformation())) {
59 }
60 return rv;
61 }
62
63 } // namespace win
64 } // namespace base
65
66 #endif // BASE_WIN_WRAPPED_WINDOW_PROC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698