auto task = create_task(Windows::Storage::KnownFolders::PicturesLibrary->GetFilesAsync(Windows::Storage::Search::CommonFileQuery::OrderBySearchRank));
task.then([&sstrpath](Windows::Foundation::Collections::IVectorView<Windows::Storage::StorageFile^>^ files)
{
CCLog("num of files detected %d",files->Size);
Platform::String^ pathstr = files->GetAt(0)->Path;
OutputDebugStringW(pathstr->Data());
auto task2 = create_task(files->GetAt(0)->OpenAsync(Windows::Storage::FileAccessMode::Read));
task2.then([](Windows::Storage::Streams::IRandomAccessStream^ filestream)
{
Windows::UI::Xaml::Media::Imaging::BitmapImage^ bmp = ref new Windows::UI::Xaml::Media::Imaging::BitmapImage();
bmp->SetSource(filestream);
}
);
}
);
將其在Win8的RTM完成與VS表達RTM在C++(cocos2dx框架)。我正試圖從圖片庫中加載一個圖像,並從中創建一個BitmapImage。接下來是在cococs2dx中以某種方式使用BitmapImage for CCSprite,但這不是問題。該程序能夠一直運行到task2中,但在嘗試重新引入BitmmapImage時會崩潰。以下是在輸出控制檯加載圖像分成的BitmapImage
First-chance exception at 0x75004B32 in myGame.exe: Microsoft C++ exception:
Platform::WrongThreadException^at memory location 0x02D1D794. HRESULT:0x8001010E
First-chance exception at 0x75004B32 in myGame.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
First-chance exception at 0x75004B32 in myGame.exe: Microsoft C++ exception:
Platform::WrongThreadException^at memory location 0x02D1E5F0. HRESULT:0x8001010E
Unhandled exception at 0x622C9AD1 (msvcr110d.dll) in PixBlitz.exe: An invalid parameter was passed to a function that considers invalid parameters fatal.
我真的不知道在那裏根據適用於Win8應用程序開發的JavaScript或XAML是我做錯了,因爲大多數教程。
您的應用程序是否有權限訪問該文件位置和文件類型? – mydogisbox
是的,如果不是,執行不會通過第一個任務。 –