| 3773 | |
| 3774 | |
| 3775 | HMODULE LoadKeyboardLayoutModule(HKL aLayout) |
| 3776 | // Loads a keyboard layout DLL and returns its handle. |
| 3777 | // Activates the layout as a side-effect, but reverts it if !aSideEffectsOK. |
| 3778 | { |
| 3779 | HMODULE hmod = NULL; |
| 3780 | // Unfortunately activating the layout seems to be the only way to retrieve it's name. |
| 3781 | // This may have side-effects in general (such as the language selector flickering), |
| 3782 | // but shouldn't have any in our case since we're only changing layouts for our thread, |
| 3783 | // and only if some other window is active (because if our window was active, aLayout |
| 3784 | // is already the current layout). |
| 3785 | if (HKL old_layout = ActivateKeyboardLayout(aLayout, 0)) |
| 3786 | { |
| 3787 | #define KEYBOARD_LAYOUTS_REG_KEY _T("SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts\\") |
| 3788 | const size_t prefix_length = _countof(KEYBOARD_LAYOUTS_REG_KEY) - 1; |
| 3789 | TCHAR keyname[prefix_length + KL_NAMELENGTH]; |
| 3790 | _tcscpy(keyname, KEYBOARD_LAYOUTS_REG_KEY); |
| 3791 | if (GetKeyboardLayoutName(keyname + prefix_length)) |
| 3792 | { |
| 3793 | TCHAR layout_file[MAX_PATH]; // It's probably much smaller (like "KBDUSX.dll"), but who knows what whacky custom layouts exist? |
| 3794 | if (ReadRegString(HKEY_LOCAL_MACHINE, keyname, _T("Layout File"), layout_file, _countof(layout_file))) |
| 3795 | { |
| 3796 | hmod = LoadLibrary(layout_file); |
| 3797 | } |
| 3798 | } |
| 3799 | if (aLayout != old_layout) |
| 3800 | ActivateKeyboardLayout(old_layout, 0); // Nothing we can do if it fails. |
| 3801 | } |
| 3802 | return hmod; |
| 3803 | } |
| 3804 | |
| 3805 | |
| 3806 |
no test coverage detected