积极答复者
OpenAsync提示 0x40080201: WinRT originate error 错误

问题
-
在工程从VS2012升级到VS2013之后,读取文件内容的回调函数中的OpenAsync运行之后提示:
0x764D2EEC (KernelBase.dll) (codename.exe 中)处的第一机会异常: 0x40080201: WinRT originate error (参数: 0x80004001, 0x00000006, 0x057DA7D0)。
这是什么原因引起的呢? 附上问题代码
这个函数的作用是同步取得偏移量为offset大小为size的文件数据,然后将其拷贝到buffer中。 StorageFile指针放在clientData中。
BOOL ReadBlock_ReLoadInFile(LPVOID clientData, void* buffer, FS_DWORD offset, FS_DWORD size,HANDLE processingHandle) { if(clientData == NULL) return FALSE; FileData* pFileData = (FileData*)clientData; OutputDebugString(L"OpenAsync\n"); auto OpenOp = pFileData->FileStream->OpenAsync(FileAccessMode::ReadWrite); //用传递进来的StorageFile 打开文件,运行完这句代码之后,Output输出异常。 OpenOp->Completed = ref new AsyncOperationCompletedHandler<IRandomAccessStream^>([buffer,offset,size,processingHandle](IAsyncOperation<IRandomAccessStream^>^ operation,Windows::Foundation::AsyncStatus status) { if(status == Windows::Foundation::AsyncStatus::Completed) { IRandomAccessStream^ readStream = operation->GetResults(); readStream->Seek(offset); DataReader^ dataReader = ref new DataReader(readStream); auto LoadOp = dataReader->LoadAsync(size); LoadOp->Completed = ref new AsyncOperationCompletedHandler<unsigned int>([buffer,dataReader,processingHandle](IAsyncOperation<unsigned int>^ operation,Windows::Foundation::AsyncStatus status) { if(status == Windows::Foundation::AsyncStatus::Completed) { int numBytesLoaded = operation->GetResults(); if(numBytesLoaded > 0) { Array<unsigned char,1>^ fileContent =ref new Array<unsigned char,1>(numBytesLoaded); dataReader->ReadBytes(fileContent); memcpy(buffer,fileContent->Data,numBytesLoaded); dataReader->DetachStream(); } SetEvent(processingHandle); } else { OutputDebugString(L"LoadAsync status ERROR!!!!!\n"); SetEvent(processingHandle); } }); } else { OutputDebugString(L"status ERROR!!!!!\n"); SetEvent(processingHandle); } }),task_continuation_context::use_arbitrary(); WaitForSingleObjectEx(processingHandle, INFINITE, true); CloseHandle(processingHandle); return TRUE; }
答案
-
你好,
现在VS 2013确实会有一些需要修复的地方。比如有的用户会抱怨智能感知会误报、智能感知会不进行提示等。
我这里并没有动态库异常,而且你所指出的异常我也没法跟进调试。因为这个错误来自于KernelBase.dll。
(注:还有一些其他用户也在反应该问题(英文论坛))
我将收集该信息,并向微软提交此现象,感谢你对MSDN的支持!
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已建议为答案 Xiaoliang Chen - MSFTModerator 2013年10月25日 7:34
- 已标记为答案 Xiaoliang Chen - MSFTModerator 2013年10月31日 7:32
全部回复
-
你好,
资源具有访问限定。 你首先需要去Package.appxmanifest 文件中设定访问权限。双击 上述文件,在Capabilities选项卡中选定你需要的资源。
希望上述方法能够帮到你。
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey. -
你好,
我自己写了一段代码,在VS2012 和 VS2013 均调试通过了。以下是我的代码:
create_task(Windows::Storage::KnownFolders::DocumentsLibrary->CreateFileAsync(ref new Platform::String(L"abc.text"),Windows::Storage::CreationCollisionOption::ReplaceExisting)).then([](Windows::Storage::StorageFile^ myfile){ auto my_file=myfile->OpenAsync(Windows::Storage::FileAccessMode::Read); });
如果你在Package.appxmainifest中以及 Decalarations 申请了对你特定类型文件的访问权限,
<Extension Category="windows.fileTypeAssociation"> <FileTypeAssociation Name="text"> <SupportedFileTypes> <FileType>.text</FileType> </SupportedFileTypes> </FileTypeAssociation> </Extension>
按理说应该不会有任何问题,如果有,你将文件访问权限限制为只读后试试。
希望上述能够帮到你!
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey. -
上述的方案还是没法解决问题,我注意到上面的代码是从Windows::Storage::KnownFolders 中去打开文件,请尝试从文件选择器中打开文件,应该就可以重现问题了。
auto openPicker = ref new FileOpenPicker(); openPicker->ViewMode = PickerViewMode::List; openPicker->SuggestedStartLocation = PickerLocationId::DocumentsLibrary; openPicker->FileTypeFilter->Append(".text"); task<StorageFile^> OpenFileTask(openPicker->PickSingleFileAsync()); OpenFileTask.then([this](StorageFile^ openedFile) { if (openedFile != nullptr) { auto OpenOp = openedFile->OpenAsync(Windows::Storage::FileAccessMode::ReadWrite); //this call 0x40080201: WinRT originate error OpenOp->Completed = ref new AsyncOperationCompletedHandler<IRandomAccessStream^>([this](IAsyncOperation<IRandomAccessStream^>^ operation, Windows::Foundation::AsyncStatus status) { //do somethine }
} });
- 已编辑 WillSu 2013年10月25日 6:26
-
你好,
我复制你的代码并进行调试,结果很正常,能够读取到文件。
请用XML方式打开Package.appxmanifest 并确认你已经完成了声明。或者你可以下载一个sample, File Access Sample,调试成功后,将测试代码copy进去,然后再试一次,来排除VS本身问题。如果结果依然错误,我想,你可能需要重新安装VS2013.
希望上述能帮到你!
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey. -
你好,
现在VS 2013确实会有一些需要修复的地方。比如有的用户会抱怨智能感知会误报、智能感知会不进行提示等。
我这里并没有动态库异常,而且你所指出的异常我也没法跟进调试。因为这个错误来自于KernelBase.dll。
(注:还有一些其他用户也在反应该问题(英文论坛))
我将收集该信息,并向微软提交此现象,感谢你对MSDN的支持!
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已建议为答案 Xiaoliang Chen - MSFTModerator 2013年10月25日 7:34
- 已标记为答案 Xiaoliang Chen - MSFTModerator 2013年10月31日 7:32