Click to See Complete Forum and Search --> : share file


Kacem
March 30th, 1999, 03:05 AM
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

Dave Lorde
March 30th, 1999, 05:44 AM
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