locked
Accessing Windows::UI::Core::InvokedHandler for methods with parameters

    Question

  • Hi,

     

    How can I invoke one method that has one or more parameters using the InvokedHandler?

    For example, I have one method:

     

     

    void MyNamespace::LoadItem(int par1int par2)

    {

    ...

    }

     

     

    And I tryied:

     

           auto callback = ref new Windows::UI::Core::InvokedHandler(

                        [this](Objectsender, Windows::UI::Core::InvokedHandlerArgseInvoke) { MyNamespace::LoadItem(val1, val2); },

                        CallbackContext::Any );

                 this->Dispatcher->Invoke(Windows::UI::Core::CoreDispatcherPriority::Normal, callback, thisnullptr);

     

    And it throws two errors like this:

     

    Error      2             error C3493: 'val1' cannot be implicitly captured because no default capture mode has been specified                c:\...\myPage.xaml.cpp               35           1             MyProject

     

    This question is related to: http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/4d3ad0da-1289-4561-a6be-cf5881944890

     

    Thanks a lot.


    • Edited by Leo Soares Thursday, January 12, 2012 1:36 AM
    Thursday, January 12, 2012 1:34 AM

All replies

  • Hi Leo,

     

    I can't see where you defined val1 and val2. Try using this syntax to capture the outer variables in your lambda that you are attempting to access:

     

     

    	int val1 = 1; int val2 = 2;
    	auto callback = ref new Windows::UI::Core::InvokedHandler(
     
            [val1, val2](Object^ sender, Windows::UI::Core::InvokedHandlerArgs^ eInvoke)
     {  MyNamespace::LoadItem(val1, val2); },
     
                        CallbackContext::Any );
     
                 this->Dispatcher->Invoke(Windows::UI::Core::CoreDispatcherPriority::Normal, callback, this, nullptr);

     

     

    Thanks,

    -David

     






    Friday, January 20, 2012 11:03 PM
    Moderator