-
share file
Hi
I want to open file, but if this file is opened by other user, I'll open in read opnly
This is my code, but doens't work ..
HANDLE hdl ;
hdl = CreateFile ( FileName, GENERIC_READ | GENERIC_WRITE , FILE_SHARE_READ ,
NULL,OPEN_EXISTING ,FILE_ATTRIBUTE_NORMAL , NULL );
if ( hdl == INVALID_HANDLE_VALUE )
hdl = CreateFile ( FileName, GENERIC_READ ,0,NULL,OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL , NULL );
Thanks for Help
-
Re: share file
Your second CreateFile call is using a dwShareMode of 0 instead of FILE_SHARE_READ. If dwShareMode is 0, the file cannot be shared, so the call will always fail.
Bear in mind also that the other user may not have opened the file in shared mode.
Dave