WinRT API WIndows::System::Launcher::LaunchFileAsync() usage from C++ -


i'm trying launch image using winrt api windows::system::launcher::launchfileasync().

code snippet follows:

roinitialize(ro_init_multithreaded);                 string^ imagepath = ref new string(l"c:\\users\\goodman\\pictures\\wood.png");   auto file = storage::storagefile::getfilefrompathasync(imagepath);   windows::system::launcher::launchfileasync(file); 

i'm getting error launchfileasync() api:

error c2665: 'windows::system::launcher::launchfileasync' : none of 2 overloads convert argument types

can please how solve this. i'm new winrt c++ coding .

the method getfilefrompathasync not return storagefile, returns iasyncoperation<storagefile>^. have convert latter former, follows:

using namespace concurrency;  string^ imagepath = ref new string(l"c:\\users\\goodman\\pictures\\wood.png"); auto task = create_task(windows::storage::storagefile::getfilefrompathasync(imagepath)); task.then([this](windows::storage::storagefile^ file) {     windows::system::launcher::launchfileasync(file); }); 

generally windows store app framework methods end in async return either iasyncoperation, or task. these methods known asynchronous methods, , require special handling. see article more info: asynchronous programming in c++ .


so great, correct? well, not quite. there issue code. when run code above, access-denied error. reason windows store apps sandboxed, , cannot access file on filesystem.

you in luck, though, because trying access file in pictures folder. pictures folder special folder windows store apps have access to. can @ using knownfolders class:

using namespace concurrency;  windows::storage::storagefolder^ pictures =     windows::storage::knownfolders::pictureslibrary; auto task = create_task(pictures->getfileasync("wood.png"));  task.then([this](windows::storage::storagefile^ file) {     windows::system::launcher::launchfileasync(file); }); 

note in order access pictures folder application has declare in project manifest. so, double click on package.appmanifest file in project "tree" in visual studio, , select capabilities tab. under capabilities, check pictures library.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -