2015-01-08 4 views
0

입니다 ++ 애셋에서 사진 2 장을 변경하여 효과가 있는지 확인하십시오.문제는이 내 콜백 기능/CX

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 

이제 그 [이] 콜백 내부 오류를받지 않고 사용할 수 있습니다 : 이것은 내가 로그에 얻을 오류가 무엇입니까? 나는 안드로이드 개발자이다. 그래서 나를위한 논리 응답은 App2 :: MainPage를 전역 변수로 만든 다음 생성자에서 "this"를 저장하면 거기에 컨텍스트가있게된다. RunAsync를 호출하려고 시도하지만 작동하지 않습니다. DispatchedHandler를 다른 방법으로 인스턴스화 할 수 있습니까?

답변

0

선언과 같은 맥락 :

App2::MainPage^ context; 
다음

MainPage 기능에서 설정 :

void VideoCapturerSampleCallback(struct LmiVideoCapturer_* capturer, const LmiVideoFrame* videoFrame, LmiVoidPtr userData) 
{ 
App2::MainPage^ ctx = context; 
Windows::ApplicationModel::Core::CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new Windows::UI::Core::DispatchedHandler([ctx]() 
{ 
    //TODO will need to set in here 
    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){ 
     XTRACE(L"===================FIIIIIIIIIIIIRST =======================\n"); 
     first = false; 
    } 
    else{ 
     XTRACE(L"===================FIIIIIIIIIIIIRST FAAAALSEEEEE=======================\n"); 
     uri = ref new Windows::Foundation::Uri("ms-appx:///Assets/2.jpg"); 
     first = true; 
    } 
    bitmapImage->UriSource = uri; 
    media->Source = bitmapImage; 
})); 
} 

:

MainPage::MainPage() 
{ 
InitializeComponent(); 
media = this->player; 
context = this; 
} 

을 그리고 나는이 식으로 VideoCapturerSampleCallback 내부에 그것을했다 이 문제가 해결되어 UI 스레드에서 UI를 수정할 수 있습니다.