Unfortuantly I already tryed a statically allocated array of 255 TCHARS. Same result And actually tried allocating a larger buffer dynamically 2. Again, same results *sigh* Very confusing.
Here, these r the values gotten by watching the memory while single stepping through the code. Data in comments. I changed the implementation to the last one I posted as it really is nicer and I can't be workin on the rest till I get this done anyways... lol
Code:
1 enter'd into edit field. EN_CHANGE msg calls funtion.
void SizeChanged() {
int charsCopied = 0;
TCHAR * buff;
TCHAR * buffptr;
TCHAR * buffptr2;
int len;
int i = 0;
HWND ctrl;
FILE * debug;
ctrl = GetDlgItem(hdlgActive, IDE_FONTSIZE);
len = Edit_GetTextLength(ctrl);
// len == 1
if(!len) {
// feild cleared
// set flag
return;
}
buff = new TCHAR[len+1];
buffptr = buffptr2 = buff;
if(buff == NULL) {
// error
}
Edit_GetText(ctrl, buff, len+1);
// buff == {'1', 0 } "1"
while(*buffptr) {
if(isdigit(*buffptr))
// 1st run, tests true
*buffptr2++ = *buffptr;
// buff == {'1', 0}
// buffptr2 == {0} ""
buffptr++;
// buffptr == {0} ""
}
// Second run, exits out of while
*buffptr2 = '\0';
// buffptr2 == buff[1] == {0}
debug = fopen("debug.txt", "w");
fprintf(debug, "%s\n", buff);
fflush(debug);
fclose(debug);
buff == {'1', 0} "1"
Edit_SetText(ctrl, buff);
// CRASH!!!!!!!!!!!
delete [] buff;
}
If a invalid char is enter'd, it doens't crash. In anther words, if the string passed to SetText is a empty string it seems to be ok.