C,C++
[C/C++/UWP] 사진라이브러리에서 jpg 파일 선택하기 ( C++/CX - Lambda )
덜지
2016. 7. 22. 03:42
# C++/CX Lambda
- 비동기 API 호출에 사용
- Lambda식 사용 : create_task(), then()
- 이벤트 핸들러(Win32에서 콜백함수)의 상당수를 Lambda식으로 전달
- I/O 관련 API는 모조리 Async
- Async API는 ppl task의 create_task()와 같이 사용
- create_task().then().then().then().... 가능
- create_task()는 Windows ThreadPool 사용하므로 task 생성 비용이 높지 않음
# 예제
1 2 3 4 | using namespace App3; using namespace Platform; using namespace Windows::Storage; using namespace concurrency; | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | void App3::Test::Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) { Windows::Storage::Pickers::FileOpenPicker^ picker = ref new Windows::Storage::Pickers::FileOpenPicker(); picker->ViewMode = Windows::Storage::Pickers::PickerViewMode::Thumbnail; picker->SuggestedStartLocation = Windows::Storage::Pickers::PickerLocationId::PicturesLibrary; picker->FileTypeFilter->Append(".jpg"); create_task(picker->PickSingleFileAsync()).then([this](Windows::Storage::StorageFile^ file) { if (file) { TestTextBlock->Text = "Success : " + file->Name; } else { TestTextBlock->Text = "Failed"; } }); } |