DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: For ATL expert - More Explanation : ... Function Pointer in a Class (ATL) ...

Hybrid View

  1. #1
    Guest

    For ATL expert - More Explanation : ... Function Pointer in a Class (ATL) ...

    First Thank you all for yor answer, i'm working on it right now ...

    And that's right, like Ralph and Dany have said :

    - "this is seldom a good idea. If you are using the 'services' of a class,
    import the class, not pieces of it."
    - "importing a piece of a class is rarely a good idea"

    Ok, let me expain my problem :
    ________________________________________________________________________

    class CclassB :
    {
    public:
    void (*fonction2) (double, double); // Wil be executed by an event in
    Process 2 (Exe application)
    }
    ________________________________________________________________________

    class ATL_NO_VTABLE CclassA :
    {
    public:
    CclassA()
    {
    CtheclassInside = new CclassB;
    CtheclassInside->fonction2 = fonction1;
    }
    CclassB* CtheclassInside;
    void fonction1 (double, double); // will fire an event in Process1,
    (visual basic form, single Exe)
    }

    ________________________________________________________________________

    The CclassA is a ATL class containing an event (IConnectionPoint) to fire
    in a 'Visual Basic Form', and the CclassB is loading in a process of an
    other 'Windows application'. This 'CclassB' is waiting for an event from
    this 'Windows application', and then has to execute the fire function
    'Fonction1' (Fire_MouseMove) of the ATL 'CclassA' to fire the event
    'MouseMove' in the 'Visual Basic Form' .

    'fonction1' will execute the public function 'Fire_MouseMove' of :
    _________________________________________________________________________

    template <class T>
    class CProxy_IclassAEvents : public IConnectionPointImpl<T,
    &DIID__IclassAEvents, CComDynamicUnkArray>
    {
    //Warning this class may be recreated by the wizard.
    public:
    VOID Fire_MouseMove(DOUBLE dPointX, DOUBLE dPointY)
    {
    T* pT = static_cast<T*>(this);
    int nConnectionIndex;
    CComVariant* pvars = new CComVariant[6];
    int nConnections = m_vec.GetSize();
    .....
    .....
    }
    };
    ___________________________________________________________________________

    Ralph, you said :

    - "If you are using the 'services' of a class, import the class, not pieces
    of it"

    I'm not sure it will be possible in this case ...

    -> So, what do you suggest ??? What can i do ?

    Thank's again...

    Driss.



  2. #2
    Ralph D. Cole Guest

    Re: For ATL expert - More Explanation : ... Function Pointer in a Class (ATL) ...


    <ndriss@club-internet.fr> wrote:
    >First Thank you all for yor answer, i'm working on it right now ...
    >
    >And that's right, like Ralph and Dany have said :
    >
    >- "this is seldom a good idea. If you are using the 'services' of a class,
    >import the class, not pieces of it."
    >- "importing a piece of a class is rarely a good idea"
    >
    >Ok, let me expain my problem :
    >________________________________________________________________________
    >
    >class CclassB :
    >{
    > public:
    > void (*fonction2) (double, double); // Wil be executed by an event in
    >Process 2 (Exe application)
    >}
    >________________________________________________________________________
    >
    >class ATL_NO_VTABLE CclassA :
    >{
    >public:
    > CclassA()
    > {
    > CtheclassInside = new CclassB;
    > CtheclassInside->fonction2 = fonction1;
    > }
    > CclassB* CtheclassInside;
    > void fonction1 (double, double); // will fire an event in Process1,
    >(visual basic form, single Exe)
    >}
    >
    >________________________________________________________________________
    >
    >The CclassA is a ATL class containing an event (IConnectionPoint) to fire
    >in a 'Visual Basic Form', and the CclassB is loading in a process of an
    >other 'Windows application'. This 'CclassB' is waiting for an event from
    >this 'Windows application', and then has to execute the fire function
    >'Fonction1' (Fire_MouseMove) of the ATL 'CclassA' to fire the event
    >'MouseMove' in the 'Visual Basic Form' .
    >
    >'fonction1' will execute the public function 'Fire_MouseMove' of :
    >_________________________________________________________________________
    >
    >template <class T>
    >class CProxy_IclassAEvents : public IConnectionPointImpl<T,
    >&DIID__IclassAEvents, CComDynamicUnkArray>
    >{
    >//Warning this class may be recreated by the wizard.
    >public:
    > VOID Fire_MouseMove(DOUBLE dPointX, DOUBLE dPointY)
    > {
    > T* pT = static_cast<T*>(this);
    > int nConnectionIndex;
    > CComVariant* pvars = new CComVariant[6];
    > int nConnections = m_vec.GetSize();
    > .....
    > .....
    > }
    >};
    >___________________________________________________________________________
    >
    >Ralph, you said :
    >
    >- "If you are using the 'services' of a class, import the class, not pieces
    >of it"
    >
    >I'm not sure it will be possible in this case ...
    >
    >-> So, what do you suggest ??? What can i do ?
    >
    >Thank's again...
    >
    > Driss.
    >


    Right off hand, you got me. There probably is a way to somehow coerce the
    compiler into doing what you want. However, I would probably invoke another
    general principle - "There is no programming problem that can't be resolved
    with another layer of indirection". <g>

    A while back I had a similar 3-ring circus which I handled with a separate
    "EventWatcher" class that I modified from an example in Chapter 6 of the
    "Beginning ATL COM Programming" book (Grimes, et al - Wrox). Not sure if
    it is a good fit for your problem domain or not. (Even sitting here looking
    at the book I can't remember all the details.)

    It worked on the idea that any COM component can 'listen' or 'fire' any
    number of events. It also had the advantage that once I got it working it
    became a general 'hammer' for a number of situations. The disadvantage is
    the impact on performance of the increased number of callbacks required.

    If I come up with anything else, I'll shout.


  3. #3
    Guest

    Re: For ATL expert - More Explanation : ... Function Pointer in a Class (ATL) ...

    Thank you very much for your quick answer Ralph ! ... I'm going to make some
    tries right now.

    And it's funny ! On tuesday evening, I was in a library and didn't know
    which book to buy, talking about ATL and COM. There was so many of them ...
    And it's so difficult to know which one is the good one (for me) just by
    reading the table of contents ... letting the chance guide my self ... I
    decided finaly to buy the Wrox book : 'Beginning ATL 3 COM Beginning
    programming' by Richard Grimes, and you are just talking about a chapter in
    it ! :-) So ... Ralph, thank you to have wait that i buy first the book
    before to talk about it in your answer ... :-) ...

    Driss.


    Driss

    "Ralph D. Cole" <nt_consulting32@SPAMhotmail.com> a écrit dans le message
    news: 3bd84bef$1@news.devx.com...
    >
    > <ndriss@club-internet.fr> wrote:
    > >First Thank you all for yor answer, i'm working on it right now ...
    > >
    > >And that's right, like Ralph and Dany have said :
    > >
    > >- "this is seldom a good idea. If you are using the 'services' of a

    class,
    > >import the class, not pieces of it."
    > >- "importing a piece of a class is rarely a good idea"
    > >
    > >Ok, let me expain my problem :
    > >________________________________________________________________________
    > >
    > >class CclassB :
    > >{
    > > public:
    > > void (*fonction2) (double, double); // Wil be executed by an event in
    > >Process 2 (Exe application)
    > >}
    > >________________________________________________________________________
    > >
    > >class ATL_NO_VTABLE CclassA :
    > >{
    > >public:
    > > CclassA()
    > > {
    > > CtheclassInside = new CclassB;
    > > CtheclassInside->fonction2 = fonction1;
    > > }
    > > CclassB* CtheclassInside;
    > > void fonction1 (double, double); // will fire an event in

    Process1,
    > >(visual basic form, single Exe)
    > >}
    > >
    > >________________________________________________________________________
    > >
    > >The CclassA is a ATL class containing an event (IConnectionPoint) to

    fire
    > >in a 'Visual Basic Form', and the CclassB is loading in a process of an
    > >other 'Windows application'. This 'CclassB' is waiting for an event from
    > >this 'Windows application', and then has to execute the fire function
    > >'Fonction1' (Fire_MouseMove) of the ATL 'CclassA' to fire the event
    > >'MouseMove' in the 'Visual Basic Form' .
    > >
    > >'fonction1' will execute the public function 'Fire_MouseMove' of :
    > >_________________________________________________________________________
    > >
    > >template <class T>
    > >class CProxy_IclassAEvents : public IConnectionPointImpl<T,
    > >&DIID__IclassAEvents, CComDynamicUnkArray>
    > >{
    > >//Warning this class may be recreated by the wizard.
    > >public:
    > > VOID Fire_MouseMove(DOUBLE dPointX, DOUBLE dPointY)
    > > {
    > > T* pT = static_cast<T*>(this);
    > > int nConnectionIndex;
    > > CComVariant* pvars = new CComVariant[6];
    > > int nConnections = m_vec.GetSize();
    > > .....
    > > .....
    > > }
    > >};

    >
    >___________________________________________________________________________
    > >
    > >Ralph, you said :
    > >
    > >- "If you are using the 'services' of a class, import the class, not

    pieces
    > >of it"
    > >
    > >I'm not sure it will be possible in this case ...
    > >
    > >-> So, what do you suggest ??? What can i do ?
    > >
    > >Thank's again...
    > >
    > > Driss.
    > >

    >
    > Right off hand, you got me. There probably is a way to somehow coerce the
    > compiler into doing what you want. However, I would probably invoke

    another
    > general principle - "There is no programming problem that can't be

    resolved
    > with another layer of indirection". <g>
    >
    > A while back I had a similar 3-ring circus which I handled with a separate
    > "EventWatcher" class that I modified from an example in Chapter 6 of the
    > "Beginning ATL COM Programming" book (Grimes, et al - Wrox). Not sure if
    > it is a good fit for your problem domain or not. (Even sitting here

    looking
    > at the book I can't remember all the details.)
    >
    > It worked on the idea that any COM component can 'listen' or 'fire' any
    > number of events. It also had the advantage that once I got it working it
    > became a general 'hammer' for a number of situations. The disadvantage is
    > the impact on performance of the increased number of callbacks required.
    >
    > If I come up with anything else, I'll shout.
    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center