Home Forums Software Development [C++] static callback function to member function

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1469
    Escallon
    Participant

    Hello,

    I followed one of the example contained in the eyeX SDK to use a callback function as a member function of my class and not a static function.

    bool EyeXHost::RegisterConnectionStateChangedHandler()
    {
        // we pass the "this" pointer as the user parameter when registering the event handler,
        // so that we can access it in the callback function.
    
        auto connectionStateChangedTrampoline = [](TX_CONNECTIONSTATE connectionState, TX_USERPARAM userParam)
        {
            static_cast<EyeXHost*>(userParam)->OnEngineConnectionStateChanged(connectionState);
        };
    
        bool success = txRegisterConnectionStateChangedHandler(
            m_context,
            &m_connectionStateChangedTicket,
            connectionStateChangedTrampoline,
            this) == TX_RESULT_OK;
    
        return success;
    }

    but compilation fails saying ‘txRegisterConnectionStateChangedHandler’ : cannot convert parameter 3 from ‘`anonymous-namespace’::<lambda0>’ to ‘TX_CONNECTIONSTATECHANGEDCALLBACK’

    I wonder if something is missing in the example ? Maybe the is another way to do that… I use QtCreator with Qt5.3 and MVSC2010 compiler.

    Thanks you

    #1470
    Jenny [Tobii]
    Participant

    Hi Escallon,

    It seems it may be a bug in the implementation of lambda expressions in the MSVC 2010 redistributable: https://connect.microsoft.com/VisualStudio/feedback/details/572138

    That bug report is marked as closed, but there is no information about in which version the fix was included. Maybe you could try downloading the latest MSVC 2010 redist and see if that helps.

    #1471
    Escallon
    Participant

    Ok thanks,
    I will take a look on it.
    Also, Why both of the C++ examples given in the SDK use C entities like TX_CONNECTIONSTATECHANGEDCALLBACK instead of ConnectionStateChangedCallback, found in EyeXClientTypes.h :

    namespace Tx {
    typedef std::function<void (TX_CONNECTIONSTATE)>
    ConnectionStateChangedCallback;
    }

    ?
    That’s might be useful to avoid this error.
    Is there a 100% C++ example/doc available ?

    Best regards

    #1473
    Jenny [Tobii]
    Participant

    Hi Escallon,

    Yes, the current C/C++ samples are written using the C API directly. It was important for us initially to have the C API exercised as much as possible so we could find areas of improvement and simplification.

    But now it is definately on our todo list to have a new take on the C/C++ SDK and write samples using the C++ binding. Inspired by the .NET SDK we have developed since, we will probably extract and expand common functionality into a separate EyeXFramework for C++ and provide some code integrating EyeX into one or two specific C++ GUI frameworks.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.