I have a problem with the GetDiskFreeSpaceEx

A

amiga500

Hello

I have discovered that someone else have the same problem as me when
it comes to GetDiskFreeSpaceEx, the only problem is I am unable to
resolve it while he have.

http://groups.google.com/group/micr...read/thread/aa8c310704610a9b/e5d1314010a16ae8

Above is the link for the discussion for that problem I have. Can
someone help me? Please click the link above as I have posted my
problem there but discovered it did not bump the topic to the top
list. Thanks in advance.

------------------ For the lazy people I have posted the problem below
in fear people will not click the link ----------

Hello,

I have same problem but I am unable to solve it. Here is my code:

--- Declaration
Private Declare Function GetDiskFreeSpaceEx Lib "coredll.dll" Alias
"GetDiskFreeSpaceEx" (ByVal lpDirectoryName As String, ByRef
lpFreeBytesAvailableToCaller As Long, ByRef lpTotalNumberOfBytes As
Long, ByRef lpTotalNumberOfFreeBytes As Long) As Long

--- Function

Public Function GetFreeSpace(ByVal Drive As String) As Long
'returns free space in MB, formatted to two decimal places
'e.g., msgbox("Free Space on C: "& GetFreeSpace("C:\") & "MB")

Dim lBytesTotal, lFreeBytes, lFreeBytesAvailable As Long

Dim iAns As Integer

iAns = GetDiskFreeSpaceEx(Drive, lFreeBytesAvailable, _
lBytesTotal, lFreeBytes)
If iAns > 0 Then

Return BytesToMegabytes(lFreeBytes)
Else
Throw New Exception("Invalid or unreadable drive")
End If
End Function

Public Function GetTotalSpace(ByVal Drive As String) As String
'returns total space in MB, formatted to two decimal places
'e.g., msgbox("Free Space on C: "& GetTotalSpace("C:\") &
"MB")

Dim lBytesTotal, lFreeBytes, lFreeBytesAvailable As Long

Dim iAns As Integer

iAns = GetDiskFreeSpaceEx(Drive, lFreeBytesAvailable, _
lBytesTotal, lFreeBytes)
If iAns > 0 Then

Return BytesToMegabytes(lBytesTotal)
Else
Throw New Exception("Invalid or unreadable drive")
End If
End Function

Private Function BytesToMegabytes(ByVal Bytes As Long) _
As Long

Dim dblAns As Double
dblAns = (Bytes / 1024) / 1024
BytesToMegabytes = Format(dblAns, "###,###,##0.00")

End Function

--- Use

'' SqlMobile.sdf located in Program Files\daedalusmobile
If GetFreeSpace("\Program Files\daedalusmobile\") <= 1 Then
If MessageBox.Show("You are low or out of space. Please
dock your equipment, complete some tasks, and then synchronize.",
MessageBoxButtons.OK) = DialogResult.OK Then
MyApp.fs.Stop()
End If
End If

When I run the program I get this error message:

NotSupportedException

Can someone please help me? Thanks in advance.
 
G

Guest

I answered this elsewhere (probably in the thread you're giving us a link
to) - don't start a new thread.

The return for GetDiskFreeSpaceEx is a native BOOL, which is #defined to a
32-bit int. That translates to a VB Integer or Int32, not a Long as you
have it defined.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Managed Code in an Embedded World
www.OpenNETCF.com
 
A

amiga500

I answered this elsewhere (probably in the thread you're giving us a link
to) - don't start a new thread.

The return for GetDiskFreeSpaceEx is a native BOOL, which is #defined to a
32-bit int. That translates to a VB Integer or Int32, not a Long as you
have it defined.

--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Managed Code in an Embedded Worldwww.OpenNETCF.com
You keep saying it the variable type but to my demsie when I followed
your advice it failed there too. Why do you think I keep requesting
help in this regard?
 
A

amiga500

I am sorry. You are right as usual and I am wrong as usual. I fixed it
and it worked. You are one hundred percent I am one hundred percent
wrong, forgive me. No more posting in this regard anymore.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top