Google Search

Tuesday, November 4, 2008

Check Available Memory Space in Storeage card on windows Mobile programmatically

Recently i wanted to check available Free Memory in Memory card on Windows CE Mobile using .NETCF C# programming though i got lot of examples on the net nothing seems to work well i was getting error while pInvoking the GetDiskFreeSpaceEx function after a R&D on MSDN several samples i figured it out to get the required disk space available info below is the code snippet

below is the code snippet to get memory card available space total space etc using win32 apis

[DllImport("coredll.dll", SetLastError = true, CharSet = CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool GetDiskFreeSpaceEx(string lpDirectoryName,
out ulong lpFreeBytesAvailable,
out ulong lpTotalNumberOfBytes,
out ulong lpTotalNumberOfFreeBytes);

public static ulong GetDiskSize(string volumeName)
{
ulong avail;
ulong total;
ulong totalfree;

GetMemoryCardInfo.GetDiskFreeSpaceEx(volumeName, out avail, out total, out totalfree);

return avail;
// return others as desired
}

//call it using below function
ulong diskSize = GetDiskSize("\ your storeage path");

The above sample is working very much fine for me i tested in windows mobile smart phone 5.0 and pocketpc 6.0 if there is any issue or need more information you can reach me through email.

0 comments:

Post a Comment

Other Interesting Articles



Related Article Widget by ceveni

Search Powered by Google