EM_GETSEL returning character position rather than byte position in
MBCS build.
<p>I am maintaining a large legacy application build using MBCS. On a syste=
m with Japanese as the system locale I have an issue where the selection po=
sition of an edit control is being returned incorrectly.<br /></p><div styl=
e="border:#000080 1px solid;color:#000;font-family:'Courier New',Courier,=
Monospace;font-size:10pt;"><div style="background:#000080;color:#fff;font=
-family:Verdana,Tahoma,Arial,sans-serif;font-weight:bold;padding:2px 5px;">=
Code Snippet</div><div style="background:#ddd;max-height:300px;"><ol star=
t="351" style="background:#ffffff;margin:0 0 0 3em;padding:0 0 0 5px;">=
<ul><ul><li><span style="color:#0000ff;">CEdit</span>* <span style="col=
or:#000080;">pEdit</span> =
<span style="color:#000080;">state</span>-><span style="color:#88000=
0;">GetEdit</span>() ;</li><li style="background:#f3f3f3;"><span style==
"color:#0000ff;">auto</span> <span style="color:#000080;">
hWnd</span> = <span style="color:#000080;">pEdit</span>-><span style=
="color:#880000;">GetSafeHwnd</span>() ;</li><li><span style="color:#00=
00ff;">if</span> ( <span style="color:#000080;">hWnd</span> )</li><li sty=
le="background:#f3f3f3;">{</li><li> ::<span style=
="color:#880000;">SendMessageA</span>(<span style="color:#000080;">hWnd=
</span>,
<span style="color:#a000a0;">EM_GETSEL</span>, (<span style="color:#000=
0ff;">WPARAM</span>)&<span style="color:#000080;">nStart</span>, (<sp=
an style="color:#0000ff;">LPARAM</span>)&<span style="color:#000080=
;">nEnd</span>) ;</li></ul><li style="background:#f3f3f3;"> &n=
bsp; <span style="color:#0000ff;">TCHAR</span>
<span style="color:#000080;">buffer</span>[128];</li><li> &nbs=
p; ::<span style="color:#880000;">SendMessageA</span>(<span style==
"color:#000080;">hWnd</span>,
<span style="color:#a000a0;">WM_GETTEXT</span>, (<span style="color:#00=
00ff;">WPARAM</span>)<span style="color:#a000a0;">_countof</span>(<span s=
tyle="color:#000080;">buffer</span>), (<span style="color:#0000ff;">LPA=
RAM</span>)&<span style="color:#000080;">buffer</span>);</li></ul><li=
style="background:#f3f3f3;"> <span style="color=
:#a000a0;">_RPT4</span>(<span style="color:#a000a0;">_CRT_WARN</span>,
<span style="color:#a31515;">"String '%s' selection [%d,%d], unicode? %s"=
</span>,
<span style="color:#000080;">buffer</span>, <span style="color:#000080;=
">nStart</span>,
<span style="color:#000080;">nEnd</span>, (::<span style="color:#880000=
;">IsWindowUnicode</span>(<span style="color:#000080;">hWnd</span>)) ?
<span style="color:#a31515;">"True"</span> : <span style="color:#a31515=
;">
"False"</span>);</li><li>}</li></ol></div></div><p>With the Carat at the en=
d of the string this produces the output</p><p><strong>String '=E6=9C=AA=E5=
=AE=9A=E7=BE=A9' selection [3,3], unicode? False</strong></p><p><strong></s=
trong>What on earth can be going on?<strong></strong></p><p>I have built a =
little test application and that works as I would expect producing the outp=
ut</p><p><strong>String '=E6=9C=AA=E5=AE=9A=E7=BE=A9' selection [6,6], unic=
ode? False</strong></p><div><strong><br /></strong></div><p></p><br /><br /=
<br />