Windows CE/Mobile突破2G文件读写的限制_拔剑-浆糊的传说_新浪博客

Windows CE/Mobile突破2G文件读写的限制

The declaration of CFile actually already has a big-file operation interface
           CFile::Seek(LONGLONG lOff, UINT nFrom);  // LONGLONG -> far far more than 2G
However, in Windows CE/Mobile, it still doesn't support 4G-file I/O.

The secret is in the implementation of CFile in filecore.cpp, as follows:

ULONGLONG CFile::Seek(LONGLONG lOff, UINT nFrom)
{
...
  LARGE_INTEGER liOff;
  liOff.QuadPart = lOff;
liOff.LowPart = ::SetFilePointer(m_hFile, liOff.LowPart, 
#ifndef _WIN32_WCE  // ----------> the macro BLOCK Windows CE/Mobile from supporting big files!!!
&liOff.HighPart,
#else // !_WIN32_WCE
NULL,
#endif // !_WIN32_WCE // ------->  BLOCK Windows CE/Mobile from supporting big files!!!
 (DWORD)nFrom);
        ...
return liOff.QuadPart;
}
The root cause is simple: the macro __WIN32_WCE blocks reading/writing big files.
Actually, whether support big-file I/O depends on the functionality of SetFilePointer(),
fortunately it supports reading/writing a big file with size more than 2G in Windows CE/Mobile.

So, the simplest method to let Windows CE/Mobile support that could be the following code,
very simple:

      class CFile64: public File
      {
       public:
        virtual ULONGLONG Seek(LONGLONG lOff, UINT nFrom)
        {
            ...
               LARGE_INTEGER liOff;
               liOff.QuadPart = lOff;
             liOff.LowPart = ::SetFilePointer(m_hFile, liOff.LowPart, 
            //#ifndef _WIN32_WCE
            &liOff.HighPart,
            //#else // !_WIN32_WCE
            // NULL,
            //#endif // !_WIN32_WCE
              (DWORD)nFrom);
                    ...
            return liOff.QuadPart;
        }
        
        ULONGLONG GetPosition() const
        {
            ASSERT_VALID(this);
            ASSERT(m_hFile != INVALID_HANDLE_VALUE);
            
               LARGE_INTEGER liPos;
               liPos.QuadPart = 0;
            liPos.LowPart = ::SetFilePointer(m_hFile, liPos.LowPart, 
            //#ifndef _WIN32_WCE       //------------ disable limitation!!
            &liPos.HighPart,
            //#else // !_WIN32_WCE
            // NULL,
            //#endif // !_WIN32_WCE
            FILE_CURRENT);
            if (liPos.LowPart == (DWORD)-1)
             if (::GetLastError() != NO_ERROR)
              CFileException::ThrowOsError((LONG)::GetLastError(), m_strFileName);
            
            return liPos.QuadPart;
        }
      }


A famous stupid implementation could be found in the following URL, personally think it is stupid
and low-efficient. Why not directly copy MFC code, and make little change?
      CFile64 1.0,2009-year version:  http://download.fyxm.net/CFile64-30528.html
By the way, the biggest file size in FAT32 system is 4G. Most SD cards only support FAT32.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值