SD Memory status

  • Thread starter Thread starter Ofer B.
  • Start date Start date
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();
 
Is there a way to get the actual path to the SD-card independent on machine?
For example, on Dell Axim the path would be \SD Card\ while on a Intermec
700C it's \SDMMC disk\

br,

Peter


Maarten Struys said:
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 ----------------------
 
Back
Top