Answered How to Format SD Card with FAT16

  • Tuesday, August 08, 2006 1:06 PM
     
     
    Hi guys,
     I want to develop a program  to format SD Card with FAE16 in Wince5.0,VS2005.
    I've tried the following two methods:
    1.OpenStore()->DismountStore()->FormatStore()->CreatePartitionEX(),the parameter
      bByteType is 0x04,which indicates FAT16.The result,File System is FAT32.
    2.FormatVolume(),after include "Formatdisk.h"  my complier sad the function "Formatdisk.h" is not founded.
    and then I use "Find" to find the file,and then found the file is not existed in my computer. 
    Why does the msdn say the function is supported in Windows CE .NET 4.0 and later but I can't use it?
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcemain4/html/cmrefformatvolume.asp
     
     All suggestion is appreciated.Thank You.
     
     Para

All Replies

  • Tuesday, August 08, 2006 6:24 PM
     
     

    Not sure about 1, but as for 2 - you are looking at the Platform Builder documentation, which has different set of include files. In VS2005 you are using an SDK where FormatVolume is defined in FSDMgr.h. The actual function name is FSDMGR_FormatVolume and you can get yo it using GetProcAddress on FSDMGR.dll.

    See also

    typedef DWORD (*PFN_FORMATVOLUME)(HANDLE hFile, PDISK_INFO pdi,
        PFORMAT_OPTIONS pfo, PFN_PROGRESS pfnProgress, PFN_MESSAGE pfnMessage);
    in fatutil.h

  • Wednesday, August 09, 2006 2:46 AM
     
     

     

    Thank you very much,Alex.Can you explain it in detail?

       I tried the following codes:

       1,HINSTANCE hLib = LoadLibrary(LIB_PATH_FORMATVOLUME);
       //path of FSDMGR.lib, not dll,I can't find the dll. hLib is OK.
      
       2.PFN_FORMATVOLUMEEX pfnFormatVolume = (PFN_FORMATVOLUMEEX)GetProcAddress  (hLib,L"FSDMGR_FormatVolume");
       //"FSDMGR_FormatVolume" looks like is not the right parameter, and I think that's not the right mothed.
       //But the def doesn't export any function, so I use this to replace it. pfnFormatVolume is NULL.

       3.HANDLE hVolume = CreateFile(szFolderName, GENERIC_READ|GENERIC_WRITE,
      0, NULL, OPEN_EXISTING, 0, NULL);
      //The HANDLE is OK.


       4. PFORMAT_PARAMS pfo;
          pfo->cbSize = sizeof(FORMAT_PARAMS);
          pfo->fo.dwClusSize = 0;
          pfo->fo.dwFatVersion = 16;
         pfnFormatVolume(hVolume, pfo);
     
       beause 2 failed,so the code can't format SD Card.
      
    Can you give me some code?Thank you in advance.

    Para

  • Wednesday, August 09, 2006 8:25 AM
     
     Answered
    Wow! This was fun. See here for details and a code sample
  • Monday, August 14, 2006 2:13 AM
     
     

     Thank you ,Alex.Now everything is OK,thanks again.
    I think there maybe someone is also search the information about formating SD Card like me several days ago.

    I'd like to share my experience with them.

          1.
          FindFirstStore(storeinfo);
          hStore = OpenStore(storeinfo.szDeviceName);
          DismountStore(hStore);
          CreatePartition(hStore,L"Part00",storeinfo.snNumSectors);
          hPartition = OpenPartition(hStore,partinfo.szPartitionName);

          Now we formated SD Card with FAT16 or FAT32, and then we format with FAT16,


          2.
          DismountPartition(hPartition);
          hLib = LoadLibrary(LIB_PATH_FORMATVOLUME);
          PFN_FORMATVOLUMEEX pfnFormatVolume = (PFN_FORMATVOLUMEEX)GetProcAddress(hLib,L"FormatVolumeEx");
          FORMAT_PARAMS fp = {0};
          fp.fo.dwFatVersion = 16;
          pfnFormatVolume(hPartition,&fp);
          MountPartition(hPartition);


    OK,that's all. I hope this can give some help to somebody.

    If there is any question,please mail me, liufei_para@hotmail.com.

     

  • Thursday, September 21, 2006 6:23 AM
     
     
    Hi para,

    can you please share with me the full source code?