I am trying to understand the use of P/Invoke so that I can use the Window's APIs when I must. As an example, I am trying to get the free space on C: using GetDiskFreeSpaceEx from Kernel32.dll. Here is what I do:
$free = [IntPtr]::Zero
$total = [IntPtr]::Zero
$totalfree = [IntPtr]::Zero
Invoke-Win32 "kernel32.dll" ([System.Boolean]) "GetDiskFreeSpaceEx" ([string], [Ref], [Ref], [Ref], [Ref]) ("C:\", (
[ref]$free), ([ref]$total), ([ref]$totalfree))
Then I look at the value of $free
$free
72224768
Which has no bearing on the 24GB that I have free on C:. I understand that $free is a pointer, but I can not for the life of me find a way to dereference it and get to the data stored in memory. Can anyone help me figure this out. The Invoke-Win32 function that I use is a fairly common function that is floating around on the web but I can post the code for it if that would help.