windows-store-appswindows-8.1c++-cxfileopenpicker

windows 8 app FileOpenPicker np file info


I'm trying to get some file information about a file the user select with the FileOpenPicker, but all the information like the path and name are empty. When I try to view the object in a breakpoint I got the following message:

file = 0x03489cd4 <Information not available, no symbols loaded for shell32.dll>

I use the following code for calling the FileOpenPicker and handeling the file

#include "pch.h"
#include "LocalFilePicker.h"

using namespace concurrency;
using namespace Platform;
using namespace Windows::Storage;
using namespace Windows::Storage::Pickers;

const int LocalFilePicker::AUDIO = 0;
const int LocalFilePicker::VIDEO = 1;
const int LocalFilePicker::IMAGES = 2;

LocalFilePicker::LocalFilePicker()
{
    _init();
}

void LocalFilePicker::_init()
{
    _openPicker = ref new FileOpenPicker();
    _openPicker->ViewMode = PickerViewMode::Thumbnail;
}

void LocalFilePicker::askFile(int categorie)
{
    switch (categorie)
    {
    case 0:
        break;
    case 1:
        _openPicker->SuggestedStartLocation = PickerLocationId::VideosLibrary;
        _openPicker->FileTypeFilter->Append(".mp4");
        break;
    case 2:
        break;
    default:
        break;
}

create_task(_openPicker->PickSingleFileAsync()).then([this](StorageFile^ file)
{
    if (file)
    {
        int n = 0;
        wchar_t buf[1024];
        _snwprintf_s(buf, 1024, _TRUNCATE, L"Test: '%s'\n", file->Path);
        OutputDebugString(buf);
    }
    else
    {
        OutputDebugString(L"canceled");
    }
});
}

Can anybody see whats wrong with the code or some problems with settings for the app why it isn't work as expected.


Solution

  • First an explanation why you are having trouble debugging, this is going to happen a lot more when you write WinRT programs. First, do make sure that you have the correct debugging engine enabled. Tools + Options, Debugging, General. Ensure that the "Use Managed Compatibility Mode" is turned off.

    You can now inspect the "file" option, it should resemble this:

    enter image description here

    Hard to interpret of course. What you are looking at is a proxy. It is a COM term, a wrapper for COM objects that are not thread-safe or live in another process or machine. The proxy implementation lives in shell32.dll, thus the confuzzling diagnostic message. You can't see the actual object at all, accessing its properties requires calling proxy methods. Something that the debugger is not capable of doing, a proxy marshals the call from one thread to another, that other thread is frozen while the debugger break is active.

    That makes you pretty blind, in tough cases you may want to write a littler helper code to store the property in a local variable. Like:

       auto path = file->Path;
    

    No trouble inspecting or watching that one. You should now have confidence that there's nothing wrong with file and you get a perfectly good path. Note how writing const wchar_t* path = file->Path; gets you a loud complaint from the compiler.

    Which helps you find the bug, you can't pass a Platform::String to a printf() style function. Just like you can't with, say, std::wstring. You need to use an accessor function to convert it. Fix:

       _snwprintf_s(buf, 1024, _TRUNCATE, 
                    L"Test: '%s'\n",
                    file->Path->Data());