DWORD bytes(0);
SECURITY_ATTRIBUTES sa = {0};
sa.nLength = sizeof(sa);
HANDLE hFile = CreateFile(
lpFilePath,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
&sa, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile != INVALID_HANDLE_VALUE)
{
WriteFile(hFile, pData, lDataSize * lDataNum, &bytes, NULL);
CloseHandle(hFile);
return TRUE;
}
DWORD lRet(0), bytes(0);
SECURITY_ATTRIBUTES sa = {0};
sa.nLength = sizeof(sa);
HANDLE hFile = CreateFile(
lpFilePath,
GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
&sa, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile != INVALID_HANDLE_VALUE)
{
lRet = GetFileSize(hFile, NULL);
if(lRet >= lDataSize
&& ReadFile(hFile, &pData, lRet, &bytes, NULL))
{//至少有一个数据,且预留一个空间作为最新数据存放地址(无论最新数据是否存在)
lRet /= lDataSize;
}
else
{
lRet = 0;
}
CloseHandle(hFile);
}