织梦CMS - 轻松建站从此开始!

罗索

WinCE下SD卡格式化代码

jackyhwei 发布于 2010-08-20 17:04 点击:次 
如下代码经本人改写并验证成功。注意:需要用到微软的API库Storeapi.lib和storemgr.lib。
TAG:

如下代码经本人改写并验证成功。
注意:需要用到微软的API库"Storeapi.lib"和“storemgr.lib”。

  1. #include "stdafx.h" 
  2. #include <windows.h> 
  3. #include <commctrl.h> 
  4. #include <Storemgr.h> 
  5. #include <formatdisk.h> 
  6. #include <fatutil.h> 
  7. #include <Bootpart.h> 
  8. //#include <diskio.h> 
  9. //#include <pcireg.h> 
  10.  
  11. int wmain() 
  12.     STOREINFO StoreInfo = {0}; 
  13.     PARTINFO PartInfo = {0}; 
  14.     HANDLE hFirstStore,hStore,hPart; 
  15.     HINSTANCE hFatUtil = NULL; 
  16.     BOOL hDismount = FALSE;//, CPart,hPartition, 
  17.     BOOL hMount = FALSE; 
  18.  
  19.     FORMAT_PARAMS fp = {0}; 
  20.     FORMAT_OPTIONS pfo = {0}; 
  21.     DWORD dwClusSize = 0; 
  22.     DWORD dwFatVersion = 16; 
  23.  
  24.     typedef DWORD ( *PFN_MY_FORMATVOLUME) 
  25. (HANDLE hVolume,PDISK_INFO pdi, PFORMAT_OPTIONS pfo,
  26. PFN_PROGRESS pfnProgress,PFN_MESSAGE pfnMessage); 
  27.  
  28.     StoreInfo.cbSize = sizeof(StoreInfo); 
  29.     hFirstStore = FindFirstStore( &StoreInfo ); 
  30.  
  31.     if(!(hFirstStore )) 
  32.     { 
  33.         RETAILMSG(1, (TEXT("Error FindFirstStore\r\n"))); 
  34.  
  35.     } 
  36.  
  37.     FindNextStore(hFirstStore,&StoreInfo); 
  38.     FindNextStore(hFirstStore,&StoreInfo); 
  39.     FindNextStore(hFirstStore,&StoreInfo); 
  40.  
  41.     hFatUtil = LoadLibrary(L"fatutil.dll"); 
  42.  
  43.     PFN_MY_FORMATVOLUME pfnFormatVolume = NULL ; 
  44.  
  45.     pfnFormatVolume = (PFN_MY_FORMATVOLUME)GetProcAddress(hFatUtil, TEXT( "FormatVolume")); 
  46.     if (!pfnFormatVolume ) 
  47.     { 
  48.         RETAILMSG(1, (TEXT("Error pfnFormatVolumeEx\r\n"))); 
  49.     } 
  50.  
  51.     hStore = OpenStore(StoreInfo.szDeviceName); 
  52.     hPart = OpenPartition(hStore,L"Part00"); 
  53.  
  54.     hDismount = DismountPartition(hPart); 
  55.     if(!hDismount) 
  56.     { 
  57.         RETAILMSG(1, (TEXT("Error DismountStore\r\n"))); 
  58.     } 
  59.  
  60.     if(ERROR_SUCCESS != pfnFormatVolume(hPart, NULL, NULL, NULL, NULL)) 
  61.     { 
  62.         RETAILMSG(1, (TEXT("Error pfnFormatVolumeEx\r\n"))); 
  63.     } 
  64.  
  65.     PartInfo.cbSize = (DWORD)StoreInfo.snBiggestPartCreatable; 
  66.     //PartInfo.szPartitionName = L"Part00"; 
  67.  
  68.     hDismount = CreatePartition(hStore, L"Part00", PartInfo.cbSize); 
  69.     if(!hDismount) 
  70.     { 
  71.         RETAILMSG(1, (TEXT("Error CreatePartitionEx\r\n"))); 
  72.     } 
  73.  
  74.     hMount = MountPartition(hPart); 
  75.     if(!( hMount )) 
  76.     { 
  77.         RETAILMSG(1, (TEXT("Error OpenStore\r\n"))); 
  78.     } 
  79.  
  80. return 0; 

本文参考自http://bbs.driverdevelop.com/htm_data/48/0711/107241.html

(秩名)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/201008/10009.html]
本文出处:driverdevelop.com 作者:秩名
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
将本文分享到微信
织梦二维码生成器
推荐内容