CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Andrew Truckle Guest

    [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!!!!



  2. #2
    Join Date
    May 1999
    Location
    Sweden
    Posts
    10

    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

  3. #3
    Andrew Truckle Guest

    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.


  4. #4
    Andrew Truckle Guest

    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!


  5. #5
    Join Date
    May 1999
    Location
    Sweden
    Posts
    10

    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

  6. #6
    Andrew Truckle Guest

    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.


  7. #7
    Join Date
    May 1999
    Location
    Sweden
    Posts
    10

    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
  •  





Click Here to Expand Forum to Full Width

Featured