summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/win_util.cc20
-rw-r--r--base/win_util.h6
-rw-r--r--views/controls/table/table_view.cc2
-rw-r--r--views/controls/tree/tree_view.cc2
-rw-r--r--views/widget/widget_win.cc2
5 files changed, 29 insertions, 3 deletions
diff --git a/base/win_util.cc b/base/win_util.cc
index 2f1ceb9..b71ac30 100644
--- a/base/win_util.cc
+++ b/base/win_util.cc
@@ -436,6 +436,26 @@ void NotifyHWNDDestruction(const tracked_objects::Location& from_here,
from_here));
}
+bool IMEAttach(HWND window, bool attach) {
+ // To prevent a crash when calling ImmAssociateContextEx() function on a PC
+ // which has a valid "imm32.dll" installed, we manually load "imm32.dll" and
+ // call its "ImmAssociateContextEx() function.
+ bool result = false;
+ HMODULE imm32_module = LoadLibrary(L"imm32.dll");
+ if (imm32_module) {
+ typedef BOOL (WINAPI* Imm32_ImmAssociateContextEx)(HWND, HIMC, DWORD);
+ Imm32_ImmAssociateContextEx imm_associate_context_ex =
+ reinterpret_cast<Imm32_ImmAssociateContextEx>(
+ GetProcAddress(imm32_module, "ImmAssociateContextEx"));
+ if (imm_associate_context_ex) {
+ result = !!imm_associate_context_ex(window, NULL,
+ attach ? IACE_DEFAULT : 0);
+ }
+ FreeLibrary(imm32_module);
+ }
+ return result;
+}
+
} // namespace win_util
#ifdef _MSC_VER
diff --git a/base/win_util.h b/base/win_util.h
index 284b9bd..b801e56 100644
--- a/base/win_util.h
+++ b/base/win_util.h
@@ -117,6 +117,12 @@ void NotifyHWNDDestruction(const tracked_objects::Location& from_here,
#define TRACK_HWND_DESTRUCTION(hwnd) \
win_util::NotifyHWNDDestruction(FROM_HERE, hwnd)
+// Attach the default IME to the window or detach it from the window.
+// This functions is a wrapper function for the ImmAssociateContextEx()
+// function to prevent a crash when calling the function on a PC which doesn't
+// have a valid "imm32.dll" installed.
+bool IMEAttach(HWND window, bool attach);
+
} // namespace win_util
#endif // BASE_WIN_UTIL_H__
diff --git a/views/controls/table/table_view.cc b/views/controls/table/table_view.cc
index 434b355..bde6bec 100644
--- a/views/controls/table/table_view.cc
+++ b/views/controls/table/table_view.cc
@@ -892,7 +892,7 @@ HWND TableView::CreateNativeControl(HWND parent_container) {
// Bug 964884: detach the IME attached to this window.
// We should attach IMEs only when we need to input CJK strings.
- ::ImmAssociateContextEx(list_view_, NULL, 0);
+ win_util::IMEAttach(list_view_, false);
UpdateContentOffset();
diff --git a/views/controls/tree/tree_view.cc b/views/controls/tree/tree_view.cc
index 08f2255..894aa6e 100644
--- a/views/controls/tree/tree_view.cc
+++ b/views/controls/tree/tree_view.cc
@@ -358,7 +358,7 @@ HWND TreeView::CreateNativeControl(HWND parent_container) {
// Bug 964884: detach the IME attached to this window.
// We should attach IMEs only when we need to input CJK strings.
- ::ImmAssociateContextEx(tree_view_, NULL, 0);
+ win_util::IMEAttach(tree_view_, false);
return tree_view_;
}
diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc
index b092682..4a4e27e 100644
--- a/views/widget/widget_win.cc
+++ b/views/widget/widget_win.cc
@@ -219,7 +219,7 @@ void WidgetWin::Init(HWND parent, const gfx::Rect& bounds,
// Bug 964884: detach the IME attached to this window.
// We should attach IMEs only when we need to input CJK strings.
- ::ImmAssociateContextEx(GetNativeView(), NULL, 0);
+ win_util::IMEAttach(GetNativeView(), false);
}
void WidgetWin::SetContentsView(View* view) {