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. ATL / WTL / STL
  4. Capturing Events

Capturing Events

Scheduled Pinned Locked Moved ATL / WTL / STL
c++help
9 Posts 4 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.
  • L Offline
    L Offline
    Logan from Singapore
    wrote on last edited by
    #1

    Hi, I have a method the fires an event. But I have not been able to find the way to capture the event in VC++. I can get this event through VB but I need it in VC. Please help. Thanks in advance.

    Q 1 Reply Last reply
    0
    • L Logan from Singapore

      Hi, I have a method the fires an event. But I have not been able to find the way to capture the event in VC++. I can get this event through VB but I need it in VC. Please help. Thanks in advance.

      Q Offline
      Q Offline
      qfegd
      wrote on last edited by
      #2

      WaitForsingleObject http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/waitforsingleobject.asp[^] Eric Premature optimization is the root of all evil

      L 1 Reply Last reply
      0
      • Q qfegd

        WaitForsingleObject http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/waitforsingleobject.asp[^] Eric Premature optimization is the root of all evil

        L Offline
        L Offline
        Logan from Singapore
        wrote on last edited by
        #3

        Thanks Eric. Wasn't what I was look 4 but appreicated the help.

        L 1 Reply Last reply
        0
        • L Logan from Singapore

          Thanks Eric. Wasn't what I was look 4 but appreicated the help.

          L Offline
          L Offline
          Lim Bio Liong
          wrote on last edited by
          #4

          Hello w_logan, What you want to develop is an "Event Sink". If you are using ATL, create a class that inherits from IDispEventImpl. You will also need to include the BEGIN_SINK_MAP(), SINK_ENTRY_EX() and END_SINK_MAP() macros. Of course, your class will have to implement the event function itself. The great thing about the sink map macros is that you choose only those events that you want to supply handlers for. You do not need to implement handlers for all the events. An alternative to using the above-mentioned ATL constructs is to use my TEventHandler class. Please read my article : "Understanding COM Event Handling" (http://www.codeproject.com/com/TEventHandler.asp[^]) - Bio.

          L 1 Reply Last reply
          0
          • L Lim Bio Liong

            Hello w_logan, What you want to develop is an "Event Sink". If you are using ATL, create a class that inherits from IDispEventImpl. You will also need to include the BEGIN_SINK_MAP(), SINK_ENTRY_EX() and END_SINK_MAP() macros. Of course, your class will have to implement the event function itself. The great thing about the sink map macros is that you choose only those events that you want to supply handlers for. You do not need to implement handlers for all the events. An alternative to using the above-mentioned ATL constructs is to use my TEventHandler class. Please read my article : "Understanding COM Event Handling" (http://www.codeproject.com/com/TEventHandler.asp[^]) - Bio.

            L Offline
            L Offline
            Logan from Singapore
            wrote on last edited by
            #5

            Thanks Bio. I had already read the article when I was doing my research. It was a great article. I had initially intended to use "Event Sink" to solve my problem but I work around it by another mean. Actually, I had a COM DLL with multiple objects within it. But I had only expose the main object class. My problem arise when one of my internal object needs to fire a event to the app using my DLL. As only the main interface is expose, the internal object can't fire the event direct to the app. I was trying use the main object to sink the event and fire it again. But I never really got the way for doing the sink coding properly. Nonetheless, I worked around it by send the point to the main object inwards to the internal object and use this pointer to fire the event. It may not be the proper way to solve the problem but it solve my problem for now. Nonetheless, thanks for the help again. (If you remember, you had help this fellow Singaporean on several other occasion.) Cheers -- modified at 22:09 Tuesday 22nd November, 2005

            L 1 Reply Last reply
            0
            • L Logan from Singapore

              Thanks Bio. I had already read the article when I was doing my research. It was a great article. I had initially intended to use "Event Sink" to solve my problem but I work around it by another mean. Actually, I had a COM DLL with multiple objects within it. But I had only expose the main object class. My problem arise when one of my internal object needs to fire a event to the app using my DLL. As only the main interface is expose, the internal object can't fire the event direct to the app. I was trying use the main object to sink the event and fire it again. But I never really got the way for doing the sink coding properly. Nonetheless, I worked around it by send the point to the main object inwards to the internal object and use this pointer to fire the event. It may not be the proper way to solve the problem but it solve my problem for now. Nonetheless, thanks for the help again. (If you remember, you had help this fellow Singaporean on several other occasion.) Cheers -- modified at 22:09 Tuesday 22nd November, 2005

              L Offline
              L Offline
              Lim Bio Liong
              wrote on last edited by
              #6

              Hello w_logan, Yes, I remember you. We had corresponded som months ago I believe. How are you ? I hope you're doing well. Just a few comments : >> Actually, I had a COM DLL with multiple objects within it. But I had only expose the main object class. My problem arise when one of my internal object needs to fire a event to the app using my DLL. As only the main interface is expose, the internal object can't fire the event direct to the app. Comment : you may want to re-think about the design of your interfaces. Since the internal object needs to fire an event to your app, this may signal a need for the internal object's interface to be exposed to the app directly. On the other hand, if the internal object is meant to be internal afterall, then its events should rightfully be handled internally as well. The main object should be the handler for the event and it is a completely separate matter whether or not this main object ought to further "relay the message" to the app. >> I was trying use the main object to sink the event and fire it again. But I never really got the way for doing the sink coding properly. Comment : there are many ways to connect sinks with sources I guess. Just be careul about inter-thread event firing which will require marshaling. However, if everything happens on one thread, marshaling may not be so important. >> Nonetheless, I worked around it by send the point to the main object inwards to the internal object and use this pointer to fire the event. It may not be the proper way to solve the problem but it solve my problem for now. Comment : again, be careful about directly passing interface pointers here and there espacially across threads. Marshaling may be required. - Bio.

              T 1 Reply Last reply
              0
              • L Lim Bio Liong

                Hello w_logan, Yes, I remember you. We had corresponded som months ago I believe. How are you ? I hope you're doing well. Just a few comments : >> Actually, I had a COM DLL with multiple objects within it. But I had only expose the main object class. My problem arise when one of my internal object needs to fire a event to the app using my DLL. As only the main interface is expose, the internal object can't fire the event direct to the app. Comment : you may want to re-think about the design of your interfaces. Since the internal object needs to fire an event to your app, this may signal a need for the internal object's interface to be exposed to the app directly. On the other hand, if the internal object is meant to be internal afterall, then its events should rightfully be handled internally as well. The main object should be the handler for the event and it is a completely separate matter whether or not this main object ought to further "relay the message" to the app. >> I was trying use the main object to sink the event and fire it again. But I never really got the way for doing the sink coding properly. Comment : there are many ways to connect sinks with sources I guess. Just be careul about inter-thread event firing which will require marshaling. However, if everything happens on one thread, marshaling may not be so important. >> Nonetheless, I worked around it by send the point to the main object inwards to the internal object and use this pointer to fire the event. It may not be the proper way to solve the problem but it solve my problem for now. Comment : again, be careful about directly passing interface pointers here and there espacially across threads. Marshaling may be required. - Bio.

                T Offline
                T Offline
                ThatsAlok
                wrote on last edited by
                #7

                Lim Bio Liong wrote:

                - Bio.

                Hai Sir, I am waiting for an article on IDispEventImpl from your side :)...

                "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                cheers, Alok Gupta VC Forum Q&A :- I/ IV

                L 1 Reply Last reply
                0
                • T ThatsAlok

                  Lim Bio Liong wrote:

                  - Bio.

                  Hai Sir, I am waiting for an article on IDispEventImpl from your side :)...

                  "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                  cheers, Alok Gupta VC Forum Q&A :- I/ IV

                  L Offline
                  L Offline
                  Lim Bio Liong
                  wrote on last edited by
                  #8

                  Hello Alok ! How are you dear friend ? Enthusiastic as usual. It's very contagious :-) Yes, it'd be great if there's an in-depth dissertation on ATL's IDispEventImpl. Especially one that can show how to use it in MFC apps. I'll see if I can get some time on this. But how about yourself, Alok ? Would very much like to see you contribute another winner ! Best Regards, Bio.

                  T 1 Reply Last reply
                  0
                  • L Lim Bio Liong

                    Hello Alok ! How are you dear friend ? Enthusiastic as usual. It's very contagious :-) Yes, it'd be great if there's an in-depth dissertation on ATL's IDispEventImpl. Especially one that can show how to use it in MFC apps. I'll see if I can get some time on this. But how about yourself, Alok ? Would very much like to see you contribute another winner ! Best Regards, Bio.

                    T Offline
                    T Offline
                    ThatsAlok
                    wrote on last edited by
                    #9

                    Lim Bio Liong wrote:

                    How are you dear friend ? Enthusiastic as usual. It's very contagious

                    Ohh I am Alright Sir!.. As Usual :)..

                    Lim Bio Liong wrote:

                    Yes, it'd be great if there's an in-depth dissertation on ATL's IDispEventImpl. Especially one that can show how to use it in MFC apps. I'll see if I can get some time on this.

                    Thats would be Great :)... if you find some time for that!

                    Lim Bio Liong wrote:

                    But how about yourself, Alok ? Would very much like to see you contribute another winner !

                    Thats so nice of you, Sir!...But I am still in learning phase ... but as always its requires your help to get started :)...

                    "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                    cheers, Alok Gupta VC Forum Q&A :- I/ IV

                    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