fopen,fopen_ S, wfopen_ S and_ fsopen, _ The distinction of WFS open

In the process of C++ project, a function of opening and saving files needs to be implemented. After I write to the file tmp.dat, I want to write to the file for the second time. At this time, an error returning int error = 13 (Permission denied) occurs in both fopen_s and _wfopen_s.
Since the project is Unicode encoded, there is no way to use Fopen for file operations (fopen is available and Shared reads and writes are available as long as _CRT_SECURE_NO_WARNINGS is added to the precompile, which I don’t want to do). So all kinds of search, and look up MSDN. Here’s what it says on MSDN:
Files opened by fopen_s and _wfopen_s are not sharable. If you require that a file be sharable, use _fsopen, _wfsopen with the appropriate sharing mode constant (for example, _SH_DENYNO for read/write sharing).
Link: (v = versus 90). Aspx
That is, fopen_s and _Wfopen_s do not support file sharing. When you use fopen_s or _wfopen_s for read or write operations, you can only do one operation (i.e., you can only do one read or write operation). Note: If you use fopen_s or _wfopen_s once for a file in a different place, the file becomes unshared. If you read or write a file again, you may return an int error = 13 (EACCES (Permission denied). I just changed one place in the project, but it still doesn’t work the second time. I need to change all the places that involve reading and writing to _fsopen, _wfsopen.
FILE * FP = _wfsopen(tmpFile, _T(” WB “), _SH_DENYNO);

Read More: