Thread: Converting

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    7
    Rep Power
    0

    Converting


    Hi Guys and Gals,

    I hope someone can help me get out of this situation.

    Im converting a utility from console to win32, ,but im kinda stuck.

    The utility reads a file and then creates 2 report files, the console version uses argv[] to read the file address where as i have created the open dialog(windows deefault)

    The nest thing the console does is this:

    if ((file_fd = open(file_address,O_BINARY|O_RDONLY)) == -1)
    {
    printf("Open_files error opening file %s\n",file_address);
    return(-1);
    }

    this is when the file is opened, but the file_fd is an int.

    Ive tried Createfile instead of open, but that doesnt seem to work with the right parameters.

    Am i right in saying that this opens the file into memory allowing the rest of the program to access it and test for different things because this line is in a function called OpenTheFile.

    Ive trried lots of things and nothing seems to work, any ideas???
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,091
    Rep Power
    2222
    Instead of low-level I/O, try stream I/O. fopen(), fread(), fprintf(), fclose().

    Code:
    FILE *fp;
    CString s;
    
    if ((fp = fopen(file_address,"rb")) == NULL) 
    { 
        // assuming MFC
        s.Format("Open_files error opening file %s\n",file_address);
        // or whatever function is needed for the message box.
        AfxMessageBox(s); 
        return(-1); 
    }

IMN logo majestic logo threadwatch logo seochat tools logo