CEdit::GetLine() Windows 7
我有以下代码段,其中 m_edit
是 CEdit 控件:
TCHAR lpsz[MAX_PATH+1];
// get the edit box text
m_edit.GetLine(0,lpsz, MAX_PATH);
这在运行 Windows XP 及更早版本的计算机上完美运行。我没有在 Vista 中对此进行测试,但在 Windows 7 上,lpsz 会插入垃圾 unicode 字符(有时还会插入实际文本)。知道这里发生了什么吗?
I have the following segment of code where m_edit
is a CEdit control:
TCHAR lpsz[MAX_PATH+1];
// get the edit box text
m_edit.GetLine(0,lpsz, MAX_PATH);
This works perfectly on computers running Windows XP and earlier. I have not tested this in Vista, but on Windows 7, lpsz gets junk unicode characters inserted into it (as well as the actual text sometimes). Any idea as to what is going on here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
既然您使用的是 MFC,为什么不利用它的
CString
类呢?这是许多程序员被 MFC 吸引的原因之一,因为它使处理字符串变得更加容易。例如,您可以简单地编写:(
上面的代码经测试可以在 Windows 7 上正常工作。)
请注意,复制的行不包含空终止字符(请参阅 文档)。这可以解释您在更高版本的 Windows 中看到的无意义字符。
Since you're using MFC, why aren't you taking advantage of its
CString
class? That's one of the reasons many programmers were drawn to MFC, because it makes working with strings so much easier.For example, you could simply write:
(The above code is tested to work fine on Windows 7.)
Note that the copied line does not contain a null-termination character (see the "Remarks" section in the documentation). That could explain the nonsense characters you're seeing in later versions of Windows.
它不是以 null 终止的。你需要这样做:
It's not null terminated. You need to do this: