wParam referring to A STRING...
-
I have a trouble like below description : My program has a dll file and a server application in the mydll.dll, I want to send a message to the server application. The message has the wParam referring to a string. I wrote my code : CString speak1; .... LPTSTR str = (LPTSTR)malloc((speak1.GetLength()+1) * sizeof(TCHAR)); ....//copy the data of the "speak1" to the "str" ::PostMessage(hMainWindow,WM_USER+1,(WPARAM)str,str.GetLength()+1); free(str) ; in my server application, I try to get the address of the string from the wParam. However, I can't get the content. Please, help me, point me to some pages or give me some intruction. Thanks a lot.
-
I have a trouble like below description : My program has a dll file and a server application in the mydll.dll, I want to send a message to the server application. The message has the wParam referring to a string. I wrote my code : CString speak1; .... LPTSTR str = (LPTSTR)malloc((speak1.GetLength()+1) * sizeof(TCHAR)); ....//copy the data of the "speak1" to the "str" ::PostMessage(hMainWindow,WM_USER+1,(WPARAM)str,str.GetLength()+1); free(str) ; in my server application, I try to get the address of the string from the wParam. However, I can't get the content. Please, help me, point me to some pages or give me some intruction. Thanks a lot.
vtalau wrote:
::PostMessage(hMainWindow,WM_USER+1,(WPARAM)str,str.GetLength()+1); free(str) ;
Use
SendMessage
instead ofPostMessage
. Otherwisefree(str)
will get executed before the message is processed. AsPostMessage
does not wait for the message to be processed.
Nibu thomas Software Developer
-
I have a trouble like below description : My program has a dll file and a server application in the mydll.dll, I want to send a message to the server application. The message has the wParam referring to a string. I wrote my code : CString speak1; .... LPTSTR str = (LPTSTR)malloc((speak1.GetLength()+1) * sizeof(TCHAR)); ....//copy the data of the "speak1" to the "str" ::PostMessage(hMainWindow,WM_USER+1,(WPARAM)str,str.GetLength()+1); free(str) ; in my server application, I try to get the address of the string from the wParam. However, I can't get the content. Please, help me, point me to some pages or give me some intruction. Thanks a lot.
You need to be using
new
anddelete
instead ofmalloc()
andfree()
. Otherwise, theCString
object's constructor and destructor do not get called. In addition, if you are going to usePostMessage()
, you'll need to movedelete
to the server so that it can free the memory after it is done with it.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"We will be known forever by the tracks we leave." - Native American Proverb