Solved

Windows XP problem.

Posted on 2002-04-25
1
187 Views
Last Modified: 2013-11-20
I have an app I wrote with Visual C++ and released a little over a year ago.  We tested it on Win 95/98/NT/2000 and never had a problem.  It's been in the market and, so far, hasn't had any reported problems.  

I recently got an email from a user that said she put it on an XP machine and after 10 minutes the program shuts down.  No warning; no error messages; just shuts off the program (not the computer).  That sounds like an unhandled exception to me.  I tried to replicate the problem on a Win2k machine and never had it crash.  I don't have access to an XP machine to test it and try to debug.  

This is a shot in the dark.  Does anyone have any idea why a program that never had any problems and seems as solid as a brick would suddenly have this problem in XP?  If I can come up with some possible problems and solutions, I might be able to blind-fix the problem without buying XP. I'd send the fixed program to the same user and see if the problem was resolved.  Thanks for any help.
0
Comment
Question by:jjjkkklll
1 Comment
 
LVL 30

Accepted Solution

by:
SteveGTR earned 100 total points
ID: 6971361
I encountered a problem with the way various operating systems (NT4, 95, 2000, XP) handle the ::GetWindowText function when processing a RICHEDIT control. The way XP handles the function are dangerous! The problem occurs during standard MFC DDX_Text processing in the AfxSetWindowText() function in WINUTIL.CPP:

void AFXAPI AfxSetWindowText(HWND hWndCtrl, LPCTSTR lpszNew)
{
        int nNewLen = lstrlen(lpszNew);
        TCHAR szOld[256];
        // fast check to see if text really changes (reduces flash in controls)
        if (nNewLen > _countof(szOld) ||
                ::GetWindowText(hWndCtrl, szOld, _countof(szOld)) != nNewLen ||
                lstrcmp(szOld, lpszNew) != 0)
        {
                // change it
                ::SetWindowText(hWndCtrl, lpszNew);
        }
}

The problem occurs when the RICHEDIT field was larger than 256 characters and was being reduced to a size smaller than 256 characters.

The ::GetWindowText() call acts strangly under different operating systems.

On NT4/SP5 and on Windows 95 the function returns 255 and str is equal to the first 255 characters.

On NT2000 ::GetWindowText() returns 0 and str is empty. Calling ::GetLastError() returns 122 (ERROR_INSUFFICIENT_BUFFER). A true statement, but the documentation says: "nMaxCnt [in] Specifies the maximum number of characters to copy to the buffer, including the NULL character. If the text exceeds this limit, it is truncated.".

I'd have expected XP to act the same as NT 2000, and it does sort of. It returns 0, but str is set to
the 1st 256 of data. I wonder if it returned the NULL also? If so, then the stack is messed up.

I fixed the processing in our code by redefining the DDX_Text() function to a custom function that bypasses this processing when dealing with a RICHEDIT control.

Good Luck,
Steve

PS: See http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=cplusprog&qid=20280051 for more information about this problem.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Perl Awk Need Help 3 139
Expand to include initial dialog with two choices. 9 86
Detect file exist or not 3 202
how to use laptop or pad camera in vb.net windows application 2 107
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question