Kacem
April 1st, 1999, 08:41 AM
Hi
I try to explain what I want to do
- Two application try to open a files (A,B)
If the first open in Read/write, the second is open it just in read.
This is my code, is work
if A open the file, B open it (ReadOnly) with a message (file is opened) GOD.
BUT if A open the file, B open it (ReadOnly), A close it and try the open again (the file is opened but in read/write),
HANDLE ProtFolioHnd = CreateFile ( FileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ ,NULL, OPEN_EXISTING ,
FILE_ATTRIBUTE_NORMAL , NULL );
if ( ProtFolioHnd == INVALID_HANDLE_VALUE ){
char Buffer[80];
ProtFolioHnd = CreateFile ( FileName, GENERIC_READ , FILE_SHARE_READ,
NULL, OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , NULL );
if( ProtFolioHnd!=INVALID_HANDLE_VALUE ){
//ReadOnly
_snprintf(Buffer,80,"%s : Is read-only.",FileName);
}
else{ // File is open by other application
_snprintf(Buffer,80,"%s : Is being used by another user.",FileName);
ProtFolioHnd = CreateFile ( FileName, GENERIC_READ ,
FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING
,FILE_ATTRIBUTE_READONLY , NULL );
}
MessageBox ( GetActiveWindow(), Buffer,"Estimates Direct", MB_OK);
}
Thanks
I try to explain what I want to do
- Two application try to open a files (A,B)
If the first open in Read/write, the second is open it just in read.
This is my code, is work
if A open the file, B open it (ReadOnly) with a message (file is opened) GOD.
BUT if A open the file, B open it (ReadOnly), A close it and try the open again (the file is opened but in read/write),
HANDLE ProtFolioHnd = CreateFile ( FileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ ,NULL, OPEN_EXISTING ,
FILE_ATTRIBUTE_NORMAL , NULL );
if ( ProtFolioHnd == INVALID_HANDLE_VALUE ){
char Buffer[80];
ProtFolioHnd = CreateFile ( FileName, GENERIC_READ , FILE_SHARE_READ,
NULL, OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , NULL );
if( ProtFolioHnd!=INVALID_HANDLE_VALUE ){
//ReadOnly
_snprintf(Buffer,80,"%s : Is read-only.",FileName);
}
else{ // File is open by other application
_snprintf(Buffer,80,"%s : Is being used by another user.",FileName);
ProtFolioHnd = CreateFile ( FileName, GENERIC_READ ,
FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING
,FILE_ATTRIBUTE_READONLY , NULL );
}
MessageBox ( GetActiveWindow(), Buffer,"Estimates Direct", MB_OK);
}
Thanks