EM_GETTEXTEX - 错误记录的返回值?

时间:2016-07-18 15:51:23

标签: c winapi richedit

根据MSDN,EM_GETTEXTEX返回以下内容:

The return value is the number of TCHARs copied into the
output buffer, including the null terminator.

现在看一下下面的代码:

GETTEXTLENGTHEX gtl;
GETTEXTEX gt;
int len;
TCHAR *buf;

memset(&gtl, 0, sizeof(GETTEXTLENGTHEX));
gtl.flags = GTL_DEFAULT;
gtl.codepage = 1200;

len = SendMessage(hEditWnd, EM_GETTEXTLENGTHEX, (WPARAM) &gtl, 0);

printf("LEN: %d\n", len);

buf = malloc((len + 1) * sizeof(TCHAR));

memset(&gt, 0, sizeof(GETTEXTEX));
gt.cb = (len + 1) * sizeof(TCHAR);
gt.flags = GT_DEFAULT;
gt.codepage = 1200;

len = SendMessage(hEditWnd, EM_GETTEXTEX, (WPARAM) &gt, (LPARAM) buf);

printf("LEN: %d NULLCHECK: %d\n", len, buf[len]);

对于包含文本Hello的RichEdit控件,此程序输出以下内容:

LEN: 5
LEN: 5 NULLCHECK: 0

这让我感到困惑,因为MSDN说由EM_GETTEXTEX重新调整的计数值应该包含空终止符,因此我期望6但是我得到5。

这是文档错误还是我在这里做错了什么?

修改

这是清单:

<?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>

这是CreateWindowEx()电话:

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);

0 个答案:

没有答案