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,
Printable View
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,
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);
If you have the old header files, INT_PTR will not be defined. Simply add the following to the top of your file.Code:/* Receive returned string. */
char* pszStudentName = (char*) DialogBox(...);
/* Free returned string when done. */
free(pszStudentName);
If you are using C++, consider using new/delete in place of malloc/free.Code:typedef int INT_PTR;
great!
thanks for yer help