|
-
April 12th, 1999, 01:06 AM
#1
[RESOLVED] How do I know that a message has been processed?
In a previous query, someone gave me the following idea:
******************************
In the thread you can send the message using something like:
CString sendstring = _T("Send this text");
char *lpszPostedBytes = (char *) LocalAlloc(LPTR,sendstring.Length() + 1);
if (lpszPostedBytes != NULL)
{
strcpy(lpszPostedBytes, (LPCTSTR) sendstring);
PostMessage(myWnd, YOUR_MESSAGE, (LPARAM) lpszPostedBytes, 0L);
}
Then release the memory when the message been processed using:
LocalFree();
******************************
I've implemented this with only one problem. I don't know where, or when to release the memory using LocalFree().
If I do it after calling ::PostMessage(), it frees the memory before processing the message. So what do I do!!!!
-
April 12th, 1999, 01:45 AM
#2
Re: How do I know that a message has been processed?
Using SendMessage (instead of PostMessage) would help you. A call to SendMessage returns after the message has benn processed.
Otherwise you could always let the receiver of the message free the allocated bytes... But using SendMessage seams more appropiate.
------------------------------
Emil Gustafsson, [email protected]
NTier Solutions AB
-
April 12th, 1999, 01:49 AM
#3
Re: How do I know that a message has been processed?
Hi, I will try what you said. Only, someone suggested this earlier, but another person gave this reply:
check out:
http://www.codeguru.net/bbs/wt/showp...&sb=5#Post2579
Tell me what you think.
-
April 12th, 1999, 02:15 AM
#4
Re: How do I know that a message has been processed?
Hi again,
I've just tried SendMessage and all seems great to me - cheers!
-
April 12th, 1999, 03:38 AM
#5
Re: How do I know that a message has been processed?
Well, SendMessage is always a hazard if your code is written so that deadlocks might happen.
As I see it, to deadlock, when sending messages to the main app, there must be some "SendMessage" from the main app to the thread. i.e. to deadlock, two threads must send each other messages. If this is the case, you better let the receiver free data sent to them so that you may use PostMessage.
And, if you have threads sending messages to each other (and hence a risk for dead-locks) and don't want to let the receiver free the data, the problem (of deadlocks with SendMessage) can always be solved using critical sections...
------------------------------
Emil Gustafsson, [email protected]
NTier Solutions AB
-
April 12th, 1999, 03:44 AM
#6
Re: How do I know that a message has been processed?
Hi again
Thanks for the advice.
To be honest, my application is not that complicated. It begins another thread which sends messages back to the calling thread and not the other way, so I don't think a deadlock will happen.
-
April 12th, 1999, 03:57 AM
#7
Re: How do I know that a message has been processed?
Neither can I.
With one way communication there just can't be any deadlocks...
------------------------------
Emil Gustafsson, [email protected]
NTier Solutions AB
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|