J
Johyowa
Guest
Hello,
I wrote a someway medium program, where I want to read a large String into a WCHAR String. I use an Edit Contol window to get the text.
countChars is the Length the output text is supposed to have.
The if loop shall crop the length to 504 characters and fill up the missing input text characters with '.'
The program works for small Strings (<20 Characters) and a countChar of 20. But if I like to increase countChar to 200 it crashes, I don't know where exactely, because it throws the error at the end of the message call (I use to get the input from the EditControl).
I'm rather lost and don't know where to find the problem.
When I set the if loop to 16 it doesn't crash, but this can't be the solution?
HWND temp = GetDlgItem(hDlg, IDC_UserFileData);
int textlength = min((countChars + 1), GetWindowTextLength(temp));
wchar_t* data = new wchar_t(textlength); //create wchar_t* of data
GetDlgItemText(hDlg, IDC_UserFileData, data, textlength); //from input
int dataIndex = 0; //set index in data
wchar_t* fileData = new wchar_t(min(504,countChars) + 1); //set size of fileData
int endOfString = countChars; //initialize end of input
for (int i = 0; i < min(504,countChars); i++) {
if (data == '\0') {//if input data was terminated
endOfString = i; //set new end of input
}
if (i < endOfString) { //if original string not ended
fileData = data;//use original string
}
else { //if original string ended
wchar_t t = L'.'; //fill up string
fileData = t;
}
}
fileData[min(504, countChars)] = '\0'; //set end of string
dataSystem[address / 512]->addUserData(fileData); //add data to userfile
Continue reading...
I wrote a someway medium program, where I want to read a large String into a WCHAR String. I use an Edit Contol window to get the text.
countChars is the Length the output text is supposed to have.
The if loop shall crop the length to 504 characters and fill up the missing input text characters with '.'
The program works for small Strings (<20 Characters) and a countChar of 20. But if I like to increase countChar to 200 it crashes, I don't know where exactely, because it throws the error at the end of the message call (I use to get the input from the EditControl).
I'm rather lost and don't know where to find the problem.
When I set the if loop to 16 it doesn't crash, but this can't be the solution?
HWND temp = GetDlgItem(hDlg, IDC_UserFileData);
int textlength = min((countChars + 1), GetWindowTextLength(temp));
wchar_t* data = new wchar_t(textlength); //create wchar_t* of data
GetDlgItemText(hDlg, IDC_UserFileData, data, textlength); //from input
int dataIndex = 0; //set index in data
wchar_t* fileData = new wchar_t(min(504,countChars) + 1); //set size of fileData
int endOfString = countChars; //initialize end of input
for (int i = 0; i < min(504,countChars); i++) {
if (data == '\0') {//if input data was terminated
endOfString = i; //set new end of input
}
if (i < endOfString) { //if original string not ended
fileData = data;//use original string
}
else { //if original string ended
wchar_t t = L'.'; //fill up string
fileData = t;
}
}
fileData[min(504, countChars)] = '\0'; //set end of string
dataSystem[address / 512]->addUserData(fileData); //add data to userfile
Continue reading...