获取存储设备的大小信息

来源:互联网 发布:二手车评估软件免费 编辑:程序博客网 时间:2024/06/05 04:01

很多底层操作的函数,Visual Studio 2005.NET 的 API 库中并没有提供,这个时候,我

们就要在 C#开发中调用 Win32 的函数来进行相应的操作。一大批 Win32 底层操作的函数

都存在于 cordll.dll 动态链接库中。

调用 Win32 的申明:

using System.Runtime.InteropServices; 

在 WinCE 下已经没有了驱动器名的概念,文件存储设备都是在 WinCE 的根目录下中

以目录的形式出现,可以采用如下方法并调用相应函数来获取存储设备的总的大小和空闲空

间的信息:

[DllImport("coredll.dll")] 

private static extern bool GetDiskFreeSpaceEx(string directoryName, ref long 

freeBytesAvailable, ref long totalBytes, ref long totalFreeBytes); 

调用例子如下:

long freeBytes = 0, totalBytes = 0, totalFreeBytes = 0; 

GetDiskFreeSpaceEx("\\Nor Flash", ref freeBytes, ref totalBytes, ref totalFreeBytes); 

string strtotalBytes = "Nor Flash 磁盘空间大小为:"+totalBytes.ToString()+"Bytes";