Microsoft KB Archive/132288

= FIX: ExtTextOut Causes Assertion in DCPREV.CPP or DCMETA.CPP =

Q132288

-

The information in this article applies to:


 * Microsoft Foundation Classes (MFC), used with:
 * Microsoft Visual C++, versions 1.50, 1.51, 1.52
 * *EDITOR Please do not choose this product*Microsoft Visual C++ 32-bit Edition* use 241, 265, 225, versions 2.0, 2.1

-

SYMPTOMS
Calling ExtTextOut in a CView's OnDraw or OnPaint routine causes an assertion failure when Print Preview is used. The assertion failure occurs only when the lpszString parameter points to read-only memory. The assertion failure will occur on one of the following lines:

  In Visual C++, version 1.50 (MFC 2.50): "DCPREV.CPP - Line 588"  In Visual C++, version 1.51 or 1.52 (MFC 2.51 or MFC 2.52): "DCPREV.CPP - Line 592"  In Visual C++, 32-bit Edition, version 2.0 or 2.1 (MFC 3.0 or 3.1): "DCPREV.CPP - Line 594"

CAUSE
The cause is in an incorrect ASSERT statement in the CPreviewDC::ExtTextOut function as follows:

  ... ASSERT(AfxIsValidAddress(lpszString, nCount)); ... The documentation states (correctly) that AfxIsValidAddress takes an optional third parameter that specifies whether the memory is to be used for both reading and writing. It defaults to TRUE.

Because this particular ASSERT does not provide the optional third parameter, the call to AfxIsValidAddress checks whether the memory pointed to by lpszString can be written to. If it cannot, the assertion fails.

Note that there is no need for the ExtTextOut function to write to the memory pointed to by lpszString.

RESOLUTION
Modify the call to ExtTextOut so that it passes non-read-only memory to the function. This can be done by storing your string data in a different location or by making a copy of the string data before calling the ExtTextOut function.

STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This problem was fixed in Microsoft Visual C++, 32-bit Edition, version 4.0.

Additional query words: 1.50 1.51 1.52 2.50 2.51 2.52 2.00 2.10 3.00 3.10

Keywords : kbDocView kbGDI kbMFC kbVC150bug kbVC200bug kbVC210bug kbVC400fix kbGrpDSMFCATL kbNoUpdate

Issue type : kbbug

Technology : kbAudDeveloper kbMFC

Last Reviewed: July 29, 2001

-

[mailto:MSDN@MICROSOFT.COM Send feedback to Microsoft]

© 2002 Microsoft Corporation. All rights reserved.