在Windows mobile 5.0下操作INI文件
2010-08-22 12:58:00 来源:WEB开发网LPTSTR lpCombine = strCombine.GetBuffer(0);
iniFile.SetLength(0);
iniFile.SeekToBegin();
iniFile.Write(lpCombine, strCombine.GetLength() * 2);
iniFile.Close();
return TRUE;
}
else
{
iIndex3 = strCombine.Find(L" ", iIndex2 + 1);
if(iIndex3 == -1)
{
iniFile.Close();
return FLASE;
}
iIndexT = iIndex2 + 1 + strEntry.GetLength();
strCombine.Delete(iIndexT, iIndex3 - iIndexT);
strCombine.Insert(iIndexT, strValue);
LPTSTR lpCombine = strCombine.GetBuffer(0);
iniFile.SetLength(0);
iniFile.SeekToBegin();
iniFile.Write(lpCombine, strCombine.GetLength() * 2);
iniFile.Close();
return TRUE;
}
iniFile.Close();
return FLASE;
}
3。替换INI值
BOOL ReplaceInIVal(LPCTSTR lpFolderName,LPCTSTR lpKey,LPCTSTR lpValue)
{
if(lpFolderName==NULL||lpFolderName == NULL || lpFolderName == NULL)
{
return HT_ERROR;
}
CFile iniFile;
CString strCombine;
if(!iniFile.Open(L"ini文件所在路", CFile::modeReadWrite|CFile::modeCreate|CFile::modeNoTruncate))
{
return FALSE;
}
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);
更多精彩
赞助商链接