Why would fopen fail to open a file that exists?

≯℡__Kan透↙ 提交于 2019-12-04 06:01:43

The Answer:

I found the cause, too many open file handles cause by some recent updates to the application. These where not code changes though so this bug has been present for a while. I stepped into the fopen function down to a function called _getstream. This attempts to find a stream not in use, the function searches a table of 512 streams Sure enough all 512 where in use and other calls to fopen where failing. I used the handle tool from sysinternals to see the number of used handles.

Your function has an HRESULT return type (where 0 is good) but you return a boolean (where 0 is bad). That can't be right...

Assuming you have a reasonable version of VC6, then you have the source code to the CRT, and you can step into the fopen call, and all the way down to the CreateFile call that the CRT will make. (Be prepared for it to be quite a long way down!)

put breakpoint on fopen line, trigger it in debugger, input "ERR, hr" in "Watch" window, execute the line and check in Watch what was the problem. Most probably it's access permissions.

You are already having 512 opened files.

We can hold only max 512 opened files in VC application. I am suggesting to close the unnecessary files using fclose.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!