Storage Card

  • Thread starter Thread starter Thore Berntsen
  • Start date Start date
T

Thore Berntsen

I need to determine the size and space available on the storage card on a
Pocket PC. Can anyone please help me with that?

Thore Berntsen
VBD
 
I call API function GetDiskFreeSpaceEx() to get the free space. Pass the
storage card's directory as first parameter ...

[DllImport("coredll.dll", EntryPoint="GetDiskFreeSpaceEx",
SetLastError=true)]
public static extern bool GetDiskFreeSpaceEx(string directory,
out UInt64 lpFreeBytesAvailableToCaller,
out UInt64 lpTotalNumberOfBytes,
out UInt64 lpTotalNumberOfFreeBytes);

Christian
 
From message SD Memory Status, reply by Maarten Struys


Here is a little sample, P/Invoking GetDiskFreeSpaceEx


--------------------------- file MemoryStatus.cs ----------------------

using System;
using System.Runtime.InteropServices;

namespace SmartDeviceApplication2
{

public class MemoryStatus
{
[DllImport("coredll.dll")]
public static extern bool GetDiskFreeSpaceEx (
string lpDirectoryName,
out ulong lpFreeBytesAvailableToCaller,
out ulong lpTotalNumberOfBytes,
out ulong lpTotalNumberOfFreeBytes
);

public const string STORAGE_INTERNAL = "\\";
public const string STORAGE_CARD = "\\storage card\\";

public MemoryStatus()
{
}

public static void GetStorageInfo (string storagePath, out int
totalBytes, out int availBytes)
{
ulong freeBytesAvail, totalBytesAvail, freeBytesTotal;
bool result = GetDiskFreeSpaceEx(storagePath, out freeBytesAvail, out
totalBytesAvail, out freeBytesTotal);

if (result == true)
{
totalBytes = Convert.ToInt32(totalBytesAvail);
availBytes = (int)freeBytesAvail;
}
else
{
totalBytes = -1;
availBytes = -1;
}
}
}
}

--------------------------- end file MemoryStatus.cs ----------------------

Usage:

int totalBytes, availBytes;

MemoryStatus.GetStorageInfo(MemoryStatus.STORAGE_CARD, out totalBytes, out
availBytes);
label1.Text = totalBytes.ToString();
 
Back
Top