Hello. 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
You need to use the method GetDiskSpaceFreeEx, Do not specify the wide character version. HEre is a link that should help: http://msdn2.microsoft.com/en-US/library/aa912270.aspx Rick D. Contractor [quoted text, click to view] "ve3wtj" wrote: > Hello. > > 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
Thanks for the suggestion, but dropping the W didn't make a difference - I still get a "NotSupportedException". I've since been able to use GetStoreInformation() to acquire main storage space, but still no success with '\Storage Card'. [quoted text, click to view] "dbgrick" wrote: > You need to use the method GetDiskSpaceFreeEx, Do not specify the wide > character version. HEre is a link that should help: > > http://msdn2.microsoft.com/en-US/library/aa912270.aspx > > Rick D. > Contractor > > "ve3wtj" wrote: > > > Hello. > > > > 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
Looks like I needed to pass the directory name by value instead of by reference. Issue resolved. -- David Friesen, B.Eng [quoted text, click to view] "ve3wtj" wrote: > Thanks for the suggestion, but dropping the W didn't make a difference - I > still get > a "NotSupportedException". > > I've since been able to use GetStoreInformation() to acquire main storage > space, but still no success with '\Storage Card'. > > > "dbgrick" wrote: > > > You need to use the method GetDiskSpaceFreeEx, Do not specify the wide > > character version. HEre is a link that should help: > > > > http://msdn2.microsoft.com/en-US/library/aa912270.aspx > > > > Rick D. > > Contractor > > > > "ve3wtj" wrote: > > > > > Hello. > > > > > > 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
A String is a reference type, so it's already being passed as a pointer. Passing it ByRef sends a pointer to a pointer, which is the likely cause of failure. -- Chris Tacke, Embedded MVP OpenNETCF Consulting Managed Code in an Embedded World www.OpenNETCF.com [quoted text, click to view] "ve3wtj" <ve3wtj@discussions.microsoft.com> wrote in message news:A6469684-AEC3-4659-90BB-54EC6587ADF2@microsoft.com... > Thanks for the suggestion, but dropping the W didn't make a difference - I > still get > a "NotSupportedException". > > I've since been able to use GetStoreInformation() to acquire main storage > space, but still no success with '\Storage Card'. > > > "dbgrick" wrote: > >> You need to use the method GetDiskSpaceFreeEx, Do not specify the wide >> character version. HEre is a link that should help: >> >> http://msdn2.microsoft.com/en-US/library/aa912270.aspx >> >> Rick D. >> Contractor >> >> "ve3wtj" wrote: >> >> > Hello. >> > >> > 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.
Public Declare Function GetDiskFreeSpaceExW Lib "CoreDll.Dll" ( _ ByVal 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) -- David Friesen, B.Eng [quoted text, click to view] "ve3wtj" wrote: > Looks like I needed to pass the directory name by value instead of by > reference. Issue resolved. > -- > David Friesen, B.Eng > > > "ve3wtj" wrote: > > > Thanks for the suggestion, but dropping the W didn't make a difference - I > > still get > > a "NotSupportedException". > > > > I've since been able to use GetStoreInformation() to acquire main storage > > space, but still no success with '\Storage Card'. > > > > > > "dbgrick" wrote: > > > > > You need to use the method GetDiskSpaceFreeEx, Do not specify the wide > > > character version. HEre is a link that should help: > > > > > > http://msdn2.microsoft.com/en-US/library/aa912270.aspx > > > > > > Rick D. > > > Contractor > > > > > > "ve3wtj" wrote: > > > > > > > Hello. > > > > > > > > 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
It returns a BOOL which is 32-bits (Integer) not 64 (Long). You have your declaration wrong. -- Chris Tacke, Embedded MVP OpenNETCF Consulting Managed Code in an Embedded World www.OpenNETCF.com [quoted text, click to view] <amiga500@gmail.com> wrote in message news:1190224464.615536.189310@r29g2000hsg.googlegroups.com... > 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. >
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.
[quoted text, click to view] On Sep 20, 3:10 am, "<ctacke/>" <ctacke[at]opennetcf[dot]com> wrote: > It returns a BOOL which is 32-bits (Integer) not 64 (Long). You have your > declaration wrong. > > -- > > Chris Tacke, Embedded MVP > OpenNETCF Consulting > Managed Code in an Embedded World www.OpenNETCF.com > > <amiga...@gmail.com> wrote in message > > news:1190224464.615536.189310@r29g2000hsg.googlegroups.com... > > > 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. http://writerviral.blogspot.com/2007/09/how-to-find-availabe-memory-on-windows.html
Don't see what you're looking for? Try a search.
|