Article ID: 143330
Article Last Modified on 11/21/2006
if (nLen > value.GetAllocLength()) ...It is possible that the buffer for the string has been emptied by a call to AddNew() or SetFieldNull(). This would cause the CString value to be empty, which causes the messagebox to be displayed.
void DDX_MyFieldCBString(CDataExchange* pDX, int nIDC, CString& value, CDaoRecordset* pRecordset, int nMaxFieldLength)Replace these lines:
if (nLen > value.GetAllocLength())
AfxFailMaxChars(pDX, value.GetAllocLength());
// get known length
::GetWindowText(hWndCtrl, value.GetBuffer(0), nLen+1);
with these lines:
if (nLen > nFieldLength)
AfxFailMaxChars(pDX, nFieldLength);
// get known length
::GetWindowText(hWndCtrl, value.GetBuffer(nLen), nLen+1);
Note that GetBuffer() is no longer receiving 0 but is using the value
in nLen.
void DDX_MyFieldLBString(CDataExchange* pDX, int nIDC, CString& value, CDaoRecordset* pRecordset, int MaxFieldLength)Replace these lines:
if (nLen > value.GetAllocLength())
AfxFailMaxChars(pDX, value.GetAllocLength());
::SendMessage(hWndCtrl, LB_GETTEXT, nIndex,
(LPARAM)(LPSTR)value.GetBuffer(0));
with these lines:
if (nLen > nFieldLength)
AfxFailMaxChars(pDX, nFieldLength);
::SendMessage(hWndCtrl, LB_GETTEXT, nIndex,
(LPARAM)(LPSTR)value.GetBuffer(nLen));
You will need to include a prototype for AfxFailMaxChars() in your code.
Here's the prototype:
void _stdcall AfxFailMaxChars(CDataExchange* pDX, int nChars);
Additional query words: kbVC400bug
Keywords: kbbug kbdatabase kbfix kbvc410fix KB143330