Solved

Windows XP problem.

Posted on 2002-04-25
1
180 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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now