Returning Free Storage Spce on Omni XT15

This question is answered

Hi

I'm trying to figure out how to return the available free storage space prior to writing images.  I'm using the Omni XT15 and the device is running WIndows Embedded Handheld 6.5 Profrssional on Win CE 5.2. and I'm programming using VB.NET (VS2008) with .NET 3.5.

I can't find anything in the System.IO namespace but did find an article on using the GetFreeDiskSpaceEx() function.  After some jiggery pokery I've managed to get the function to run without erroring on compiliation but it returns zero (call failed).  Can you help please?

 The code I've created is:

Private Shared Function GetDiskFreeSpaceEx(ByVal directoryName As String, ByRef freeBytesAvailable As Long, ByRef totalBytes As Long, ByRef totalFreeBytes As Long) As Boolean

End Function

Function GetFreeSpace(ByVal path As String) As Long

Try

Dim freeBytes As Long = 0

Dim totalBytes As Long = 0

Dim totalFreeBytes As Long = 0

Dim result As Boolean = GetDiskFreeSpaceEx(path, freeBytes, totalBytes, totalFreeBytes)

If result = False Then

'call failed handle the error

Return 0

Else

Return CLng(freeBytes / 1024)

End If

Catch ex As Exception

Return 0

End Try

End Function

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim lngMem As Long

lngMem = GetFreeSpace("\")

MsgBox(CStr(lngMem))

End Sub

Verified Answer
  • I figured out my own issue.  I was missing the following statement above the declaration of the GetFreeDiskSpaceEx function

    <System.Runtime.InteropServices.DllImport("coredll.dll")> _

    I'm surprised the code compiled but at least I understand now where I went wrong.

All Replies
  • I figured out my own issue.  I was missing the following statement above the declaration of the GetFreeDiskSpaceEx function

    <System.Runtime.InteropServices.DllImport("coredll.dll")> _

    I'm surprised the code compiled but at least I understand now where I went wrong.

  • Great Job PM.

    -sean

    Sean M. Kennedy  {Americas Help Desk Application Support}

  • Good morning pm620wh,

    Although you already figured it out Yes, let me bring the « Retrieving Storage Info in .NET - HOW TO? » demo to your attention...

    Kind regards,
    Jacques

  • Awesome - comprehensive and very useful in terms of learning

    Thanks for taking the time to add the link.