Thread: GetWindowTextLength() = crash ?

  1. #1
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378

    GetWindowTextLength() = crash ?

    hey, i'm having a problem with an MDI text editor where every time i try to call GetWindowTextLength(), my program crashes. EVERY TIME. its rather irritating and frustrating and if anyone knows why, the information would be greatly appreciated or even if anyone has a shot in the dark..anything.. lol thanks


    oh yea, and i'm using the function in order to find out how much text has been entered in my edit control so that i can allot enough space in memory to hold the text in a buffer.
    Last edited by willc0de4food; 07-04-2005 at 10:02 AM.
    Registered Linux User #380033. Be counted: http://counter.li.org

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Can you post a small example that demonstrates the issue?

    Either the HWND you're passing GetWindowTextLength() is invalid or your process/memory has already been corrupted to the point that GetWindowTextLength() is just a victim and not the cause.

    gg

  3. #3
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    as an update, i can make it tell me that theres no text in the dialog

    Code:
    case ID_ENC_ENCRYPT:
    {
        char algorithm[31] = "Az!By@Cx#Dw$Ev%Fu^Gt&Hs*Ir(Js)";
        TCHAR *buf;
        char *converted_int;
        int i, len;
        HWND hEdit = GetDlgItem(hwnd, IDC_CHILD_EDIT);
                             
        len = GetWindowTextLength(hEdit);
        buf = (TCHAR *)malloc(len+1);
        if (len <= 0) { MessageBox(hwnd, "There is no text to encrypt.", "Error.", MB_OK | MB_ICONERROR); return FALSE; }
        GetDlgItemText(hwnd, IDC_CHILD_EDIT, buf, len);
                             
        for (i = 0; i <= len; i++)
        {
            buf[i] = buf[i] ^ algorithm[i % 30];
        }
                             
        SendMessage(hEdit, WM_SETTEXT, 0, (LPARAM)buf);
                             
        free(buf);
    }
    break;
    that codes give me the "a programmer f*d up and Microsoft wants to hear about it " message.
    *bites tongue*
    uhm.......for some reason its working.?.this time...all i did was remove some comments and some MessageBox's that were telling me how far into the function the program got.

    mm..it seems i found the problem to be trying to have a messagebox display an int. the var "len" was an int, but i had the code:
    Code:
    MessageBox(hwnd, (LPCSTR)len, "Contents of: len", MB_OK | MB_ICONINFORMATION);
    and that freaked things out. hmm..explanation?

    but i'm still getting a "there's no text entered" in a dif function.
    Code:
    BOOL CALLBACK SetPassProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
        switch(Message)
        {
            case WM_COMMAND:
                switch(LOWORD(wParam))
                {
                    case ID_PASSBTN:
                    {
                         int TxtLen;
                         HWND hEdit = GetDlgItem(hwnd, ID_PWDPROMPT);
                             
                         TxtLen = SendMessage(hEdit, WM_GETTEXTLENGTH, 0, 0);
                         TCHAR *buf = (TCHAR *)malloc (TxtLen+1); 
                         GetWindowText(hEdit, buf, TxtLen);
                         if (TxtLen <= 0) 
                         { MessageBox(hwnd, "There is no text entered.", "Error.", MB_OK | MB_ICONERROR); return FALSE; }
                         GetDlgItemText(hwnd, ID_PWDPROMPT, buf, TxtLen);
    			/* other code that doesn't get executed. */
    		}
    		break;
    	    }
            break;
    	default:
    	    return FALSE;
    	break;
        }
        return TRUE;
    }
    Last edited by willc0de4food; 07-04-2005 at 11:07 AM.
    Registered Linux User #380033. Be counted: http://counter.li.org

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hooking Crash?
    By Elysia in forum Windows Programming
    Replies: 9
    Last Post: 03-15-2008, 01:13 PM
  2. Can not debug a crash
    By hannibar in forum Windows Programming
    Replies: 2
    Last Post: 06-30-2007, 10:02 AM
  3. Dynamic array sizing causes crash
    By Mithoric in forum C++ Programming
    Replies: 3
    Last Post: 12-30-2003, 07:46 AM
  4. FYI: asctime(gmtime(&mytime)) = crash!
    By anonytmouse in forum C Programming
    Replies: 2
    Last Post: 09-29-2003, 02:24 AM
  5. Crash after crash!
    By Dual-Catfish in forum C++ Programming
    Replies: 1
    Last Post: 03-31-2002, 09:32 AM