Thread: Creating File Handles

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    220

    Creating File Handles

    This seems to me, to be the most basic question I've ever encountered, and YET I have been having trouble searching BOTH msdn and google to find it..what a bother, and even a search on cboard didn't show what I wanted...couldn't believe it, figured it might be my search terms, but I'm on a limited time frame and don't want to go through that. My brother has to get on the comp, so I have to ask it and get results quickly. I'm sure all three of these sources have information, I just don't have the time to build up search terms for them.

    My question is, how do I create a file handle?

    My usage is, to have my application run, and modify the applications creation/access/last write times using
    Code:
    SetFileTime(
      HANDLE hFile,
      const FILETIME* lpCreationTime,
      const FILETIME* lpLastAccessTime,
      const FILETIME* lpLastWriteTime
    );
    But, obviously, I need a handle to the application for this to work. I have every other argument i need, it's just the first one that's crucial to the success of this project.

    I don't want an alternative mind you, I really want to stick to winapi functions, infact there's no other implementation that I would accept since I'm learning about winapi at this point in time.
    Last edited by Tronic; 12-30-2004 at 06:53 PM.
    OS: Windows XP Pro CE
    IDE: VS .NET 2002
    Preferred Language: C++.

  2. #2
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    Well you could use createfile

    Code:
    HANDLE CreateFile(
      LPCTSTR lpFileName,                         // file name
      DWORD dwDesiredAccess,                      // access mode
      DWORD dwShareMode,                          // share mode
      LPSECURITY_ATTRIBUTES lpSecurityAttributes, // SD
      DWORD dwCreationDisposition,                // how to create
      DWORD dwFlagsAndAttributes,                 // file attributes
      HANDLE hTemplateFile                        // handle to template file
    );
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    220
    I can't use CreateFile, since the exe that I want to change the attributes of, IS the exe that's running. and I don't want to create a copy of the application I'm running.

    Now, that is assuming that I can modify the time attributes while It's running. If it doesn't let me do that, I still want to modify the time attributes of another exe without having to create the file or copy a file. That's just a bother if you ask me.
    Last edited by Tronic; 12-30-2004 at 07:06 PM.
    OS: Windows XP Pro CE
    IDE: VS .NET 2002
    Preferred Language: C++.

  4. #4
    Registered User
    Join Date
    Dec 2004
    Posts
    95
    CreateFile doesn't copy a file. It opens an existing file, or a new file - read it up in MSDN. It's a very versatile function, possibly a little OTT

  5. #5
    Registered User
    Join Date
    Mar 2004
    Posts
    220
    Thank you, I'll check that out Didn't know about the opening.
    OS: Windows XP Pro CE
    IDE: VS .NET 2002
    Preferred Language: C++.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with Creating File for File Processing
    By Dampecram in forum C Programming
    Replies: 2
    Last Post: 12-07-2008, 01:26 AM
  2. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  3. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  5. Replies: 3
    Last Post: 03-04-2005, 02:46 PM