According to MSDN, EM_GETTEXTEX
returns the following:
The return value is the number of TCHARs copied into the
output buffer, including the null terminator.
Now take a look at the following code:
GETTEXTLENGTHEX gtl;
GETTEXTEX gt;
int len;
TCHAR *buf;
memset(>l, 0, sizeof(GETTEXTLENGTHEX));
gtl.flags = GTL_DEFAULT;
gtl.codepage = 1200;
len = SendMessage(hEditWnd, EM_GETTEXTLENGTHEX, (WPARAM) >l, 0);
printf("LEN: %d\n", len);
buf = malloc((len + 1) * sizeof(TCHAR));
memset(>, 0, sizeof(GETTEXTEX));
gt.cb = (len + 1) * sizeof(TCHAR);
gt.flags = GT_DEFAULT;
gt.codepage = 1200;
len = SendMessage(hEditWnd, EM_GETTEXTEX, (WPARAM) >, (LPARAM) buf);
printf("LEN: %d NULLCHECK: %d\n", len, buf[len]);
For a RichEdit control that contains the text Hello
, this program outputs the following:
LEN: 5
LEN: 5 NULLCHECK: 0
This is confusing me because MSDN says that the count value retuned by EM_GETTEXTEX
is supposed to include the null terminator, thus I'd expect 6 but instead I get 5.
Is this a documentation bug or am I doing something wrong here?
EDIT
Here is the manifest:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="x86"
name="ELIMINATED FOR PRIVACY REASONS"
type="win32"
/>
<description>ELIMINATED FOR PRIVACY REASONS</description>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>
And here is the CreateWindowEx()
call:
hEditWnd = CreateWindowEx(0, L"RichEdit20W", L"",
WS_VSCROLL|WS_HSCROLL|ES_LEFT|ES_AUTOHSCROLL|ES_AUTOVSCROLL|
WS_CHILD|ES_MULTILINE|WS_BORDER,
0,0,0,0, hWnd, NULL, hInstance, NULL);
I have made a doc pull request that has been merged, so assume it was indeed a mistake and it should be fixed by now.