在Windows mobile 5.0下操作INI文件
2010-08-22 12:58:00 来源:WEB开发网对于Windows mobile 5.0来说没有像window那样操作INI文件的API,所以只能自已来实现。其实操作INI文件就是操作普通的文本文件,只是要麻烦一些。以下是我实现的一些常用的操作的函数:
1。读INI
BOOL ReadINIFile(const wchar_t* pszSection,
const wchar_t* pszKey,
wchar_t* pszValue)
{
ZeroMemory(chValue,ulValueLength);
HANDLE hFile = ::CreateFile(L"ini文件所在路",
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
break;
}
if(hFile != NULL)
{
CloseHandle(hFile);
return FLASE;
}
CFile iniFile;
PBYTE pFileBuf;
CString szBuf;
DWORD dwLength;
if(!iniFile.Open(lpFileName, CFile::modeRead))
return FLASE;
dwLength = (DWORD)iniFile.GetLength();
if (dwLength == 0)
return 0;
pFileBuf = new BYTE[dwLength + 2];
if (pFileBuf == NULL)
return 0;
memset(pFileBuf, 0x0, dwLength + 2);
iniFile.Read((void *)pFileBuf, dwLength);
iniFile.Close();
if (pFileBuf[0] == 0xFF && pFileBuf[1] == 0xFE)
szBuf = (LPCWSTR)(pFileBuf + 2);
else
{
PTCHAR pszWideChar = new TCHAR[dwLength + 1];
MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pFileBuf, dwLength, pszWideChar, dwLength);
szBuf = pszWideChar;
delete pszWideChar;
}
delete pFileBuf;
while (1)
{
CString szTemp;
int nPos;
if (szBuf.IsEmpty())
return FLASE;
nPos = szBuf.FindOneOf(TEXT(" "));
if (nPos == -1)
{
szTemp = szBuf;
更多精彩
赞助商链接