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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. problem in triggering events

problem in triggering events

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++question
7 Posts 3 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.
  • R Offline
    R Offline
    rajeev82
    wrote on last edited by
    #1

    Hi all, i've developed a dialog based application, which has to respond for certain events (ex:when the sound filled in a buffer has stopped playing.. etc). To achieve this i've used the function, MsgWaitForMultipleObjects( 1, &g_hNotificationEvent,FALSE, INFINITE, QS_ALLEVENTS ); where, g_hNotificationEvent --> handle to the event to be triggered. the problem what i'm facing is,where to place this function? if i put this within OnInitDialog the application stops executing further.The problem will be solved if this function is placed within WinMain() ,but where i do i find WinMain in a dialog based MFC application? It'll be really great if someone can help me out in this. Thanks and regards, rajeev

    C R 2 Replies Last reply
    0
    • R rajeev82

      Hi all, i've developed a dialog based application, which has to respond for certain events (ex:when the sound filled in a buffer has stopped playing.. etc). To achieve this i've used the function, MsgWaitForMultipleObjects( 1, &g_hNotificationEvent,FALSE, INFINITE, QS_ALLEVENTS ); where, g_hNotificationEvent --> handle to the event to be triggered. the problem what i'm facing is,where to place this function? if i put this within OnInitDialog the application stops executing further.The problem will be solved if this function is placed within WinMain() ,but where i do i find WinMain in a dialog based MFC application? It'll be really great if someone can help me out in this. Thanks and regards, rajeev

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      Start a separate thread to check for that, otherwise your GUI will freeze until you receive the event. Once the event is received in your thread, send a user defined message to your dialog to specify that the event is finished.

      1 Reply Last reply
      0
      • R rajeev82

        Hi all, i've developed a dialog based application, which has to respond for certain events (ex:when the sound filled in a buffer has stopped playing.. etc). To achieve this i've used the function, MsgWaitForMultipleObjects( 1, &g_hNotificationEvent,FALSE, INFINITE, QS_ALLEVENTS ); where, g_hNotificationEvent --> handle to the event to be triggered. the problem what i'm facing is,where to place this function? if i put this within OnInitDialog the application stops executing further.The problem will be solved if this function is placed within WinMain() ,but where i do i find WinMain in a dialog based MFC application? It'll be really great if someone can help me out in this. Thanks and regards, rajeev

        R Offline
        R Offline
        Roger Stoltz
        wrote on last edited by
        #3

        Umm.. The whole thing about having an event signaled is the use of multiple threads. Since you seem to have only one thread I don't understand why you consider this solution. Why don't you post a user defined message from where you are signalling the event and write a message handler for that message instead? -- Roger


        It's suppose to be hard, otherwise anybody could do it!

        R 1 Reply Last reply
        0
        • R Roger Stoltz

          Umm.. The whole thing about having an event signaled is the use of multiple threads. Since you seem to have only one thread I don't understand why you consider this solution. Why don't you post a user defined message from where you are signalling the event and write a message handler for that message instead? -- Roger


          It's suppose to be hard, otherwise anybody could do it!

          R Offline
          R Offline
          rajeev82
          wrote on last edited by
          #4

          Let me explain the application more clearly. i've a demodulator hardware which keeps pumping out some sound data which is being feed to a sound card. I've used "DirectX" to achieve this. when the sound fed to the card has finished playing ,the application has to be notified so that it can fill the buffer with new data and play it again.This process has to repeat continuously. Please let me know whether using MsgWaitForMultipleObjects(...)is a good idea ? rajeev -- modified at 6:54 Thursday 27th April, 2006

          R R 2 Replies Last reply
          0
          • R rajeev82

            Let me explain the application more clearly. i've a demodulator hardware which keeps pumping out some sound data which is being feed to a sound card. I've used "DirectX" to achieve this. when the sound fed to the card has finished playing ,the application has to be notified so that it can fill the buffer with new data and play it again.This process has to repeat continuously. Please let me know whether using MsgWaitForMultipleObjects(...)is a good idea ? rajeev -- modified at 6:54 Thursday 27th April, 2006

            R Offline
            R Offline
            Roger Stoltz
            wrote on last edited by
            #5

            rajeev82 wrote:

            MsgWaitForMultipleObjects(...)is a good idea ?

            It depends on how you know when your demodulator has finished feeding the sound card... If it signals an event, then I suggest you create a worker thread simply waits for the event with WaitFormUltipleObjects(), presumably there's no need to process messages. If a message gets posted you write a message handler and restart the feeding process from there. To be able to help you futher we need to know how you can tell when the demodulator has finished feeding the sound card. -- Roger


            It's suppose to be hard, otherwise anybody could do it!

            1 Reply Last reply
            0
            • R rajeev82

              Let me explain the application more clearly. i've a demodulator hardware which keeps pumping out some sound data which is being feed to a sound card. I've used "DirectX" to achieve this. when the sound fed to the card has finished playing ,the application has to be notified so that it can fill the buffer with new data and play it again.This process has to repeat continuously. Please let me know whether using MsgWaitForMultipleObjects(...)is a good idea ? rajeev -- modified at 6:54 Thursday 27th April, 2006

              R Offline
              R Offline
              rajeev82
              wrote on last edited by
              #6

              The demodulator doesnt feed the data to the sound card directly.Itz my program which collects the data from the demodulator and feeds it to the sound card so that it can be heard.the sound which comes out from the demodulator is in chunks of 4096 points. In directx there is a interface called IDirectSoundNotify which will notify my application when one chunk of 4096 has been played ,so that the next 4096 points can be loaded ,played and so on. as long my application runs the demodulator will work and it'll pump out something(atleast noise).so please tell me how to call a function according to the notification i receive. rajeev

              R 1 Reply Last reply
              0
              • R rajeev82

                The demodulator doesnt feed the data to the sound card directly.Itz my program which collects the data from the demodulator and feeds it to the sound card so that it can be heard.the sound which comes out from the demodulator is in chunks of 4096 points. In directx there is a interface called IDirectSoundNotify which will notify my application when one chunk of 4096 has been played ,so that the next 4096 points can be loaded ,played and so on. as long my application runs the demodulator will work and it'll pump out something(atleast noise).so please tell me how to call a function according to the notification i receive. rajeev

                R Offline
                R Offline
                Roger Stoltz
                wrote on last edited by
                #7

                Well, given that I've understood your problem correctly I suggest the following: 1. Set up interface sinks and create objects necessary. 2. Create a worker thread that gathers the data from the demodulator and put the data in a queue which is read from... 3. a second worker thread that feeds the sound card and waits for an event which gets signalled when your app is notified using WFMO(). 4. Marshal needed interfaces to your threads before you unleash them. (Create them suspended.) This will keep the GUI responsive since the main thread is not blocked. You should also get the notification in the main thread. Read JoeNewcomer's article[^] about multithreading if you are unfamiliar with the subject. Hope this helps -- Roger


                It's suppose to be hard, otherwise anybody could do it!

                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