WinCE下获取SD卡容量(By Walle@ARMCE)

http://www.armce.com/bbs/thread-113-1-2.html 

 

常用代码段: 从block设备中读取扇区大小,扇区数,和总容量等。

  1. void GetStorageInfo()
  2. {
  3.                 DISK_INFO  m_devinfo;
  4.         BOOL  buf=1;
  5.         unsigned long BytesReturned;
  6. //这里DSK1:的名字要根据具体你的块设备index来的,sd卡的index一般不定死,但你可以用注册表工具从Active下面找到被加载的所有block设备,你可以知道哪个DSK是哪个存储设备。5楼更新了具体的方法。
  7.         HANDLE        h_nfd = CreateFile( L"DSK1:",
  8.                 GENERIC_READ,
  9.                 0,
  10.                 NULL,
  11.                 OPEN_EXISTING,
  12.                 0,
  13.                 NULL);
  14.         if(h_nfd==NULL)
  15.                 ::MessageBox ( NULL, L"ERRO in createfile", L"ERROR", 0);
  16.        
  17.         if ( FALSE == DeviceIoControl(
  18.                 h_nfd,
  19.                 IOCTL_DISK_GETINFO,
  20.                 NULL,
  21.                 0,
  22.                 &m_devinfo
  23.                 sizeof(m_devinfo),
  24.                 &BytesReturned,
  25.                 NULL
  26.                 )) {
  27.                 ::MessageBox ( NULL, L"DISK_IOCTL_GETINFO", L"ERROR", 0);
  28.                 return ;
  29.         }
  30.         CString tmp;
  31.         tmp.Format(L"di_bytes_per_sect=%d di_total_sectors =%d Total Captal=%d/r/n",inbuf.di_bytes_per_sect,inbuf.di_total_sectors,di_total_sectors*di_bytes_per_sect );
  32.         ::MessageBox ( NULL, tmp, L"ERROR", 0);
  33.        
  34.         CloseHandle(h_nfd);       
  35. }

 

你可能感兴趣的:(WinCE工具,WinCE问题解答)