Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
GetDiskFreeSpaceEx() in WIN32API
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00315812
Message ID:
00315927
Views:
40
>Is there a VFP solution to use GetDiskFreeSpaceEx()? I'm trying to get the FULL/USED/FREE size of the hard drive programatically. In the UT file section I found a wrapper for using GetDiskFreeSpace(), but it will not return the correct sizes for very large HDs.

It's not trivial to do, since the return values are PU_LARGE, an 8 byte integer that's larger than the native VFP INTEGER type. One way to handle this is to use my CLSHEAP class to manage the memory and then convert the results on return:
SET PROCEDURE TO MEMMGR ADDITIVE
oHeap = CREATEOBJ('Heap')
LOCAL n3PU_LARGE_Values, cBuffer
n3PULARGE_Values = oHeap.AllocInitAs(24,CHR(0))
DECLARE INTEGER GetDiskFreeSpaceEx IN Win32API ;
  STRING @ lpDirectoryName, ;
  INTEGER lpFreeBytesAvailable, ;
  INTEGER lpTotalNumberOfBytes, ;
  INTEGER lpTotalNumberOfFreeBytes
IF GetDiskFreeSpaceEx('C:\', ;
                      n3PULARGE_Values,;
                      n3PULARGE_Values+8, ;
                      n3PULARGE_Values+16) # 0
   cBuffer = oHeap.CopyFrom(n3PULARGE_Values)
   ? 'Free bytes', ConvertULARGE(SUBST(cBuffer,1,8))
   ? 'Tot. bytes', ConvertULARGE(SUBST(cBuffer,9,8))
   ? 'Free bytes', ConvertULARGE(SUBST(cBuffer,17,8))
ENDIF
oHeap.DeAlloc(n3PULARGE_Values)
oHeap = ''

FUNCTION ConvertULARGE
LPARAMETER tcULARGE
LOCAL nCtr, nValue
nValue = 0
FOR nCtr = 8 TO 1 STEP -1
   nValue = (nValue * 256) + ASC(SUBST(tcULARGE,nCtr,1))
ENDFOR
RETURN nValue
Note - I allocate a block of memory large enough to hold the 3 values, and pass pointers to the sections of the memory block rather than passing strings. Each ULARGE is 8 bytes in length. The conversion is rather brute force, but it works; numbers are stored with the Least Significant Byte first. Be aware that rouding errors may occur, since VFP is forced to work with this as a floating point number.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform