Results 1 to 3 of 3

Thread: Open File for Reading while Writing

  1. #1

    Thread Starter
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032

    Open File for Reading while Writing

    My app opens a log file for writing on startup. It closes it (CloseHandle API) when the app exits. It writes lines to the log file as the program runs.

    What I would like to do is open another handle to this file for just reading during the course of the program, to just display its contents to the screen. Is there a combination of flags for the openings (CreateFile) that will allow me to do this? Right now opening for reading fails.

    Thanks.

    VB Code:
    1. 'open for writing
    2. hFile = CreateFile(FixDir(App.Path) & LOGFILE, GENERIC_WRITE, FILE_SHARE_READ, _
    3.         ByVal 0&, CREATE_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, 0)
    4.  
    5. 'open for reading
    6. hRead = CreateFile(FixDir(App.Path) & LOGFILE, GENERIC_READ, FILE_SHARE_READ, _
    7.         ByVal 0&, OPEN_EXISTING, 0, 0)
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Why not open the log file and write its contents to a Locked Text box?

  3. #3

    Thread Starter
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    That's not the problem. Trying to open the file for reading fails when I already have the file open for writing the way I'm doing it now.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

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