EndUpdateResource() throws Error 110 在输出位置打开windowsexplorer时系统无法打开指定的设备或文件

EndUpdateResource() throws Error 110 The system cannot open the device or file specified when windowsexplorer is open at the output location

仅当 windows 资源管理器在 D:\test\output\ 中打开时,以下代码才会在 EndUpdateResource 调用上引发 110 错误,其中可执行文件被复制到:

std::ifstream in("C:\Windows\notepad.exe", std::ios::binary);
std::ofstream out("D:\test\output\notepad.exe", std::ios::binary);
out << in.rdbuf();
in.close();
out.close();

Handle hUpdateRes = BeginUpdateResource(_T("D:\test\output\notepad.exe"), FALSE);
EndUpdateResource(hUpdateRes, FALSE);

只要我没有在 windows 资源管理器中打开该文件夹,它就可以正常工作。如果我打开它,它会抛出一个错误。此外,如果我在调用 BeginUpdateResource 之前执行具有读写访问权限的 CreateFile,即使我打开了输出文件夹,它也能正常工作。我真的很困惑,希望得到任何帮助。谢谢!

我在机器上禁用了按需病毒扫描程序,代码不再抛出错误。

这都是关于您正在编写的文件的目录权限。至少对我来说是这样。我在桌面上写文件,它有 Read only 属性并且随机出现这个错误。我通过简单地在桌面上创建一个文件夹并将文件写入其中来解决它。所以,解决方案:
1) 不要将文件写入系统目录。
2) 自己创建一个目录
3) 编辑目录的属性。脱掉只读。要以编程方式执行此操作:
How to Remove the Readonly attribute of a File MFC
removing readonly from folder, its sub folders and all the files in it

或者全部合并。