EndDialog Function

This is a discussion on EndDialog Function within the Windows Programming forums, part of the Platform Specific Boards category; hello, my program must return a name from a dialog box to the "main" window , but i see that ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    113

    EndDialog Function

    hello,

    my program must return a name from a dialog box to the "main"
    window , but i see that the EndDialog Function only returns ints
    how i return a pointer to char(student name string) to the main window from a dialog box

    thanks for any help,

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    EndDialog returns an INT_PTR. An INT_PTR is guaranteed to be big enough to hold either an int or a pointer. This means that you can safely return a pointer which is cast to an INT_PTR.

    Here is some quick sample code. Error checking is omitted.
    Code:
    /* Set up the string to return. */
    char* pszStudentName = (char*) malloc(255);
    strcpy(pszStudentName, "Joe Blogs");
    
    /* Return string. */
    EndDialog(hDlg, (INT_PTR) pszStudentName);
    Code:
    /* Receive returned string. */
    char* pszStudentName = (char*) DialogBox(...);
    
    /* Free returned string when done. */
    free(pszStudentName);
    If you have the old header files, INT_PTR will not be defined. Simply add the following to the top of your file.
    Code:
    typedef int INT_PTR;
    If you are using C++, consider using new/delete in place of malloc/free.

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    113
    great!
    thanks for yer help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  4. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 01:28 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM

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