Re: Create a file larger than 3 gb
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