问题
The following code throws a 110 Error on the EndUpdateResource call only when windows explorer is open at D:\test\output\ where the executable is being copied to:
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);
As long as I don't have that folder open in windows explorer it works fine. If I have it open it will throw an error. Also, if I do a CreateFile with read and write access before the BeginUpdateResource call it will work fine even if I have the output folder open. I am really confused and would appreciate any help. Thanks!
回答1:
I disabled the on demand virus scanner on the machine and the code no longer throws an error.
回答2:
It's all about directory's permissions for the files you're writing. At least it was for me. I was writing files on desktop, which had Read only
attribute and was getting this error randomly. I solved it by simply creating a folder on desktop and writing files to it. So, the solutions:
1) Don't write files to system's directories.
2) Create a directory yourself
3) Edit directory's attributes. Take off read-only. To do it programmatically:
How to Remove the Readonly attribute of a File MFC
removing readonly from folder, its sub folders and all the files in it
Or combine all of them.
来源:https://stackoverflow.com/questions/32727996/endupdateresource-throws-error-110-the-system-cannot-open-the-device-or-file-s