ITPub博客

首页 > Linux操作系统 > Linux操作系统 > WinCE下SD卡格式化代码

WinCE下SD卡格式化代码

原创 Linux操作系统 作者:warchief_dx 时间:2009-06-30 16:09:47 0 删除 编辑
注意:需要用到微软的API库"Storeapi.lib"和“storemgr.lib”。

#include "stdafx.h"
#include
#include
#include
#include
#include
#include
//#include
//#include

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;
}

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/21917021/viewspace-607943/,如需转载,请注明出处,否则将追究法律责任。

下一篇: WinCE6.0注册表
请登录后发表评论 登录
全部评论

注册时间:2009-06-18

  • 博文量
    36
  • 访问量
    25578