GetDlgItemText(...) crashes on a space.

This is a discussion on GetDlgItemText(...) crashes on a space. within the Windows Programming forums, part of the Platform Specific Boards category; In the interests of berevity, I'm only posting the code inside of the case: break;. Code: case ID_HTML_HEAD: { int ...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313

    GetDlgItemText(...) crashes on a space.

    In the interests of berevity, I'm only posting the code inside of the case: break;.

    Code:
    case ID_HTML_HEAD:
    {
    	int length = GetWindowTextLength(GetDlgItem(hWnd, ID_EDIT));
    					
    	if (length > 0)
    	{
    		char *temp = new char;
    		
    		GetDlgItemText(hWnd, ID_EDIT, temp, length+1);
    		
    		std::string s(temp);
    	
    		s += "/* Long string */";
    							
    	    SetDlgItemText(hWnd, ID_EDIT, s.c_str());
    	    
    	    delete temp;
    	}
    	
    	else
    	{
    		SetDlgItemText(hWnd, ID_EDIT, "/* Long string */");
    	}
    }
    break;
    The problem is that when I have text in my edit control with a newline (\r\n as Windows defines it), the program exits. I can't figure out how to handle this.

    For example, you have text like:

    <html>
    <head>
    <title>Blah</title>
    </head>
    <body>

    Blah.
    Thank you in advance.
    Last edited by Lithorien; 03-31-2005 at 06:16 PM.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Code:
    char *temp = new char;
    I think what you intended was this
    Code:
    char *temp = new char [length+1];

  3. #3
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,803
    You do realize you are making space for just one char right?
    Woop?

  4. #4
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    Quote Originally Posted by prog-bman
    You do realize you are making space for just one char right?
    *faceplants*

    ..Thank you. I have absolutely no idea how I missed that. -_-()

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Out of space when compiling kernel
    By NuNn in forum Linux Programming
    Replies: 3
    Last Post: 04-01-2009, 02:43 PM
  2. disk space mysteriously gone
    By evader in forum C++ Programming
    Replies: 4
    Last Post: 01-21-2004, 12:30 PM
  3. Replies: 12
    Last Post: 05-17-2003, 05:58 AM
  4. someone who is good at finding and fixing bugs?
    By elfjuice in forum C++ Programming
    Replies: 8
    Last Post: 06-07-2002, 03:59 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21