||SQL Server Tips by Gama and Naughter
The XP calls the function GetDiskFreeSpaceEx to obtain information
about the amount of space available on a disk volume.
GetDiskFreeSpaceEx has four parameters: the first one is the path
for a directory on the disk to be examined; this is a pointer to a
null-terminated string. The second is the total number of free bytes
on the disk and this is a pointer to an unsigned large integer (64
bits). The third is the total number of available bytes on the disk
and this is a pointer like the one for the second parameter.
Finally, the fourth is the total number of free bytes on the disk
and this is a pointer like the ones from parameters two and three.
XP_DISKSPACE will divide the number of free bytes on the disk by
1,048,576 (2 to the 20th power); this will result in a value
measured in megabytes.
The DLL exposes 1 XP using the following XP++ code:
This is the code for calling GetDiskFreeSpaceEx and calculating the
result in megabytes:
BOOL bSuccess = GetDiskFreeSpaceEx(pszDriveLetter,
&i64FreeBytesToCaller, &i64TotalBytes, &i64FreeBytes);
DBINT nSpaceLeft = (DBINT) (((__int64) i64FreeBytes.QuadPart) /
The above book excerpt is from:
Turbocharge Database Performance with C++ External Procedures
Joseph Gama, P. J. Naughter