Thread: need help on OpenFile()

  1. #1

    need help on OpenFile()

    can anyone help give an example of this function for opening a file for reading access?

    I am new to this and want to avoid using fstream.h

  2. #2
    train spotter
    Join Date
    Aug 2001
    near a computer
    OpenFile() has been superseded by CreateFile()
    This will return the HANDLE to a file given the path, including the name of the file. It will display a message box if it fails (with the error code).
    HANDLE	OpenDocument(HWND hDlg, char *sFilePath)
    	char				sBuffer[STRING];
    	int					iError=INVALID;
    	HANDLE				hFile;
    	if((hFile == NULL)||(hFile == INVALID_HANDLE_VALUE))
    		sprintf(sBuffer,"%s file failed to open with Error #:%d",sFilePath,iError);
    		return NULL;
    		return hFile;
    Look up the flags I have used as I want the file to be created if it does not exist and may want to write to it.
    Use Readfile() and SetFilePointer() to read data from the file.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 02:29 PM
  2. openfile error
    By lambs4 in forum Windows Programming
    Replies: 4
    Last Post: 11-06-2002, 09:00 PM
  3. BC++5 can not open OpenFile dialog
    By Unregistered in forum Windows Programming
    Replies: 2
    Last Post: 05-22-2002, 11:27 AM
  4. OpenFile API
    By Steve-O in forum Windows Programming
    Replies: 1
    Last Post: 04-18-2002, 04:12 PM
  5. OpenFile Dialog Box
    By Terrell in forum Windows Programming
    Replies: 5
    Last Post: 09-30-2001, 01:52 PM