Problem with GetDlgItemText()

This is a discussion on Problem with GetDlgItemText() within the Windows Programming forums, part of the Platform Specific Boards category; The follwing codes doesn't work: Code: TCHAR must_be_str; TCHAR entered[MAX}PATH]; strcpy(must_be_str,"b"); GetDlgItemText(hDlg, IDC_ENTER, entered, 5); itoa(must_be, must_be_two, 10); if(entered == ...

  1. #1
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052

    Problem with GetDlgItemText()

    The follwing codes doesn't work:
    Code:
    		  
    TCHAR must_be_str;
    TCHAR entered[MAX}PATH];
    strcpy(must_be_str,"b");
    GetDlgItemText(hDlg, IDC_ENTER, entered, 5); 
    itoa(must_be, must_be_two, 10);
    
    if(entered == must_be_str)
    {
        MessageBox(NULL, "It worked", "yay", MB_OK);
    }
    else
    {
        MessageBox(NULL, "Failed", "Damn", MB_OK);
        MessageBox(NULL, entered, "Value of 'entered'", MB_OK);
        MessageBox(NULL, must_be_str, "Value of 'must_be_str", MB_OK);
    }
    When this code runs, 'entered' shows up as blank and 'must_be_str' shows up as 0. Whats goin on?

    I put this on the Windows Programming board becuase there is obviously a problem with what I did with GetDlgItemText()...

    Thanks

  2. #2
    Registered User
    Join Date
    May 2002
    Posts
    50
    Try replacing

    entered[MAX}PATH];

    with

    entered[MAX_PATH];


    I'm not sure why your compiler doesn't give you an error about an undefined identifier "MAX}PATH". MAX_PATH is predefined to be a sufficiently large memory space to hold whatever you want. MAX}PATH isn't anything. That could be the problem.

  3. #3
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    that is just a typo that i must have done when I typed it out here - i didn't copy/paste. In the source, there's no brace.

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> strcpy(must_be_str,"b");

    You are using strcpy() to copy to a non-string destination...

    >>> if(entered == must_be_str)

    You cannot compare strings that way, either use strcmp() if you want to comapre things as strings, or subscript the array to compare character values...

    >>> GetDlgItemText(hDlg, IDC_ENTER, entered, 5);

    Check the return value, if it is zero, then the call failed, so call GetLastError() and see what went wrong...

    (From http://www.cprogramming.com/cboard/s...threadid=17871)

    >>> I already know C++ and Windows programming in C++.

    Are you sure?!?!
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  5. #5
    Unregistered
    Guest
    Originally posted by adrianxw


    >>> if(entered == must_be_str)

    You cannot compare strings that way, either use strcmp() if you want to comapre things as strings, or subscript the array to compare character values...
    In C++ you can compare strings that way

  6. #6
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> In C++ you can compare strings that way

    Not those kind of strings, you need to use one of the string classes with the == operator overloaded to acheive that.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  7. #7
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    >>Are you sure?!?!

    I've used GetDlgItemText() before successfully, there's just a mix up with all the string stuff...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 05:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 09:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM

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