CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Oct 2003
    Location
    Minnesota
    Posts
    175

    Event Programming Question

    I have a project that is essentially a notifier to listening applications. The base class is a generic C++ class that simply manages data. When the data changes it needs to notify the listeners that something has changed. One of the methods of notification is events.

    I have already implemented an ATL class that has events within it. How does my base class notify the ATL class to fire the events?

    Sorry if this is simple - I think I am trying to make it more difficult then it actually is. Thanks in advance!

  2. #2
    Join Date
    Jul 2001
    Location
    Netherlands
    Posts
    751

    Re: Event Programming Question

    Usually the base class calls a virtual function that is implemented in your ATL class. The ATL class then raises the event with Fire_[eventname](args).

  3. #3
    Join Date
    Oct 2003
    Location
    Minnesota
    Posts
    175

    Re: Event Programming Question

    How does the base class call functions within another class?

    I created public virtual functions which call the corresponding Fire functions within my ATL class. Should I have created the virtual functions within my base class?

    Thanks for your help.

  4. #4
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: Event Programming Question

    See the "Observer pattern" at http://en.wikipedia.org/wiki/Observer_pattern

    Mike

  5. #5
    Join Date
    Oct 2003
    Location
    Minnesota
    Posts
    175

    Re: Event Programming Question

    Thank you all for your help thus far. I am still very confused however, and maybe it is because I am not being clear (or just am very confused and have my process implemented incorrectly).

    My base class is a generic C++ class which handles data. Within my project I have implemented ATL interfaces for other applications to communicate to me through to access data and to be notified when it changes. These are working fine, but I need to add one more option which is to raise an event when data changes. Is there a way to raise an event without an ATL class that everyone listening can hear?

  6. #6
    Join Date
    Jul 2001
    Location
    Netherlands
    Posts
    751

    Re: Event Programming Question

    No.

    class MyBase
    {
    virtual void DoFireWhatever(string strArg) ;
    };

    class ATL_NO_VTABLE YourAtlClass:
    ...
    {
    ...
    void DoFireWhatever(string strArg)
    {
    Fire_Whatever(strArg);
    }
    ...
    }

    The base class can just call DoFireWhatever and the ATL class takes it from there.

  7. #7
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: Event Programming Question

    Quote Originally Posted by drm15
    I have already implemented an ATL class that has events within it. How does my base class notify the ATL class to fire the events?
    Do you mean, you have implemented connection point container and connection point for the event notification ?

  8. #8
    Join Date
    Oct 2003
    Location
    Minnesota
    Posts
    175

    Re: Event Programming Question

    I apologize if my terminology is not correct (I assume it is not). I believe you are correct, I have implemented a connection point container. I am trying to follow the tutorials for creating an ATL interface class with connection points. I did this because that is the only way I know how to create global events to any attached process. I am trying to raise these events from my base class within this ATL class.

    I am currently trying to implement the previous suggestion to yours, but if you have anything I am open to suggestions. I seem to be very stuck on this and it doesn't seem like it should be this difficult.

  9. #9
    Join Date
    Oct 2003
    Location
    Minnesota
    Posts
    175

    Re: Event Programming Question

    I have attached my ATL class to try to make more sense. If anyone has an idea of how my base class can fire the events within my ContextParticipant class I am open to anything.

    Thank you all for your help!
    Attached Files Attached Files

  10. #10
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: Event Programming Question

    Your code doesn't contain the connection point implementation.
    I suggest reading this article.

    http://www.codeguru.com/cpp/com-tech...cle.php/c3623/

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