Can CreateFile() Open one file at the same time in two different thread
void new_function(void * what)
{
HANDLE h = CreateFile("c:\\tmp", GENERIC_ALL,FILE_SHARE_WRITE |
FILE_SHARE_READ , NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (h == INVALID_HANDLE_VALUE)
{
DWORD d = GetLastError();
return ;
}
Sleep(10000);
}
int main()
{
HANDLE h = CreateFile("c:\\tmp", GENERIC_ALL,FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
Sleep(10000);
return 1;
}
every time it exits at the GetLastError
position. and the error is ERROR_SHARING_VIOLATION
(32, "The
process cannot access the file because it is being used by another
process.")
if i canot share open the file, then what is the use of the FILE_SHARE_WRITE | FILE_SHARE_READ
thanx
The program environment is Win32 Vs2003