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

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

Issue 1852143002: win: Remove GetModuleFromAddress, deduplicate __ImageBase code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/win/wrapped_window_proc.h" 5 #include "base/win/wrapped_window_proc.h"
6 6
7 #include "base/atomicops.h" 7 #include "base/atomicops.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/process/memory.h"
10 9
11 namespace { 10 namespace {
12 11
13 base::win::WinProcExceptionFilter s_exception_filter = NULL; 12 base::win::WinProcExceptionFilter s_exception_filter = NULL;
14 13
14 HMODULE GetModuleFromWndProc(WNDPROC window_proc) {
15 HMODULE instance = NULL;
16 // Converting a pointer-to-function to a void* is undefined behavior, but
17 // Windows (and POSIX) APIs require it to work.
18 void* address = reinterpret_cast<void*>(window_proc);
19 if (!::GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
20 GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
21 static_cast<char*>(address),
Will Harris 2016/04/04 01:26:44 why double cast, why not just reinterpret_cast<> s
Nico 2016/04/04 01:38:47 Yes. I had this inline here, but it looked cramped
22 &instance)) {
23 NOTREACHED();
24 }
25 return instance;
26 }
27
15 } // namespace. 28 } // namespace.
16 29
17 namespace base { 30 namespace base {
18 namespace win { 31 namespace win {
19 32
20 WinProcExceptionFilter SetWinProcExceptionFilter( 33 WinProcExceptionFilter SetWinProcExceptionFilter(
21 WinProcExceptionFilter filter) { 34 WinProcExceptionFilter filter) {
22 subtle::AtomicWord rv = subtle::NoBarrier_AtomicExchange( 35 subtle::AtomicWord rv = subtle::NoBarrier_AtomicExchange(
23 reinterpret_cast<subtle::AtomicWord*>(&s_exception_filter), 36 reinterpret_cast<subtle::AtomicWord*>(&s_exception_filter),
24 reinterpret_cast<subtle::AtomicWord>(filter)); 37 reinterpret_cast<subtle::AtomicWord>(filter));
(...skipping 15 matching lines...) Expand all
40 HBRUSH background, 53 HBRUSH background,
41 const char16* menu_name, 54 const char16* menu_name,
42 HICON large_icon, 55 HICON large_icon,
43 HICON small_icon, 56 HICON small_icon,
44 WNDCLASSEX* class_out) { 57 WNDCLASSEX* class_out) {
45 class_out->cbSize = sizeof(WNDCLASSEX); 58 class_out->cbSize = sizeof(WNDCLASSEX);
46 class_out->style = style; 59 class_out->style = style;
47 class_out->lpfnWndProc = window_proc; 60 class_out->lpfnWndProc = window_proc;
48 class_out->cbClsExtra = class_extra; 61 class_out->cbClsExtra = class_extra;
49 class_out->cbWndExtra = window_extra; 62 class_out->cbWndExtra = window_extra;
50 class_out->hInstance = base::GetModuleFromAddress(window_proc); 63 // RegisterClassEx uses a handle of the module containing the window procedure
64 // to distinguish identically named classes registered in different modules.
65 class_out->hInstance = GetModuleFromWndProc(window_proc);
51 class_out->hIcon = large_icon; 66 class_out->hIcon = large_icon;
52 class_out->hCursor = cursor; 67 class_out->hCursor = cursor;
53 class_out->hbrBackground = background; 68 class_out->hbrBackground = background;
54 class_out->lpszMenuName = menu_name; 69 class_out->lpszMenuName = menu_name;
55 class_out->lpszClassName = class_name; 70 class_out->lpszClassName = class_name;
56 class_out->hIconSm = small_icon; 71 class_out->hIconSm = small_icon;
57 72
58 // Check if |window_proc| is valid. 73 // Check if |window_proc| is valid.
59 DCHECK(class_out->hInstance != NULL); 74 DCHECK(class_out->hInstance != NULL);
60 } 75 }
61 76
62 } // namespace win 77 } // namespace win
63 } // namespace base 78 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698