WinCE下SD卡格式化代码

来源:互联网 发布:深圳男科网络咨询 编辑:程序博客网 时间:2024/05/01 17:33
 
  1. 注意:需要用到微软的API库"Storeapi.lib"和“storemgr.lib”。
  2. #include "stdafx.h" 
  3. #include <windows.h> 
  4. #include <commctrl.h> 
  5. #include <Storemgr.h> 
  6. #include <formatdisk.h> 
  7. #include <fatutil.h> 
  8. #include <Bootpart.h> 
  9. //#include <diskio.h> 
  10. //#include <pcireg.h> 
  11.  
  12. int wmain() 
  13.     STOREINFO StoreInfo = {0}; 
  14.     PARTINFO PartInfo = {0}; 
  15.     HANDLE hFirstStore,hStore,hPart; 
  16.     HINSTANCE hFatUtil = NULL; 
  17.     BOOL hDismount = FALSE;//, CPart,hPartition, 
  18.     BOOL hMount = FALSE; 
  19.  
  20.     FORMAT_PARAMS fp = {0}; 
  21.     FORMAT_OPTIONS pfo = {0}; 
  22.     DWORD dwClusSize = 0; 
  23.     DWORD dwFatVersion = 16; 
  24.  
  25.     typedef DWORD ( *PFN_MY_FORMATVOLUME) 
  26. (HANDLE hVolume,PDISK_INFO pdi, PFORMAT_OPTIONS pfo,
  27. PFN_PROGRESS pfnProgress,PFN_MESSAGE pfnMessage); 
  28.  
  29.     StoreInfo.cbSize = sizeof(StoreInfo); 
  30.     hFirstStore = FindFirstStore( &StoreInfo ); 
  31.  
  32.     if(!(hFirstStore )) 
  33.     { 
  34.         RETAILMSG(1, (TEXT("Error FindFirstStore\r\n"))); 
  35.  
  36.     } 
  37.  
  38.     FindNextStore(hFirstStore,&StoreInfo); 
  39.     FindNextStore(hFirstStore,&StoreInfo); 
  40.     FindNextStore(hFirstStore,&StoreInfo); 
  41.  
  42.     hFatUtil = LoadLibrary(L"fatutil.dll"); 
  43.  
  44.     PFN_MY_FORMATVOLUME pfnFormatVolume = NULL ; 
  45.  
  46.     pfnFormatVolume = (PFN_MY_FORMATVOLUME)GetProcAddress(hFatUtil, TEXT( "FormatVolume")); 
  47.     if (!pfnFormatVolume ) 
  48.     { 
  49.         RETAILMSG(1, (TEXT("Error pfnFormatVolumeEx\r\n"))); 
  50.     } 
  51.  
  52.     hStore = OpenStore(StoreInfo.szDeviceName); 
  53.     hPart = OpenPartition(hStore,L"Part00"); 
  54.  
  55.     hDismount = DismountPartition(hPart); 
  56.     if(!hDismount) 
  57.     { 
  58.         RETAILMSG(1, (TEXT("Error DismountStore\r\n"))); 
  59.     } 
  60.  
  61.     if(ERROR_SUCCESS != pfnFormatVolume(hPart, NULL, NULL, NULL, NULL)) 
  62.     { 
  63.         RETAILMSG(1, (TEXT("Error pfnFormatVolumeEx\r\n"))); 
  64.     } 
  65.  
  66.     PartInfo.cbSize = (DWORD)StoreInfo.snBiggestPartCreatable; 
  67.     //PartInfo.szPartitionName = L"Part00"; 
  68.  
  69.     hDismount = CreatePartition(hStore, L"Part00", PartInfo.cbSize); 
  70.     if(!hDismount) 
  71.     { 
  72.         RETAILMSG(1, (TEXT("Error CreatePartitionEx\r\n"))); 
  73.     } 
  74.  
  75.     hMount = MountPartition(hPart); 
  76.     if(!( hMount )) 
  77.     { 
  78.         RETAILMSG(1, (TEXT("Error OpenStore\r\n"))); 
  79.     } 
  80.  
  81. return 0; 
原创粉丝点击