在Windows mobile 5.0下操作INI文件
2010-08-22 12:58:00 来源:WEB开发网nSize += szTemp1.GetLength() + 1;
return FALSE;
}
}
return TRUE;
}
2。写INI
BOOL WriteInIFile(CString strSection,CString strEntry,CString strValue)
{
if(strSection == L"" || strEntry == L"" || strValue == L"")
{
return FLASE;
}
CFile iniFile;
CString strCombine;
if(!iniFile.Open(L"ini文件所在路", CFile::modeReadWrite|CFile::modeCreate|CFile::modeNoTruncate))
{
return FLASE;
}
DWORD dwFilesize = iniFile.GetLength() / 2 + 1;
WCHAR *pBuf;
try
{
pBuf = new WCHAR[dwFilesize];
}
catch(...)
{
iniFile.Close();
return FALSE;
}
if(iniFile.Read(pBuf, iniFile.GetLength()) != iniFile.GetLength())
{
delete[] pBuf;
iniFile.Close();
return FALSE;
}
pBuf[iniFile.GetLength() / 2] = NULL;
strCombine.GetBuffer(MAX_LEN);
strCombine = pBuf;
delete[] pBuf;
int iIndex1, iIndex2, iIndex3, iIndexT;
iIndex1 = strCombine.Find(L"[" + strSection + L"] ");
if(iIndex1 == -1)
{
strCombine += L"[" + strSection + L"]" + L" "
+ strEntry + L"=" + strValue + L" ";
LPTSTR lpCombine = strCombine.GetBuffer(0);
iniFile.SetLength(0);
iniFile.SeekToBegin();
iniFile.Write(lpCombine, strCombine.GetLength() * 2);
iniFile.Close();
return FLASE;
}
iIndexT = iIndex1 + 4 + strSection.GetLength();
iIndex2 = strCombine.Find(strEntry + L"=", iIndexT);
if(iIndex2 == -1)
{
strCombine.Insert(iIndexT, strEntry + L"=" + strValue + L"
更多精彩
赞助商链接