Title: Re: [msvc] CFile::Seek

Hello David,

Yes You can seek a location that is beyond EOF. MSDN says "Note that it is
not an error to set the file pointer to a position beyond the end of the
file. The size of the file does not increase until you call the
SetEndOfFile, WriteFile, or WriteFileEx function. A write operation
increases the size of the file to the file pointer position plus the size of
the buffer written, leaving the intervening bytes uninitialized."   I just
have written a small program which will move the file pointer little bit
away from it current write position. And i have called the function
SetEndOfFile(...) and observed the file. File size has been increased. I
will paste the code here.

HANDLE hFile;
 hFile = CreateFile("c:\\file.txt", GENERIC_READ|GENERIC_WRITE, NULL, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

CString str = "Hello World";

DWORD dwWrite;

DWORD dwFileSize;

BOOL ret = WriteFile(hFile, str, str.GetLength(), &dwWrite, NULL);

dwFileSize = GetFileSize(hFile, NULL);


DWORD dwPtr = SetFilePointer(hFile, dwFileSize+10, NULL, FILE_BEGIN);

if (dwPtr == 0xFFFFFFFF)

MessageBox("Failed");

SetEndOfFile(hFile);

CloseHandle(hFile);

Hope some of this will helps you.

Cheers
Sreeram.



----- Original Message -----
From: "David Stroupe" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, April 30, 2003 7:17 AM
Subject: Re: [msvc] CFile::Seek


> At 08:31 PM 4/29/2003, David Stroupe wrote:
> >If I have a file that I need to make bigger, can I seek to a location
that
> >is beyond the eof?  Theoretically, the next 'record' would be written to
> >the current location of the eof, making the file larger.
> >
> >TIA
>
> Some additional info on the error that I am getting...the system is in the
> field and I am relying on logged error messages.  The error during the
seek
> OR write is # 9 - The storage control block address is invalid.
>
> What could be causing this?
>
> Thanks
>
>
>
> Best regards,
> <mailto:[EMAIL PROTECTED]>David Stroupe
>
<http://www.keyed-upsoftware.com/>Keyed<http://www.keyed-upsoftware.com/>-Up
> Software
> 5307 Faireast Court
> Arlington, Texas 76018-1683
> 817/557-4903 voice
> 817/472-0408 fax
>
>

Reply via email to