CRichEditCtrl :: GetLine功能不适用于Charaters< 4 [英] CRichEditCtrl::GetLine funtion is not working for Charaters < 4

查看:70
本文介绍了CRichEditCtrl :: GetLine功能不适用于Charaters< 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在visual studio 2008中,当我尝试在富文本框中写入少于4个字符时,它会给出异常(下面是附件)在进行调试时,我们发现Ensure()导致异常:

 

int CRichEditCtrl :: GetLine(_In_ int nIndex,_Out_writes_to_(nMaxLength,return)LPTSTR lpszBuffer,_In_ int nMaxLength)const
{
ASSERT(:: IsWindow(m_hWnd));
ENSURE(sizeof(nMaxLength)< = nMaxLength * sizeof(TCHAR)&& nMaxLength> 0);
*(LPINT)lpszBuffer = nMaxLength;
return(int):: SendMessage(m_hWnd,EM_GETLINE,nIndex,(LPARAM)lpszBuffer);
}

解决方案

使用足够大的缓冲区以确保ENSURE不会导致例外。


$
由于MFC代码在缓冲区的开头存储一个包含nMaxLength的int,因此接收缓冲区的最小大小必须至少为a的大小。 。INT&NBSP;这与EM_GETLINE消息的要求有关。



$
此外,请参阅
https://msdn.microsoft.com/en-us/library/z0z83tcz(v = VS.90)的.aspx


In visual studio 2008, When I am trying to write less than 4 characters in Rich Text Box, it gives exception (below is the attachment) After doing Debugging, we came to know that Ensure() is causing the Exception:

int CRichEditCtrl::GetLine(_In_ int nIndex, _Out_writes_to_(nMaxLength, return) LPTSTR lpszBuffer, _In_ int nMaxLength) const { ASSERT(::IsWindow(m_hWnd)); ENSURE(sizeof(nMaxLength)<=nMaxLength*sizeof(TCHAR)&&nMaxLength>0); *(LPINT)lpszBuffer = nMaxLength; return (int)::SendMessage(m_hWnd, EM_GETLINE, nIndex, (LPARAM)lpszBuffer); }

解决方案

Use a buffer that is large enough to make sure that ENSURE doesn't cause an exception.

Since the MFC code stores an int containing nMaxLength at the beginning of the buffer the minimum size of the receiving buffer must be at least the size of an int.  This is related to the requirements of the EM_GETLINE message.


Also, see the Note about buffer size at https://msdn.microsoft.com/en-us/library/z0z83tcz(v=vs.90).aspx


这篇关于CRichEditCtrl :: GetLine功能不适用于Charaters&lt; 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆