Menu

owl::TDispatchFunction

Alan Jones
2015-02-26
2017-06-30
  • Alan Jones

    Alan Jones - 2015-02-26

    I am converting my project from 6.30 to 6.40 using Visual Studio 2015 Community. Getting a number of compile errors. Most I can figure out but not this one:

    error C2440: 'initializing' : cannot convert from 'overloaded-function' to 'owl::TDispatchFunction'

    It is referring to the END_RESPONSE_TABLE for example:

      // [snip]
      EV_COMMAND(IDC_ENTER_EDIT, CmEnterCreate),
    END_RESPONSE_TABLE;
    


    Alan

    Moderator: Formatted the code.

     

    Last edit: Vidar Hasfjord 2015-03-02
  • Vidar Hasfjord

    Vidar Hasfjord - 2015-02-27

    Hi Alan,

    error C2440: 'initializing' : cannot convert from 'overloaded-function' to 'owl::TDispatchFunction'

    For 6.40, you get this error when a handler does not have the expected signature. Unfortunately, the error given by the MS compiler is unspecific and just points to the response table as a whole (END_RESPONSE_TABLE). Check the signatures for all the entries in the table.

    Some handler signatures have changed for 6.40. You can look up TDispatch in the reference documentation to get it right; e.g. TDispatch<WM_SIZE>. Google works well, e.g. "tdispatch wm_size". The correct signature is given by the second template parameter for the TDispatch::Decode function (e.g. for WM_SIZE it is "void(T::*)(uint, const TSize &)").

     

    Last edit: Vidar Hasfjord 2015-02-27
  • Vidar Hasfjord

    Vidar Hasfjord - 2015-02-27

    Also see the FAQ,

    > I get response table errors. Has something changed?

    It discusses a few other changes that may affect your code.

     
    • Ivan Stepanov

      Ivan Stepanov - 2017-06-30

      Hi Vidar,

      With moving to OWLNext 6.44, I start to change the Doc/View notification messages, and got the following problem:

      For example, I change vnMarkChanged notification that should call the following method of the TWindowView derived class:

      bool    VnMarkChanged( Mark* m );
      


      When I use a separate decode function template, as below, it works.

      template <class T, bool (T::*M)(Mark*)> 
      owl::TResult DecodeVnMarkChanged(void* i, owl::TParam1, owl::TParam2 p2) 
      {
          return (static_cast<T*>(i)->*M)(reinterpret_cast<Mark*>(p2)) ? TRUE : FALSE;
      }
      
      #define EV_VN_MARKCHANGED\
              VN_DEFINE( vnMarkChanged, VnMarkChanged, DecodeVnMarkChanged)
      


      But, when I use a decode function template that is defined within a dispatch template (as you recommended), I got the following error message:

      1>...cpp(647): error C2440: 'initializing': cannot convert from 'overloaded-function' to 'owl::TDispatchFunction'
      1>  ...cpp(647): note: None of the functions with this name in scope match the target type
      


      My code looks like this:

      template <> struct
      TMarkViewDispatch<WM_OWLNOTIFY>::TNotificationDispatch<vnMarkChanged>
      {
          template <class T, bool (T::*M)(Mark*)>
          TResult Decode(void* i, TParam1, TParam2 p2)
          {
              return (static_cast<T*>(i)->*M)(reinterpret_cast<Mark*>(p2)) ? TRUE : FALSE;
          }
      };
      
      #define EV_VN_MARKCHANGED\
          VN_DEFINE( vnMarkChanged, VnMarkChanged, TMarkViewDispatch<WM_OWLNOTIFY>::TNotificationDispatch<vnMarkChanged>::Decode)
      


      What is wrong?

      Best,
      Ivan Stepanov


      Moderator: Formatted code and clarified wording.

       

      Last edit: Vidar Hasfjord 2017-06-30
      • Vidar Hasfjord

        Vidar Hasfjord - 2017-06-30

        Hi Ivan,

        There is a bug in the documentation. The Decode function template should be static:

        template <> struct
        TMarkViewDispatch<WM_OWLNOTIFY>::TNotificationDispatch<vnMarkChanged>
        {
            template <class T, bool (T::*M)(Mark*)>
            static TResult Decode(void* i, TParam1, TParam2 p2)
            {
                return (static_cast<T*>(i)->*M)(reinterpret_cast<Mark*>(p2)) ? TRUE : FALSE;
            }
        };
        


        I will fix the documentation. Thanks for the feedback!

         
        • Ivan Stepanov

          Ivan Stepanov - 2017-06-30

          Hi Vidar,

          thanks for the prompt help.

           
  • Alan Jones

    Alan Jones - 2015-02-27

    Thanks for the response but I'm still lost. Here is the signature for the EV_COMMAND. What do I need to add to get my EV_COMMANDs to compile?

    //
    /// Response table entry for a menu/accelerator/push button message
    ///
    /// Required method signature:
    /// void method()
    //
    #define EV_COMMAND(id, method)\
      {{0}, id, OWL_DISPATCH(::owl::DispatchCommand, method)}
    


    Moderator: Formatted the code.

     

    Last edit: Vidar Hasfjord 2015-03-02
  • Alan Jones

    Alan Jones - 2015-02-27

    I discovered something on this problem by trial and error. In the following:

    DEFINE_RESPONSE_TABLE1(RSClientDialog, TDialog)
      EV_COMMAND(IDCANCEL,   CmCancel),
      EV_COMMAND(IDOK,       CmOk),
      EV_COMMAND(IDHELP,     CmHelp),
    END_RESPONSE_TABLE;
    

    The signatures for the three functions are:

    void TDialog::CmCancel();
    void RSClientDialog::CmOk();
    void RSClientDialog::CmHelp();
    

    If I make that first function a member of RSClientDialog instead of TDialog, the error goes away. Of course the new CmCancel() function has one line and that line calls TDialog::CmCancel();

    Is that what I have to do throughout my project?

    Alan

     

    Last edit: Alan Jones 2015-02-28
  • Alan Jones

    Alan Jones - 2015-02-28

    Of course, if I had read the documentation more carefully, I would have seen that the functions have to defined in the class. I'm making progress but still have a ways to go.

    Alan

     
  • Vidar Hasfjord

    Vidar Hasfjord - 2015-03-02

    Hi Alan, good to hear your port to 6.40 is making progress.

    As you found out, 6.40 requires that an event handler is defined in the class that owns the response table in which it is used. This is unfortunate with regard to backwards compatibility, but has some good side-effects; it prevents mistakes, such as forgetting to declare and define a handler, and using a handler in a base by mistake.

     

    Last edit: Vidar Hasfjord 2015-03-02
  • Anonymous

    Anonymous - 2015-05-21

    My code looks like as given below:

    DEFINE_RESPONSE_TABLE1(PtPartList,FDialog)
      EV_WM_PAINT,                // This is not working
      EV_WM_CLOSE                 // This is working
      EV_COMMAND(IDOK,EvSelect),  // This is working
    END_RESPONSE_TABLE;
    


    Here FDialog is derived from the TDialog. I am getting the below error for the EV_WM_PAINT only:

    error C2440: 'initializing' : cannot convert from 'overloaded-function' to 'owl::TDispatchFunction'

    Please suggest what to do ?

    --Gaurav--

    Moderator: Formatted code and error message.

     

    Last edit: Vidar Hasfjord 2015-05-21
  • Vidar Hasfjord

    Vidar Hasfjord - 2015-05-21

    Hi Gaurav, welcome to the forum!

    The correct signature for WM_PAINT is "void T::EvPaint()". See TDispatch <WM_PAINT>. Also, for OWLNext 6.40 and later, the handler needs to be defined in PtPartList (i.e. PtPartList::EvPaint), not in a base class. See earlier replies in this discussion thread and the FAQ.

     

Anonymous
Anonymous

Add attachments
Cancel