# Re: GetFileSize() API

Posted by Honey on August 17, 1998 at 21:56:02:

In Reply to: Re: GetFileSize() API posted by Midco on August 17, 1998 at 17:07:31:

: 请问 getfilesize() API 要如何用呢？

: Declare Function GetFileSize Lib "kernel32" Alias "GetFileSize" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long

: 我没有用过 API，如何 pass parameter 到 GetFIleSize() 中呢？

: Thanks

通常事先要先用CreateFile 取得档案代码
才能用GetFileSize 取得档案大小

'模组宣告方式通常如下 _
如在其他地方宣告得作修改

Declare Function CreateFile Lib _
"kernel32" Alias "CreateFileA" _
(ByVal lpFileName As String, _
ByVal dwDesiredAccess As Long, _
ByVal dwShareMode As Long, _
ByVal lpSecurityAttributes _
As Long, ByVal _
dwCreationDisposition As Long, _
ByVal dwFlagsAndAttributes _
As Long, ByVal hTemplateFile _
As Long) As Long

Declare Function CloseHandle Lib _
"kernel32" (ByVal hObject As Long) As Long

Declare Function GetFileSize Lib _
"kernel32" (ByVal hFile As Long, _
lpFileSizeHigh As Long) As Long

Public Const GENERIC_READ = &H80000000
Public Const GENERIC_WRITE = &H40000000

Public Const FILE_SHARE_READ = &H1
Public Const FILE_SHARE_WRITE = &H2

Public Const OPEN_ALWAYS = 4

Public Const FILE_ATTRIBUTE_NORMAL = &H80

Public Const PAGE_READWRITE = 4

Public Const SECTION_MAP_WRITE = &H2
Public Const FILE_FLAG_SEQUENTIAL_SCAN = &H8000000

'宣告后 只要加入以下程式 就能取得档案大小
dim StrfileName as string
dim hFile as long
dim DblSize as double
dim Result as long
StrfileName="c:\dot.wav"'设定所要开启的档案

hFile = CreateFile(StrfileName, _
GENERIC_READ Or GENERIC_WRITE, _
FILE_SHARE_READ Or FILE_SHARE_WRITE, _
0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, _
0)'取得档案代码
DblSize = GetFileSize(hFile, 0)
'DblSize 就是档案大小

Result = CloseHandle(hFile) '关闭档案代码

Follow Ups:

- Re: GetFileSize() API 多谢你！ (无内容) Midco 23:54:38 8/17/98 (0)