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]));  
        
}

Here is the algorithm as a DOS console project...

Tried running it under a debugger. It terminated when the dialog box was initialized. The position that it crashed was this.

while(Lines[i][j]!=',')
              {
                   j++;
              }

I think the reason is this. When you initialized the window, there are no text strings in the edit box. Remember the return value of EM_GETLINECOUNT cant be less than one.

Return Value

The return value is an integer specifying the total number of text lines in the multiline edit control or rich edit control. If the control has no text, the return value is 1. The return value will never be less than 1.

But the above loop will continue searching until it finds a ',' character. It ran after I made the following change. Check if it agrees with your program logic.

while( Lines[ i ] [ j ] != '\0' && Lines[i][j]!=',' )
              {
                   j++;
              }

Similarly for

while(Lines[i][j]!='-')
              {
                   j++;
              }

I dont see why you would want to process the Editbox input at the WM_PAINT message. Cant you just do it at the WM_COMMAND generated at the press of the AddCount ( ID_PB_ADD ) button?

I just want to say thank you very much for your help.. for some reason, my dev-cpp and mvsc++ debuggers don't work for windows projects.. I originally put all that code under WM_PAINT just mainly for testing purposes.. and then later on split it up into one or two seperate functions.. but obviously there were fundamental problems with where my code was located and how it was being called..

very cool catch on the return value from EM_GETLINECOUNT.. who would have thought that it would always return at least one line..?!?! This means that my parsing functions was going to be called on windows creation.. when there is no text.. and attempt to parse a lot of nothing into memory.

anyway.. moved some code around.. life == good.. been at a standstill for about a week.. made a breakthrough today :cool:

You are welcome. Glad to know that I was of any help. Get those debuggers working. The debugger is a programmer's best friend. Strange that both of the debuggers are not working. Do you KNOW how to work with a debugger? Setting breakpoints, and stepping through code using F10, quick watch and such? Just running in debug mode wont help that much. Better take a look in the net. There are heaps of tutorials on Visual Studio debugging.

when it comes to my dev-cpp debugger.. when I try to go into debug mode.. I am prompted that, "Your project does not have degubbing information, do you want to enable degubbing and rebuild your project?" I select yes, the code is then recompiled.. and then execution stops. why? I don't know.. Here is the compilation log:

Compiler: Default compiler
Building Makefile: "F:\Dev-Cpp\Makefile.win"
Executing make clean
rm -f cablesplicer.o cablesplicer.exe

g++.exe -c cablesplicer.cpp -o cablesplicer.o -I"F:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"F:/Dev-Cpp/include/c++/3.4.2/backward" -I"F:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"F:/Dev-Cpp/include/c++/3.4.2" -I"F:/Dev-Cpp/include"

g++.exe cablesplicer.o -o "cablesplicer.exe" -L"F:/Dev-Cpp/lib" -mwindows

Execution terminated
Compilation successful

Why this happens with only windows projects..??!? I have no idea..

As far as MVSC++ goes.. I have issues with making any windows projects.. I open up a new windows project.. I write the code.. always get this one single error:

--------------------Configuration: cablesplicer - Win32 Debug--------------------
Compiling...
cablesplicer1.cpp
f:\cablesplicer\cablesplicer1.cpp(437) : fatal error C1010: unexpected end of file while looking for precompiled header directive
Error executing cl.exe.

cablesplicer.exe - 1 error(s), 0 warning(s)

for some reason, mvsc++ doesn't even appear to recognize my <windows.h> or StdAfx.. or something.. I've tried to play around with the settings and stuff.. even re-installation does not help..

I had breakpoints set in all the above scenarios.


So.. I am down to using my dev-cpp and msvc++ debuggers only for DOS console projects..


I think maybe because.. I have two hard drives.. and I installed my compilers on my F: drive.. I think that maybe some of the default library paths might be to C: but this does not account for why the compiler can allegedly locate every other library except for windows.h


But thanks again for your help.. I think I will be coding non-stop all night long :cool:


skins vs. the bucs at tampa this sunday at 1pm EST. go skins..!!

when it comes to my dev-cpp debugger.. when I try to go into debug mode.. I am prompted that, "Your project does not have degubbing information, do you want to enable degubbing and rebuild your project?" I select yes, the code is then recompiled.. and then execution stops. why?

This is because you havent specified that you want debugging information generated for the project. You can set this by
1. Select Project
2. Select Options
3. Select the Compiler Tab from the Dialog Box that appear
4. Select Linker
5. Set "Generate Debugging Information" to Yes

After that set a break point and do Debug. You should be able to debug your project.

for some reason, mvsc++ doesn't even appear to recognize my <windows.h> or StdAfx.. or something.. I've tried to play around with the settings and stuff.. even re-installation does not help..

Seems like you have a serious path misconfiguration. What version of VSC++ are you using? I got the same problem with the Visual Studio 2005 beta. But I could work around that by the information in this link .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.