我正在尝试获取一些关于用户使用FileOpenPicker选择的文件的文件信息,但是所有的信息(如路径和名称)都是空的。当我试图在断点中查看对象时,我得到了以下消息:
文件= 0x03489cd4 <信息不可用,没有为shell32.dll>加载符号
我使用以下代码调用FileOpenPicker并处理该文件
#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");
}
});
}有人能看到代码出了什么问题,或者应用程序的设置出现了一些问题,为什么它不能像预期的那样工作。
发布于 2014-11-09 19:44:13
首先,解释调试困难的原因,在编写WinRT程序时,这种情况会发生得更多。首先,确保启用了正确的调试引擎。工具+选项,调试,一般。确保关闭“使用托管兼容性模式”。
现在您可以检查"file“选项,它应该如下所示:

当然很难理解。你所看到的是一个代理。它是一个COM术语,是一个COM对象的包装器,这些对象不是线程安全的,也不是存在于另一个进程或机器中的。代理实现驻留在proxy 32.dll中,因此出现了混乱的诊断消息。您根本看不到实际的对象,访问它的属性需要调用代理方法。调试器无法执行的一些事情,代理将调用从一个线程封送到另一个线程,另一个线程被冻结,而调试器中断是活动的。
这使您非常盲目,在困难的情况下,您可能需要编写少量的助手代码来将属性存储在局部变量中。比如:
auto path = file->Path;检查或观看那一个没什么问题。现在,您应该相信文件没有什么问题,并且您得到了一条非常好的路径。注意编写const wchar_t* path = file->Path;是如何引起编译器的强烈抱怨的。
它帮助您找到错误,您不能将Platform::String传递给printf()样式函数。就像你不能使用std::wstring一样。您需要使用访问器函数来转换它。修正:
_snwprintf_s(buf, 1024, _TRUNCATE,
L"Test: '%s'\n",
file->Path->Data());https://stackoverflow.com/questions/26701099
复制相似问题