Note that there are some explanatory texts on larger screens.

plurals
  1. POOne control returns contents as single-byte, another as double-byte?
    primarykey
    data
    text
    <p>I have 2 <code>CRichEditCtrls</code>. One is part of a dialog template, created automatically. When I call GetSelText on it, the bytes returned are one byte per char, i.e I'll get back <code>char *str={'a','n','d'}</code>. The 2nd control is created dynamically using the <code>Create</code> method, and the data returned calling GetSelText is returned in 2-byte characters: <code>char *str={'a',0,'n',0,'d',0}</code>.</p> <p>This is making things a real pain... see <a href="https://stackoverflow.com/questions/2333684/cricheditctrlgetseltext-is-not-working-right">this topic</a>. One way works with one control, one way works with the other.</p> <p>I can't even see <em>how</em> two controls (on the same dialog) can have different behavior like this. I don't see a way to tell the one created dynamically what way to work.</p> <p>How can this be going on? The control created dynamically is the odd one out in our application, so that's the one that needs to be changed...</p> <p>Here is the code I'm using:</p> <pre><code>ASSERT(::IsWindow(m_hWnd)); CHARRANGE cr; cr.cpMin = cr.cpMax = 0; ::SendMessage(m_hWnd, EM_EXGETSEL, 0, (LPARAM)&amp;cr); CString strText; LPTSTR lpsz=strText.GetBufferSetLength((cr.cpMax - cr.cpMin + 1) * 2); lpsz[0] = NULL; long nLen = ::SendMessage(m_hWnd, EM_GETSELTEXT, 0, (LPARAM)lpsz); lpsz[nLen] = NULL; for(long i=0;i&lt;nLen;++i) { TRACE("lpsz[%d] (%d bytes) = %d {",i,sizeof(lpsz[i]),lpsz[i]); char *pc = (char *)&amp;lpsz[i]; for(int j=0;j&lt;sizeof(lpsz[i]);++j) { TRACE(" %d(%c)",pc[j],pc[j] ? pc[j] : '#'); } TRACE("}\n"); } strText.ReleaseBuffer(); return CString(strText); </code></pre> <p>The output from my dialog-template control:</p> <pre><code>lpsz[0] (2 bytes) = 28257 { 97(a) 110(n)} lpsz[1] (2 bytes) = 100 { 100(d) 0(#)} lpsz[2] (2 bytes) = 52685 { -51(Í) -51(Í)} </code></pre> <p>And from my dynamically created control:</p> <pre><code>lpsz[0] (2 bytes) = 97 { 97(a) 0(#)} lpsz[1] (2 bytes) = 110 { 110(n) 0(#)} lpsz[2] (2 bytes) = 100 { 100(d) 0(#)} </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload