Having troubles handling text from a multiline edit box.. the first part of this algorithm runs fine by itself.. the second part (highlighted in blue) runs fine as a DOS console project using 'char' data types.. but when I add it to this windows project (using TCHAR's) it distorts the GUI display and causes the program to lock-up/terminate... why would it work so well as a dos console project.. but totally go bezerk as a windows project...??!!
The entire code thus far can be viewed here (for like up to 3 days)
Problem code:
void EditBoxFileParser(HDC hdc, PAINTSTRUCT* ps, HFONT hFont, HWND hwnd, HWND hEdit)
{
int iCount;
WORD iLength, iOffset;
TCHAR **Lines;
//Get Number of Lines in Edit Field
iCount = SendMessage(hEdit, EM_GETLINECOUNT, 0, 0);
//If Editbox is empty, exit function
if(!iCount)
return;
Lines = new TCHAR*[iCount];
//Populate 2D array, Lines[LineIndex][LineText]
for(int i=0; i<iCount; i++)
{ iOffset = SendMessage(hEdit, EM_LINEINDEX, i, 0);
iLength = (WORD)SendMessage(hEdit, EM_LINELENGTH, iOffset, 0);
Lines[i] = new TCHAR[iLength+sizeof(WORD)+1];
CopyMemory(Lines[i], &iLength, sizeof(WORD));
SendMessage(hEdit, EM_GETLINE, i, (LPARAM)Lines[i]);
Lines[i][iLength] = '\0';
}
//Visually Verify Lines[][]
for(int i=0, x=300, y=275; i<iCount; i++)
TextOut(hdc, x, y+=20, Lines[i], lstrlen(Lines[i]));
[b]/* Code works fine up until this point */[/b]
//The code below works fine by itself in as a DOS application
//But locks up this windows project
//Parse User Entered Text
TCHAR **Name = new TCHAR*[iCount];
TCHAR **FiberCount1 = new TCHAR*[iCount];
TCHAR **FiberCount2 = new TCHAR*[iCount];;
int word_index;
bool cont = true;
for(int i=0, j=0; i<iCount; i++, j=0)
{
word_index = 0;
cont = true;
do{
//Extract Fiber Name
while(Lines[i][j]!=',')
{
j++;
}
Lines[i][j]='\0';
Name[i] = new TCHAR[j-word_index+1];
lstrcpy(Name[i], Lines[i]+word_index);
Name[i][j-word_index] = '\0';
word_index = j;
word_index++;
//Extract Beginning Fiber Count
while(Lines[i][j]!='-')
{
j++;
}
Lines[i][j] = '\0';
FiberCount1[i] = new TCHAR[j-word_index+1];
lstrcpy(FiberCount1[i], Lines[i]+word_index);
FiberCount1[i][j-word_index] = '\0';
word_index = j;
word_index++;
//Extract Ending Fiber Count
while(Lines[i][j]!=',' && Lines[i][j]!='\0')
{
j++;
}
if(Lines[i][j]=='\0')
cont = false;
Lines[i][j] = '\0';
FiberCount2[i] = new TCHAR[j-word_index+1];
lstrcpy(FiberCount2[i], Lines[i]+word_index);
FiberCount2[i][j-word_index] = '\0';
word_index = j;
word_index++;
}while(cont);
}
//Visual Verification
for(int i=0, x=400, y=275; i<iCount; i++)
TextOut(hdc, x, y+=20, Name[i], lstrlen(Lines[i]));
}