Chromium Code Reviews| Index: base/win/wrapped_window_proc.cc |
| diff --git a/base/win/wrapped_window_proc.cc b/base/win/wrapped_window_proc.cc |
| index 61b79eda8851bd02e837e6a5cfd91b2becb2f8ce..0a00996fbad1a55ab674985d310cfe5c95567a12 100644 |
| --- a/base/win/wrapped_window_proc.cc |
| +++ b/base/win/wrapped_window_proc.cc |
| @@ -6,12 +6,25 @@ |
| #include "base/atomicops.h" |
| #include "base/logging.h" |
| -#include "base/process/memory.h" |
| namespace { |
| base::win::WinProcExceptionFilter s_exception_filter = NULL; |
| +HMODULE GetModuleFromWndProc(WNDPROC window_proc) { |
| + HMODULE instance = NULL; |
| + // Converting a pointer-to-function to a void* is undefined behavior, but |
| + // Windows (and POSIX) APIs require it to work. |
| + void* address = reinterpret_cast<void*>(window_proc); |
| + if (!::GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | |
| + GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, |
| + 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
|
| + &instance)) { |
| + NOTREACHED(); |
| + } |
| + return instance; |
| +} |
| + |
| } // namespace. |
| namespace base { |
| @@ -47,7 +60,9 @@ BASE_EXPORT void InitializeWindowClass( |
| class_out->lpfnWndProc = window_proc; |
| class_out->cbClsExtra = class_extra; |
| class_out->cbWndExtra = window_extra; |
| - class_out->hInstance = base::GetModuleFromAddress(window_proc); |
| + // RegisterClassEx uses a handle of the module containing the window procedure |
| + // to distinguish identically named classes registered in different modules. |
| + class_out->hInstance = GetModuleFromWndProc(window_proc); |
| class_out->hIcon = large_icon; |
| class_out->hCursor = cursor; |
| class_out->hbrBackground = background; |