Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Multithreading - passing message to a window question

Multithreading - passing message to a window question

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionannouncementdebugging
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Indrawati
    wrote on last edited by
    #1

    Hi I have an app that use multithreading to update the display of a window. I use AfxBeginThread() to spawn the thread, passing a copy of the window's m_hWnd as its parameter. This thread will then execute SendMessage() to update the window's display. This works OK in the Debug mode. However, in the release mode, it always gives error (The app has encountered a problem and will be closed etc2) whenever I have spawned two of the said threads, and then I switched window! This error still occurs even if I make the member function processing the message to do no processing (i.e. it just returns). However, this error does not occur if I comment out the SendMessage() line in the thread's function. I have tried using PostMessage() instead of SendMessage(), but with the same result. Could someone tell me what's the possible cause for this? Thanks!

    M R R 3 Replies Last reply
    0
    • I Indrawati

      Hi I have an app that use multithreading to update the display of a window. I use AfxBeginThread() to spawn the thread, passing a copy of the window's m_hWnd as its parameter. This thread will then execute SendMessage() to update the window's display. This works OK in the Debug mode. However, in the release mode, it always gives error (The app has encountered a problem and will be closed etc2) whenever I have spawned two of the said threads, and then I switched window! This error still occurs even if I make the member function processing the message to do no processing (i.e. it just returns). However, this error does not occur if I comment out the SendMessage() line in the thread's function. I have tried using PostMessage() instead of SendMessage(), but with the same result. Could someone tell me what's the possible cause for this? Thanks!

      M Offline
      M Offline
      Milton Karimbekallil
      wrote on last edited by
      #2

      Since the prblm is with release build only , mostly it will be a memory initialiaztion/allocation prblm. Since both SendMessage and PostMessage failed, mostly the prblm will be with the initialiaztion of one of the parameter to these functions. chk whether hwnd is initialized as below. HWND hWnd = NULL; or use AfxGetApp()->GetMainWnd()->SendMessage rgds .. mil10

      1 Reply Last reply
      0
      • I Indrawati

        Hi I have an app that use multithreading to update the display of a window. I use AfxBeginThread() to spawn the thread, passing a copy of the window's m_hWnd as its parameter. This thread will then execute SendMessage() to update the window's display. This works OK in the Debug mode. However, in the release mode, it always gives error (The app has encountered a problem and will be closed etc2) whenever I have spawned two of the said threads, and then I switched window! This error still occurs even if I make the member function processing the message to do no processing (i.e. it just returns). However, this error does not occur if I comment out the SendMessage() line in the thread's function. I have tried using PostMessage() instead of SendMessage(), but with the same result. Could someone tell me what's the possible cause for this? Thanks!

        R Offline
        R Offline
        Ravi Bhavnani
        wrote on last edited by
        #3

        This[^] article may help. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

        1 Reply Last reply
        0
        • I Indrawati

          Hi I have an app that use multithreading to update the display of a window. I use AfxBeginThread() to spawn the thread, passing a copy of the window's m_hWnd as its parameter. This thread will then execute SendMessage() to update the window's display. This works OK in the Debug mode. However, in the release mode, it always gives error (The app has encountered a problem and will be closed etc2) whenever I have spawned two of the said threads, and then I switched window! This error still occurs even if I make the member function processing the message to do no processing (i.e. it just returns). However, this error does not occur if I comment out the SendMessage() line in the thread's function. I have tried using PostMessage() instead of SendMessage(), but with the same result. Could someone tell me what's the possible cause for this? Thanks!

          R Offline
          R Offline
          Rory Solley
          wrote on last edited by
          #4

          I presume you are passing a custom message to your window, e.g. WM_MYMESSAGE or something (defined from WM_USER + or you've used RegisterMessage)? I'm also assuming that your message handler is something like: LRESULT OnMyMessage(WPARAM wParam, LPARAM lParam); You MUST make sure that you include the WPARAM and LPARAM arguments. Omitting them will work in DEBUG but will NOT work in release build. This is due to the way the stack is padded in debug builds. In a release build, the message map will expect the arguments - if they're not there, you will corrupt the stack, resulting in an exception. Apologies if this is not what you're after, I'm just making blind assumptions from your original post.

          A 1 Reply Last reply
          0
          • R Rory Solley

            I presume you are passing a custom message to your window, e.g. WM_MYMESSAGE or something (defined from WM_USER + or you've used RegisterMessage)? I'm also assuming that your message handler is something like: LRESULT OnMyMessage(WPARAM wParam, LPARAM lParam); You MUST make sure that you include the WPARAM and LPARAM arguments. Omitting them will work in DEBUG but will NOT work in release build. This is due to the way the stack is padded in debug builds. In a release build, the message map will expect the arguments - if they're not there, you will corrupt the stack, resulting in an exception. Apologies if this is not what you're after, I'm just making blind assumptions from your original post.

            A Offline
            A Offline
            Anonymous
            wrote on last edited by
            #5

            Hi Thank you thank you thank you! Yep it's exactly what I'm looking for. The program's OK now when I modified the OnMyMessage() function.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups