Click here to Skip to main content
16,006,605 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRedrawing windows that don't have focus Pin
Darren Steadman1-May-03 5:29
Darren Steadman1-May-03 5:29 
GeneralRe: Redrawing windows that don't have focus Pin
valikac1-May-03 7:28
valikac1-May-03 7:28 
GeneralRe: Redrawing windows that don't have focus Pin
J. Dunlap1-May-03 8:46
J. Dunlap1-May-03 8:46 
GeneralI have a editbox in my toolbar and want change background color Pin
whofmans1-May-03 5:04
whofmans1-May-03 5:04 
GeneralRe: I have a editbox in my toolbar and want change background color Pin
David Crow1-May-03 5:57
David Crow1-May-03 5:57 
GeneralRe: I have a editbox in my toolbar and want change background color Pin
whofmans1-May-03 21:03
whofmans1-May-03 21:03 
GeneralRe: I have a editbox in my toolbar and want change background color Pin
David Crow2-May-03 4:15
David Crow2-May-03 4:15 
QuestionCString Bug??? Pin
levay1-May-03 4:52
levay1-May-03 4:52 
I have a very strange bug that I have been unable to track down. I am using a CString extension class called CStringEx. I am simply looping through the string looking for \n for wrapping purposes. Once I reach a certain portion of the loop, I get a memory error and the program crashes.
Now... here is the strange part. While stepping through the code in debug mode, the error DOES NOT HAPPEN. So then I put TraceWin code in the loop so I can see what's going on. Again, in a normal run, the error happens everytime. Then, in an effort to see of the portion of the string I an working with is causeing errors, I perform a CString.Mid() within the loop and output the results. PRESTO, the error stops!! WTF?!? Nothing else in the code has changed. I then pull the trace code out and just do a Mid() to a temp var in the loop. ERROR IS GONE! The simple act of performing a Mid() on the var has stopped the error.
I could keep this hack in the code, but I would rather not. Does anyone have any ideas what could cause a Mid() to stop a memory error from occuring? Is this an allocation issue with CString?
Any insight on this would be greatly appreciated.

The code in question is below:
<br />
void WordWrap( CStringEx &String, int intWrapSize )<br />
{<br />
	FSTRACE("WordWrap(): start\n");<br />
<br />
	CString strTemp;<br />
<br />
	int intSpace = 0;<br />
	int intLineSize = intWrapSize;<br />
	int intStart = intLineSize;<br />
	int intLastStart = 0;<br />
	int intFindLF = String.Find("\n");<br />
<br />
	while ( TRUE )<br />
	{<br />
		if ( (intSpace = String.Find(" ", intStart)) != -1 )<br />
		{<br />
			FSTRACE("WordWrap(): intSpace = %d\n", intSpace);<br />
<br />
			intFindLF = String.Find("\n", intLastStart);<br />
			FSTRACE("WordWrap(): intFindLF = %d\n", intFindLF);<br />
<br />
			if (intFindLF > intSpace || intFindLF == -1)<br />
			{<br />
				String.Insert(intSpace + 1, "\r\n");<br />
				FSTRACE("WordWrap(): insert crlf @ %d\n", intSpace + 1);<br />
<br />
				intLastStart = intSpace + 4;<br />
				intStart = (intSpace + intLineSize) + 3;<br />
			}<br />
			else if (intFindLF != 0)<br />
			//else if (intFindLF != -1)<br />
			{<br />
				intLastStart = intFindLF + 2;<br />
				FSTRACE("WordWrap(): intLastStart = %d\n", intLastStart);<br />
				<br />
				intStart = intFindLF + intLineSize;<br />
				FSTRACE("WordWrap(): intStart = %d\n", intStart);<br />
<br />
			}<br />
			else<br />
			{<br />
				intStart = intFindLF + intLineSize;<br />
				FSTRACE("WordWrap(): intStart = %d\n", intStart);<br />
			}<br />
		}<br />
		else<br />
		{<br />
			FSTRACE("WordWrap(): while - break\n", intSpace);<br />
			break;<br />
		}<br />
<br />
		// Solves the error ????<br />
		// if I rem out this code, the error comes back consistantly<br />
		strTemp = String.Mid(intLastStart, intStart);<br />
		//FSTRACE("WordWrap(): [%s]\n", String.Mid(intLastStart, intStart));<br />
		FSTRACE("WordWrap(): --------------------------\n");<br />
	}<br />
	<br />
	FSTRACE("WordWrap(): returning\n");<br />
	return;<br />
}<br />
<br />

AnswerRe: CString Bug??? Pin
David Crow1-May-03 5:07
David Crow1-May-03 5:07 
GeneralRe: CString Bug??? Pin
levay1-May-03 5:15
levay1-May-03 5:15 
GeneralRe: CString Bug??? Pin
David Crow1-May-03 5:39
David Crow1-May-03 5:39 
GeneralRe: CString Bug??? Pin
levay1-May-03 5:49
levay1-May-03 5:49 
GeneralRe: CString Bug??? Pin
levay1-May-03 6:10
levay1-May-03 6:10 
AnswerRe: CString Bug??? Pin
Nitron1-May-03 5:38
Nitron1-May-03 5:38 
GeneralRe: CString Bug??? Pin
levay1-May-03 5:52
levay1-May-03 5:52 
GeneralRe: CString Bug??? Pin
Nitron1-May-03 5:54
Nitron1-May-03 5:54 
GeneralRe: CString Bug??? Pin
David Crow1-May-03 7:45
David Crow1-May-03 7:45 
GeneralRe: CString Bug??? Pin
levay1-May-03 9:00
levay1-May-03 9:00 
AnswerRe: CString Bug??? Pin
Rein Hillmann1-May-03 6:30
Rein Hillmann1-May-03 6:30 
GeneralRe: CString Bug??? Pin
levay1-May-03 7:02
levay1-May-03 7:02 
AnswerRe: CString Bug??? Pin
John R. Shaw2-May-03 22:24
John R. Shaw2-May-03 22:24 
Generalmultiline list view Pin
SanjiDeluxe1-May-03 4:30
SanjiDeluxe1-May-03 4:30 
GeneralRe: multiline list view Pin
RobJones1-May-03 5:03
RobJones1-May-03 5:03 
GeneralRe: multiline list view Pin
happosai1-May-03 7:35
happosai1-May-03 7:35 
Generalopen solitare Pin
InternetMill1-May-03 4:28
InternetMill1-May-03 4:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.