I wanted to implement the Win32 function, GetDiskFreeSpaceEx().

This function takes 4 parameters:
$lpDirectoryName          which is a DWORD,
$lpFreeBytesAvailable     which is a PULARGE_INTEGER,
$lpTotalNumberOfBytes     which is a PULARGE_INTEGER and
$lpTotalNumberOfFreeBytes which is a PULARGE_INTEGER.

The MSDN documentation says this about PULARGE_INTEGER:
This union provides a 64-bit data type which is accessible as two DWORDs or
as
a single DWORDLONG.
The ULARGE_INTEGER structure is actually a union. If your compiler has
built-in support for 64-bit integers, use the QuadPart member to store the
64-bit integer. Otherwise, use the LowPart and HighPart members to store the
64-bit integer.

As I'm using the ActivePerl Build 613 from ActiveState I can't use 64-bit
integers.
So I tried to use two DWORDs
And I wrote this script:
############################################################################
##
#!/usr/bin/perl -w
use strict;
use Win32::API;

my $lpDirectoryName = 0; # Get info on current disk
if (@ARGV)
{
  $lpDirectoryName = $ARGV[0] if (-d $ARGV[0]);
}

my $success = _GetDiskFreeSpaceEx($lpDirectoryName,
                                  $lpFreeBytesAvailable,
                                  $lpTotalNumberOfBytes,
                                  $lpTotalNumberOfFreeBytes);
if (!$success)
{
  print "Error\n";
  exit;
}
my ($lpFreeBytesAvailable1, $lpFreeBytesAvailable2) = unpack("LL",
$lpFreeBytesAvailable);
my ($lpTotalNumberOfBytes1, $lpTotalNumberOfBytes2) = unpack("LL",
$lpFreeBytesAvailable);
my ($lpTotalNumberOfFreeBytes1, $lpTotalNumberOfFreeBytes2) = unpack("LL",
$lpFreeBytesAvailable);

print "\$lpFreeBytesAvailable1=$lpFreeBytesAvailable1\n";
print "\$lpFreeBytesAvailable2=$lpFreeBytesAvailable2\n";

print "\$lpTotalNumberOfBytes1=$lpTotalNumberOfBytes1\n";
print "\$lpTotalNumberOfBytes2=$lpTotalNumberOfBytes2\n";

print "\$lpTotalNumberOfFreeBytes1=$lpTotalNumberOfFreeBytes1\n";
print "\$lpTotalNumberOfFreeBytes2=$lpTotalNumberOfFreeBytes2\n";
exit;

sub _GetDiskFreeSpaceEx()
{
  my $dir = $_[0];
  my $func = new Win32::API("kernel32",
                            "GetDiskFreeSpaceEx",
                            ['P', 'P', 'P', 'P'],
                            'I');
  if (!defined($func))
  {
    return 0;
  }
  return $func->Call($dir, $_[1], $_[2], $_[3]);
}
############################################################################
##
The output looks like this:
$lpFreeBytesAvailable1=1832706048
$lpFreeBytesAvailable2=1
$lpTotalNumberOfBytes1=1832706048
$lpTotalNumberOfBytes2=1
$lpTotalNumberOfFreeBytes1=1832706048
$lpTotalNumberOfFreeBytes2=1
############################################################################
##
Manual check on this drive reveals this:
Used space : 3010576384 bytes
Free Space : 6127673344 bytes
Capacity   : 9138249728 bytes

And 6.127.673.344 - 1.832.706.048 = 4.294.967.296
which I'm told is the integer value of the bit string
11111111111111111111111111111111.

Now, I have two questions:
1. How can find this value (4.294.967.296)?
2. Why are all the lowpart numbers identical?
3. Why are all the highpart number identical?


---
You are currently subscribed to perl-win32-users as: [archive@jab.org]
To unsubscribe, forward this message to
         [EMAIL PROTECTED]
For non-automated Mailing List support, send email to  
         [EMAIL PROTECTED]

Reply via email to