Is any Win32 API to set size of disk file directly?

30/01/2004 - 05:44 por Frank | Informe spam
For some reason, I need to set size of file randomly directly. But after
searched msdn, I have not found any api or information about that. So, would
any one tell me Is any Win32 API to set size of disk file directly or, not,
how to do that with other methods.

Thanx :-)

Frank F.Han

+--+
| winsays@:-)hotmail:-).com |
+--+
 

Leer las respuestas

#1 Martin Horst
30/01/2004 - 08:15 | Informe spam
Hi,

"Frank" schrieb im Newsbeitrag
news:
For some reason, I need to set size of file randomly directly. But after
searched msdn, I have not found any api or information about that. So,


would
any one tell me Is any Win32 API to set size of disk file directly or,


not,
how to do that with other methods.

Thanx :-)




maybe this function will help you.

BOOL SetFileLength(HANDLE hFile, INT64 i64FileLength)
{
DWORD dwResult;
LONG lLow, lHigh;
BOOL bFailed;

SetLastError(0);
if ( i64FileLength < 0 )
return FALSE;

ASSERT(hFile != NULL);
ASSERT(hFile != INVALID_HANDLE_VALUE);
if ( hFile == NULL || hFile == INVALID_HANDLE_VALUE )
return FALSE;

lLow = LONG(i64FileLength & 0xFFFFFFFF);
lHigh = LONG((i64FileLength >> 32) & 0xFFFFFFFF);
dwResult = SetFilePointer(hFile, lLow, &lHigh, FILE_BEGIN);
bFailed = (dwResult == INVALID_SET_FILE_POINTER && GetLastError() != 0);

if ( !bFailed )
bFailed = !::SetEndOfFile(hFile);

ASSERT(!bFailed);
return !bFailed;
}


Best regards
Martin Horst

Preguntas similares