4

So basically, I'm trying to read a log file from a game while that game is running in order to have my program react to it in dynamic ways. I know it's possible, as other programs such as Notepad(++) are able to do it. However, after searching for an answer, most of what I can come up with is only Linux related.

I have no idea as to how to go about this, help in doing so with either C++ or C# would be great. Even though I would prefer native C++ over C#.

  • 1
    I think you need to use something like this: FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, System.IO.FileShare.ReadWrite). Note the FileShare mode. – alfoks Nov 06 '12 at 11:31
  • As is http://stackoverflow.com/questions/3560651/whats-the-least-invasive-way-to-read-a-locked-file-in-c-sharp-perhaps-in-unsaf – Alex K. Nov 06 '12 at 11:35
  • @alfoks After looking up the FileShare mode, that actually seems to be exactly what I need, as well as it bringing up a truckload of results for it being the resolution to my very problem; where the usual terms are so vague it's hard to find a context-specific answer. Thanks! – Samo FiveOTwo Nov 06 '12 at 11:39

1 Answers1

1

The "native" winapi solution is CreateFile, and in particular its dwShareMode parameter.

MSalters
  • 173,980
  • 10
  • 155
  • 350