概述
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.
最后
以上就是无私奇迹为你收集整理的Windows CE/Mobile突破2G文件读写的限制_拔剑-浆糊的传说_新浪博客的全部内容,希望文章能够帮你解决Windows CE/Mobile突破2G文件读写的限制_拔剑-浆糊的传说_新浪博客所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复