Does ToUnicode call ToUnicodeEx? And what does ToUnicodeEx change on the kernel space thread?

c++, keyboard-hook, unicode, windows

Solution

`ToUnicode` and `ToUnicodeEx` are both wrappers around `NtUserToUnicodeEx` and yes, the only difference is the final parameter which is NULL for `ToUnicode` and user-supplied for `ToUnicodeEx`.

Because dead keys are used to generate characters from multiple separate key presses the OS has to keep a history of which dead keys were previously pressed. I think all that note is warning you is that `ToUnicodeEx` and `TranslateMessage` both use the same history - so mixing calls to the two functions could generate unreliable results.

Problem

ToUnicodeEx: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646322(v=vs.85).aspx ToUnicode: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646320(v=vs.85).aspx It seems that the only difference between the two is that ToUnicodeEx allows the passing of the input locale indentifier parameter as ToUnicode does not. My question is: Does ToUnicode itself call ToUnicodeEx? Also, at the bottom of the ToUnicodeEx msdn page, in the remarks section, we see: As ToUnicodeEx translates the virtual-key code, it also changes the state of the kernel-mode keyboard buffer. This state-change affects dead keys, ligatures, alt+numpad key entry, and so on. It might also cause undesired side-effects if used in conjunction with TranslateMessage (which also changes the state of the kernel-mode keyboard buffer). Does anyone know exactly what it is doing the kernel-mode kb buffer?

Original source