You said that you are using the
windows.h
header; I suppose that you mean that you are using the
Win32 API, without
MFC,
ATL nor other frameworks. Isn't it?
The
Win32 way to open a file is to use the
CreateFile Function (Windows)[
^]; the third parameter of that function is
dwShareMode
, which tells
Windows if you want to get an exclusive access to the file or not. If you specified zero for that parameter you have denied others to do anything on the file. To give others the ability to open the file for reading you should use
FILE_SHARE_READ
.
See the code snippet below:
HANDLE hFile = CreateFile(
_T("myfile.txt"), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);