我使用的是Windows 7 64位和Visual Studio C ++ 2017社区。我正在尝试使用IFileOpenDialog
创建一个Windows打开文件对话框,但在程序结束时我不断收到这两个访问冲突错误:
Exception thrown at 0x00000000771ED1CB (ntdll.dll) in p.exe: 0xC0000005: Access violation reading location 0x0000000000000074.
Exception thrown at 0x00000000771DDC9D (ntdll.dll) in p.exe: 0xC0000005: Access violation reading location 0x0000000000000074.
为了调试访问冲突,我评论了所有内容并从Microsoft's online example复制了代码,但错误不会消失。这似乎是由pFileOpen->Show(NULL);
电话引起的。但是,我最终创建了一个新项目,并将相同的代码放入其中,瞧,它有效!这是示例的样子:
#include <windows.h>
#include <shobjidl.h>
int main()
{
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED |
COINIT_DISABLE_OLE1DDE);
if (SUCCEEDED(hr))
{
IFileOpenDialog *pFileOpen;
// Create the FileOpenDialog object.
hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL,
IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen));
if (SUCCEEDED(hr))
{
// Show the Open dialog box.
hr = pFileOpen->Show(NULL); <-------**Culprit**
// Get the file name from the dialog box.
if (SUCCEEDED(hr))
{
IShellItem *pItem;
hr = pFileOpen->GetResult(&pItem);
if (SUCCEEDED(hr))
{
PWSTR pszFilePath;
hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
// Display the file name to the user.
if (SUCCEEDED(hr))
{
MessageBox(NULL, pszFilePath, L"File Path", MB_OK);
CoTaskMemFree(pszFilePath);
}
pItem->Release();
}
}
pFileOpen->Release();
}
CoUninitialize();
}
return 0;
}
所以,我检查了两个项目的属性页面,因为我原来的项目已经链接了GLFW和GLEW库,所以也许他们应该受到责备。一旦我删除它们并确保两个属性页面看起来相同(例如:它们包含相同的库),我原始项目中的错误就不会消失。
如果有人知道为什么会这样,任何帮助将不胜感激。
还要注意,这并不妨碍程序运行,我只是想摆脱它。
您是否在win32组的debug-> windows-> exception Settings下检查了0xc0000005异常?如果我确实已经检查过,我只会得到您描述的行为。特别是如果我查看调用堆栈,则异常在ValidateTreeItem中。如果您确实为0xC0000005启用了break on throw,我不知道有任何方法可以不获得该行为。