All,

I am having an issue create a file larger than 3 GB. I am using CreateFile
and WriteFile. Any ideas how to create one past 3 GB? Here is what I am
doing. Thanks in advance...

BOOL bWrite = TRUE;
HANDLE hFile = CreateFile("c:\\test.dat", GENERIC_WRITE,
FILE_SHARE_WRITE, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, 0);

while(bWrite == TRUE)
{
memset(szData, 0, sizeof(szData));

WriteFile(hFile, szData, sizeof(szData), &dwBytesWrite, NULL);

Sleep(.5);

dwSize = GetFileSize(hFile, NULL);

if(dwSize >= (1024 * 1024 * 1024 * 5))
{
bWrite = FALSE;
}
}
CloseHandle(hFile);

Re: Create a file larger than 3 gb by Alexander

Alexander
Tue Jul 15 22:49:53 CDT 2008

Use 64 bit integers for file size.

1024 * 1024 * 1024 * 5 gets truncated to 1 GB. Use 1024ULL*1024*1024*5

"CodeTestDummy" <sharp_mind.TAKETHISOUT@email.TAKETHISOUT.msn.comm> wrote in
message news:ejSNN7u5IHA.4468@TK2MSFTNGP02.phx.gbl...
> All,
>
> I am having an issue create a file larger than 3 GB. I am using
> CreateFile and WriteFile. Any ideas how to create one past 3 GB? Here is
> what I am doing. Thanks in advance...
>
> BOOL bWrite = TRUE;
> HANDLE hFile = CreateFile("c:\\test.dat", GENERIC_WRITE,
> FILE_SHARE_WRITE, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, 0);
>
> while(bWrite == TRUE)
> {
> memset(szData, 0, sizeof(szData));
>
> WriteFile(hFile, szData, sizeof(szData), &dwBytesWrite, NULL);
>
> Sleep(.5);
>
> dwSize = GetFileSize(hFile, NULL);
>
> if(dwSize >= (1024 * 1024 * 1024 * 5))
> {
> bWrite = FALSE;
> }
> }
> CloseHandle(hFile);



Re: Create a file larger than 3 gb by Norbert

Norbert
Wed Jul 16 00:46:37 CDT 2008



CodeTestDummy schrieb:

> I am having an issue create a file larger than 3 GB. I am using
> CreateFile and WriteFile. Any ideas how to create one past 3 GB? Here
> is what I am doing. Thanks in advance...
>
> BOOL bWrite = TRUE;
> HANDLE hFile = CreateFile("c:\\test.dat", GENERIC_WRITE,
> FILE_SHARE_WRITE, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, 0);
>
> while(bWrite == TRUE)
> {
> memset(szData, 0, sizeof(szData));
>
> WriteFile(hFile, szData, sizeof(szData), &dwBytesWrite, NULL);
>
> Sleep(.5);
*****
Any reason to sleep here? Once WriteFile returns, the file size has already
changed, no need to sleep.
In addition, Sleep takes an unsigned integer as argument, not a floating point
value. A Sleep(.5) is the same as Sleep(0).
******

>
> dwSize = GetFileSize(hFile, NULL);
******
Alle the "standard" file api only uses a DWORD for file size. For files of your
size use the "Ex" functions like GetFileSizeEx, GetFileAttributesEx etc.
******
>
> if(dwSize >= (1024 * 1024 * 1024 * 5))
****
As already said, the interger expressen overflows, so you need to compare to a
64 bit integer.
****
> {
> bWrite = FALSE;
> }
> }
> CloseHandle(hFile);

Norbert

Re: Create a file larger than 3 gb by Igor

Igor
Wed Jul 16 06:59:07 CDT 2008

"Norbert Unterberg" <nunterberg@newsgroups.nospam> wrote in message
news:O3J8Sdw5IHA.1428@TK2MSFTNGP06.phx.gbl
>> dwSize = GetFileSize(hFile, NULL);
> ******
> Alle the "standard" file api only uses a DWORD for file size.

Not true. Note the second parameter to GetFileSize, where the OP passes
NULL. You can pass an address of a DWORD variable here, and the function
will store the upper half of the 64-bit file size in it.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925



Re: Create a file larger than 3 gb by Norbert

Norbert
Wed Jul 16 14:25:01 CDT 2008


Igor Tandetnik schrieb:
> "Norbert Unterberg" <nunterberg@newsgroups.nospam> wrote in message
> news:O3J8Sdw5IHA.1428@TK2MSFTNGP06.phx.gbl
>>> dwSize = GetFileSize(hFile, NULL);
>> ******
>> Alle the "standard" file api only uses a DWORD for file size.
>
> Not true. Note the second parameter to GetFileSize, where the OP passes
> NULL. You can pass an address of a DWORD variable here, and the function
> will store the upper half of the 64-bit file size in it.

Ups you are right. However, the OP did not use the upper 32 bit, so code to
check for 5 Gig will fail anyway, regardless if he converts the comparison
operands to a large integer or not.

Norbert