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.
Re: How to open a file using openfile() method...
msdn says:
Quote:
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.
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.
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.