CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: share file

  1. #1
    Join Date
    Apr 1999
    Posts
    13

    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

  2. #2
    Join Date
    Apr 1999
    Posts
    383

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured