Passing a string with PostMessage
-
I'm trying to pass some sort of character string with PostMessage or SendMessage (as the wparam). I got it to work, but I used a CString* and I'm not very happy with that solution. Two reasons: it's dangerous to play with memory across classes this way; and I need to call SendMessage to make sure the proper memory is removed (asynchronous nature of PostMessage causes leaks). Is there a better way to pass a string parameter to a PostMessage call? Thanks, Jason :confused:
-
I'm trying to pass some sort of character string with PostMessage or SendMessage (as the wparam). I got it to work, but I used a CString* and I'm not very happy with that solution. Two reasons: it's dangerous to play with memory across classes this way; and I need to call SendMessage to make sure the proper memory is removed (asynchronous nature of PostMessage causes leaks). Is there a better way to pass a string parameter to a PostMessage call? Thanks, Jason :confused:
First of all, the lounge is not the place for these type of posts. You're better off asking this question in one of the forums. But since we're on the subject, let's discuss a few choices. You can either: -- char *pStr = new char[200] strcpy(pStr, "hello world"); ... SendMessage(hWnd, (WPARAM)pStr, NULL) In the message handler you simply char * const pStr = (char *)wParam; delete [] pStr; -- As an alternative, if you strings are <255 characters, you can use AddAtom() and DeleteAtom() to have Windows manage memory for you. Use GlobalAddAtom() and GlobalDeleteAtom() if you're sending the message to a window of a different application. -Oz --- Grab WndTabs from http://www.wndtabs.com to make your VC++ experience that much more comfortable...