I'm running Win Mobile 5.0 on an ARM XScale, and writing in VS2005 - Visual
Basic with Compact Framework 2.0.
I want to find out (programmaticaly) how much storage space is available on
the Pocket PC, both in main storage ("\") and on a storage card ("\Storage
Card\"), and show a message box if either has less than 16 MB free.
I've tried the following inside a "Public Class Form1" but get a
NotSupportedException error:
Public Declare Function GetDiskFreeSpaceExW Lib "CoreDll.Dll" ( _
ByRef DirectoryName As String, _
ByRef FreeBytesAvailable As Int64, _
ByRef TotalNumberOfBytes As Int64, _
ByRef TotalNumberOfFreeBytes As Int64) As Boolean
Dim res As Boolean
res = Form1.GetDiskFreeSpaceExW("\", FreeBytesAvailable, TotalNumberOfBytes,
TotalNumberOfFreeBytes)
MsgBox(FreeBytesAvailable.ToString)
I've also tried using GlobalMemoryStatus and GetSystemMemoryDivision - these
work without raising an exception, but seem to give me program memory instead
of storage space.
http://msdn2.microsoft.com/en-US/library/aa912270.aspx
Rick D.
Contractor
I've since been able to use GetStoreInformation() to acquire main storage
space, but still no success with '\Storage Card'.
--
Chris Tacke, Embedded MVP
OpenNETCF Consulting
Managed Code in an Embedded World
www.OpenNETCF.com
"ve3wtj" <ve3...@discussions.microsoft.com> wrote in message
news:A6469684-AEC3-4659...@microsoft.com...
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.
Dim res As Boolean
res = Form1.GetDiskFreeSpaceExW("\", FreeBytesAvailable, TotalNumberOfBytes,
TotalNumberOfFreeBytes)
MsgBox(FreeBytesAvailable.ToString)
--
--
Chris Tacke, Embedded MVP
OpenNETCF Consulting
Managed Code in an Embedded World
www.OpenNETCF.com
<amig...@gmail.com> wrote in message
news:1190224464.6...@r29g2000hsg.googlegroups.com...
http://writerviral.blogspot.com/2007/09/how-to-find-availabe-memory-on-windows.html