HANDLE hFile, // handle of file to get size of
LPDWORD lpFileSizeHigh // address of high-order word for file size
);
Parameters
hFile
Specifies an open handle of the file whose size is being returned. The handle must have been created with either GENERIC_READ or GENERIC_WRITE access to the file.
lpFileSizeHigh
Points to the variable where the high-order word of the file size is returned. This parameter can be NULL if the application does not require the high-order word.
Return Values
If the function succeeds, the return value is the low-order doubleword of the file size, and, if lpFileSizeHigh is non-NULL, the function puts the high-order doubleword of the file size into the variable pointed to by that parameter.
If the function fails and lpFileSizeHigh is NULL, the return value is 0xFFFFFFFF. To get extended error information, call GetLastError.
If the function fails and lpFileSizeHigh is non-NULL, the return value is 0xFFFFFFFF and GetLastError will return a value other than NO_ERROR.
Remarks
You cannot use the GetFileSize function with a handle of a nonseeking device such as a pipe or a communications device. To determine the file type for hFile, use the GetFileType function.
The GetFileSize function obtains the uncompressed size of a file. Use the GetCompressedFileSize function to obtain the compressed size of a file.
Note that if the return value is 0xFFFFFFFF and lpFileSizeHigh is non-NULL, an application must call GetLastError to determine whether the function has succeeded or failed. The following sample code illustrates this point:
//
// Case One: calling the function with
// lpFileSizeHigh == NULL
kernel32的文件处理API函数
声明:Declare Function GetFileSize Lib "kernel32" Alias "GetFileSize" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
参数说明:
Long,返回文件长度。& HFFFFFFFF表示出错。注意如lpFileSizeHigh不为NULL,且结果为& HFFFFFFFF,那么必须调用GetLastError,判断是否实际发生了一个错误,因为这是一个有效的结果hFile ---------- Long,文件的句柄lpFileSizeHigh - Long,指定一个长整数,用于装载一个64位文件长度的头32位。如这个长度没有超过2^32字节,则该参数可以设为NULL(变成ByVal)