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

Last reviewed: September 18, 1997
Article ID: Q132288
1.50 1.51 1.52 | 2.00 2.10
WINDOWS        | WINDOWS NT
kbprg kbfixlist

The information in this article applies to:

  • The Microsoft Foundation Classes(MFC) included with:

        - Microsoft Visual C++ for Windows, versions 1.5, 1.51, 1.52
        - Microsoft Visual C++, 32-bit Edition, 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 reference words: 1.50 1.51 1.52 2.50 2.51 2.52 2.00 2.10 3.00
3.10
KBCategory: kbprg kbfixlist kbbuglist
KBSubcategory: MfcDocView
Keywords : MfcDocView kbbuglist kbfixlist kbprg
Technology : kbMfc
Version : 1.50 1.51 1.52 | 2.00 2.10
Platform : NT WINDOWS
Solution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 18, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.