Parameters to CreateFile

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?SGVyemwgUmVnZXY=?=

    Parameters to CreateFile

    What arguments do I need to give CreateFile? I want to open a file or folder
    for reading, even if it is already opened from another place. I'm trying:
    CreateFile (argv[1], GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRIT E, NULL,
    OPEN_EXISTING, FILE_ATTRIBUTE_ NORMAL, NULL)
    but this fails to open folders ("Access is Denied") or files that are
    already used (as far as I understand).
  • David Lowndes

    #2
    Re: Parameters to CreateFile

    >What arguments do I need to give CreateFile? I want to open a file or folder
    >for reading, even if it is already opened from another place.
    You can only do that if the "other place" has also allowed sharing.

    I have a simple test application for the CreateFile API that I use for
    checking such scenarios:


    Dave

    Comment

    • =?Utf-8?B?SGVyemwgUmVnZXY=?=

      #3
      Re: Parameters to CreateFile

      Thanks. The test opens successfully the file that is supposed to be used
      already, and fails to open any directory that I try it on claiming 5: "Access
      is denied". What does that mean?

      "David Lowndes" wrote:
      I have a simple test application for the CreateFile API that I use for
      checking such scenarios:

      >
      Dave

      Comment

      • David Lowndes

        #4
        Re: Parameters to CreateFile

        >Thanks. The test opens successfully the file that is supposed to be used
        >already, and fails to open any directory that I try it on claiming 5: "Access
        >is denied". What does that mean?
        You have to specify FILE_FLAG_BACKU P_SEMANTICS to open a directory,
        the test doesn't do that.

        Dave

        Comment

        • =?Utf-8?B?SGVyemwgUmVnZXY=?=

          #5
          Re: Parameters to CreateFile

          Indeed. It goes in the parameter before last in CreateFile.
          (However, the "used" file is still opened by the test but not by my function
          call.)

          "David Lowndes" wrote:
          You have to specify FILE_FLAG_BACKU P_SEMANTICS to open a directory,
          the test doesn't do that.
          >
          Dave

          Comment

          • David Lowndes

            #6
            Re: Parameters to CreateFile

            >Indeed. It goes in the parameter before last in CreateFile.
            >(However, the "used" file is still opened by the test but not by my function
            >call.)
            I don't understand what you're telling me there.

            My test program doesn't use the FILE_FLAG_BACKU P_SEMANTICS option, so
            it's not useful for testing opening directories.

            Dave

            Comment

            • =?Utf-8?B?SGVyemwgUmVnZXY=?=

              #7
              Re: Parameters to CreateFile

              I have a file that the test opens successfully, but my CreateFile syscall
              fails on it claiming that it's opened by another process. The other process
              is Visual Studio and the file is <project>.ncb .

              "David Lowndes" wrote:
              I don't understand what you're telling me there.

              Comment

              • David Lowndes

                #8
                Re: Parameters to CreateFile

                >I have a file that the test opens successfully, but my CreateFile syscall
                >fails on it claiming that it's opened by another process.
                So what options are you using differently?
                >The other process is Visual Studio and the file is <project>.ncb .
                What are you trying to do?

                I would expect VS to open the NCB file exclusively - it's not the sort
                of thing that it'd want to be opened by another process.

                Dave

                Comment

                • =?Utf-8?B?SGVyemwgUmVnZXY=?=

                  #9
                  Re: Parameters to CreateFile



                  "David Lowndes" wrote:
                  I have a file that the test opens successfully, but my CreateFile syscall
                  fails on it claiming that it's opened by another process.
                  >
                  So what options are you using differently?
                  None. The same call, except that I added FILE_FLAG_BACKU P_SEMANTICS .
                  The other process is Visual Studio and the file is <project>.ncb .
                  >
                  What are you trying to do?
                  Check the size of the file
                  I would expect VS to open the NCB file exclusively - it's not the sort
                  of thing that it'd want to be opened by another process.
                  So I guess that this solves the problem: What I'm trying to do can't be done
                  with opening the file. I found that it can probably be done with
                  GetFileAttribut esEx - see
                  http://blog.kowalczyk.info/kb/get-fi...r-windows.html .

                  Comment

                  • David Lowndes

                    #10
                    Re: Parameters to CreateFile

                    >The other process is Visual Studio and the file is <project>.ncb .
                    >>
                    >What are you trying to do?
                    >Check the size of the file
                    No need to open it then, just use FindFirstFile, FindClose.

                    Dave

                    Comment

                    Working...