WinCE下SD卡格式化代码

注意:需要用到微软的API库"Storeapi.lib"和“storemgr.lib”。

#include "stdafx.h"
#include <windows.h>
#include <commctrl.h>
#include <Storemgr.h>
#include <formatdisk.h>
#include <fatutil.h>
#include <Bootpart.h>
//#include <diskio.h>
//#include <pcireg.h>

int wmain()
{
STOREINFO StoreInfo = {0};
PARTINFO PartInfo = {0};
HANDLE hFirstStore,hStore,hPart;
HINSTANCE hFatUtil = NULL;
BOOL hDismount = FALSE;//, CPart,hPartition,
BOOL hMount = FALSE;

FORMAT_PARAMS fp = {0};
FORMAT_OPTIONS pfo = {0};
DWORD dwClusSize = 0;
DWORD dwFatVersion = 16;

typedef DWORD ( *PFN_MY_FORMATVOLUME)
(HANDLE hVolume,PDISK_INFO pdi, PFORMAT_OPTIONS pfo, PFN_PROGRESS pfnProgress,PFN_MESSAGE pfnMessage);

StoreInfo.cbSize = sizeof(StoreInfo);
hFirstStore = FindFirstStore( &StoreInfo );

if(!(hFirstStore ))
{
RETAILMSG(1, (TEXT("Error FindFirstStore\r\n")));

}

FindNextStore(hFirstStore,&StoreInfo);
FindNextStore(hFirstStore,&StoreInfo);
FindNextStore(hFirstStore,&StoreInfo);

hFatUtil = LoadLibrary(L"fatutil.dll");

PFN_MY_FORMATVOLUME pfnFormatVolume = NULL ;

pfnFormatVolume = (PFN_MY_FORMATVOLUME)GetProcAddress(hFatUtil, TEXT( "FormatVolume"));
if (!pfnFormatVolume )
{
RETAILMSG(1, (TEXT("Error pfnFormatVolumeEx\r\n")));
}

hStore = OpenStore(StoreInfo.szDeviceName);
hPart = OpenPartition(hStore,L"Part00");

hDismount = DismountPartition(hPart);
if(!hDismount)
{
RETAILMSG(1, (TEXT("Error DismountStore\r\n")));
}

if(ERROR_SUCCESS != pfnFormatVolume(hPart, NULL, NULL, NULL, NULL))
{
RETAILMSG(1, (TEXT("Error pfnFormatVolumeEx\r\n")));
}

PartInfo.cbSize = (DWORD)StoreInfo.snBiggestPartCreatable;
//PartInfo.szPartitionName = L"Part00";

hDismount = CreatePartition(hStore, L"Part00", PartInfo.cbSize);
if(!hDismount)
{
RETAILMSG(1, (TEXT("Error CreatePartitionEx\r\n")));
}

hMount = MountPartition(hPart);
if(!( hMount ))
{
RETAILMSG(1, (TEXT("Error OpenStore\r\n")));
}

return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值