This is my Callback function:
void VideoCapturerSampleCallback(struct LmiVideoCapturer_* capturer, const LmiVideoFrame* videoFrame, LmiVoidPtr userData)
{
//TODO will have to be on ui thread;
Windows::ApplicationModel::Core::CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(0, ref new Windows::UI::Core::DispatchedHandler([this]()
{
Windows::UI::Xaml::Media::Imaging::BitmapImage^ bitmapImage =
ref new Windows::UI::Xaml::Media::Imaging::BitmapImage();
auto uri = ref new Windows::Foundation::Uri("ms-appx:///Assets/1.jpg");
if (first){
first = false;
}
else{
uri = ref new Windows::Foundation::Uri("ms-appx:///Assets/1.jpg");
first = true;
}
bitmapImage->UriSource = uri;
media->Source = bitmapImage;
}));
}
Which will basically change the picture every time the callback will be called, for now, I just change 2 pictures from Assets, in order to see if it works. This is the error I get in the logs:
Error 17 error C1903: unable to recover from previous error(s); stopping compilation C:\Users\Alin Rosu\Downloads\App2\App2\MainPage.xaml.cpp 109 1 App2
Error 16 error C3482: 'this' can only be used as a lambda capture within a non-static member function C:\Users\Alin Rosu\Downloads\App2\App2\MainPage.xaml.cpp 93 1 App2
19 IntelliSense: 'this' may only be used inside a nonstatic member function c:\Users\Alin Rosu\Downloads\App2\App2\MainPage.xaml.cpp 93 144 App2
18 IntelliSense: function "Windows::UI::Core::CoreDispatcher::RunAsync" cannot be called with the given argument list
argument types are: (int, Windows::UI::Core::DispatchedHandler ^)
object type is: Windows::UI::Core::CoreDispatcher ^ c:\Users\Alin Rosu\Downloads\App2\App2\MainPage.xaml.cpp 93 84 App2
Now is it possible to use that [this] inside the callback, without getting an error? I am a Android developer, so for me the logic response to this, was creating a global variable App2::MainPage, and then in the constructor, save "this" in it, so that I would have the context over there, and try to call RunAsync with that, but it does not work. Is it possible to instantiate the DispatchedHandler another way?