realbasic-nug
[Top] [All Lists]

Re: File size bigger than integer

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: File size bigger than integer
From: "Steve Garman" <realbasic at garman dot demon dot co dot uk>
Date: Thu, 30 Jun 2005 22:50:18 +0100
Delivered-to: realbasic-nug at lists dot realsoftware dot com
In a message regarding Re: File size bigger than integer dated Wed, 29 Jun
2005 17:10:28 -0400, ChrisH said that ...

> I'm having some trouble getting it to work. Can you tell me what I'm 
> doing wrong?

Having taken so long to get back to you, and as there were some sensible
alternatives offered, you've probably lost interest in GetFileSize.

But just in case it helps, this seems to work:

  Const GENERIC_WRITE = &H40000000
  Const OPEN_EXISTING = 3
  Const FILE_SHARE_READ = &H1
  Const FILE_SHARE_WRITE = &H2
  Const FO_DELETE = &H3
  Declare Function GetFileSize Lib "kernel32" _
  ( hFile As Integer, ByRef lpFileSizeHigh As Integer ) As Integer
  
  Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" _
  ( lpFileName As CString, dwDesiredAccess As Integer,  _
  dwShareMode As Integer, lpSecurityAttributes As Integer, _
  dwCreationDisposition As Integer, dwFlagsAndAttributes As Integer, _
  hTemplateFile As Integer ) As Integer
  
  Declare Function CloseHandle Lib "kernel32" ( hObject As Integer ) _
  As Integer
  
  Dim hndl ,lowSize,hiSize as integer
  Dim reslt, bigNum as Double
  bigNum = 4294967296.0
  
  hndl = CreateFile("C:\sjgtest.xls", GENERIC_WRITE, FILE_SHARE_READ,  _
  0, OPEN_EXISTING, 0, 0)
  lowSize = GetFileSize(hndl, hiSize)
  Call CloseHandle(hndl)
  
  reslt = lowSize
  If reslt < 0 Then
    reslt = reslt + bigNum
  End If
 
  If hiSize > 0 Then
    bigNum = bigNum * hiSize
    reslt = reslt + bigNum
  End If
  MsgBox Format(reslt,"#")

By the way, I use GetFileSize instead of GetFileSizeEx, because the latter
only works on Win 2000, XP and later.

-- 
Steve Garman
Using REALbasic 2005.01 Professional on Windows XP Pro


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>