Results 1 to 4 of 4

Thread: How to open a file using openfile() method...

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    27

    How to open a file using openfile() method...

    Hai...

    i'm triying to open a file in read mode using the following method..

    HFILE hFile;
    hFile=OpenFile("D:\ss.doc",lpReOpenBuff,OF_READ);

    i cant undestand what is the 2nd parameter is...

    the syntax for openfile is

    HFILE OpenFile(LPCSTR lpFileName,LPOFSTRUCT lpReOpenBuff,UINT uStyle);


    plzz tell me what shall i put for lpReOpenBuff..

    senthil.

  2. #2
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403

    Re: How to open a file using openfile() method...

    msdn says:

    lpReOpenBuff
    [out] A pointer to the OFSTRUCT structure that receives information about a file when it is first opened.

    The structure can be used in subsequent calls to the OpenFile function to see an open file.

    The OFSTRUCT structure contains a pathname string member with a length that is limited to OFS_MAXPATHNAME characters, which is currently 128 characters. Because of this, you cannot use the OpenFile function to open a file with a path length that exceeds 128 characters. The CreateFile function does not have a path length limitation.
    I suggest:

    Code:
    OFSTRUCT ofs;
    
    memset(&ofs, 0, sizeof(OFSTRUCT));
    
    OpenFile("D:\ss.doc",&ofs,OF_READ);
    when the call returns, the structure will be filled in with information about the file you chose to open. See the MSDN link for more information.
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    27

    Re: How to open a file using openfile() method...

    Hai sun,
    thanks for ur reply...

    ur help works supervly...

    Now i want to open two files, one in read mode and the another in write mode..

    and i want to read the contents of the read mode file and write it into the

    write mode file...

    i had tried the following method...

    Code:
    HANDLE hFile,hFile1;
    DWORD wmWritten; 
    HFILE op,op1;
    OFSTRUCT ofs;
    
    memset(&ofs, 0, sizeof(OFSTRUCT));
    op=OpenFile("C:\\tab.doc",&ofs,OF_READ);            
    hFile = CreateFile(_T("C:\\text.doc"),GENERIC_READ|GENERIC_WRITE,        FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); 
    op1=OpenFile("C:\\text.doc",&ofs,OF_WRITE);  
    
    while(op!=EOF)
    {
    ReadFile(op,lpBuffer,(DWORD)(strlen(lpBuffer)),&wmWritten,NULL);
    WriteFile(op1,lpBuffer,(DWORD)(strlen(lpBuffer)),&wmWritten,NULL);
    }
    Here i dont know the parameter lpBuffer...
    Shall i put the path or anything?

    Can u plzz explain me how to read the contents of one file and write into
    another file...

    is the above method enough for this process..
    thanks...
    senthil.

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: How to open a file using openfile() method...

    Don't use OpenFile. It's Win16 legacy. Only use CreateFile.

    lpBuffer is just a memory buffer. A char array, for example.

    But don't do all this at all. To copy a file, you use the CopyFile API. You don't implement it yourself.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

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