如题,谢谢!

解决方案 »

  1.   

    http://community.csdn.net/Expert/topic/5612/5612380.xml?temp=.9547541
    自己读写文件实现
      

  2.   

    #define MAX_LEN 1000BOOL  WriteProfileString(const CString strSection, const CString strEntry, const CString strValue, const CString strIniPath)
    {
    if(strSection == L"" || strEntry == L"" || strValue == L"" || strIniPath == L"")
    {
    return FALSE;
    }
    CFile    IniFile;
    CString  strCombine; TRY
    {
    if(! IniFile.Open(strIniPath, CFile::modeReadWrite|CFile::modeCreate|CFile::modeNoTruncate))
    {
    return FALSE;
    } if(IniFile.GetLength() == 0)
    {
    strCombine = L"[" + strSection + L"]" + L"\r\n" 
             + strEntry + L"=" + strValue + L"\r\n";
    LPTSTR  lpCombine = strCombine.GetBuffer(0);  
    IniFile.Write(lpCombine, strCombine.GetLength() * 2);
    IniFile.Close();
    return TRUE;
    } WCHAR  *pBuf;
    pBuf = new WCHAR[IniFile.GetLength() / 2 + 1];
    if(pBuf == NULL)
    {
    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"]\r\n");
    if(iIndex1 == -1)
    {
    strCombine += L"[" + strSection + L"]" + L"\r\n" 
              + strEntry + L"=" + strValue + L"\r\n"; LPTSTR  lpCombine = strCombine.GetBuffer(0);
    IniFile.SetLength(0);
    IniFile.SeekToBegin();
    IniFile.Write(lpCombine, strCombine.GetLength() * 2);
    IniFile.Close();
    return TRUE;
    }
    iIndexT = iIndex1 + 4 + strSection.GetLength();
    iIndex2 = strCombine.Find(strEntry + L"=", iIndexT);
    if(iIndex2 == -1)
    {
    strCombine.Insert(iIndexT, strEntry + L"=" + strValue + L"\r\n"); 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"\r\n", iIndex2 + 1);
    if(iIndex3 == -1)
    {
    IniFile.Close();
    return FALSE;
    }
    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;
    }

    }
    CATCH(CFileException, e)
    {
    }
    END_CATCH

    IniFile.Close();  
    return FALSE;
    }
    CString GetProfileString(const CString strSection, const CString strEntry, const CString strDefault, const CString strIniPath)
    {
    if(strSection == L"" || strEntry == L"" || strIniPath == L"")
    {
    return strDefault;
    }
    CFile    IniFile;
    CString  strCombine; TRY
    {
    if(! IniFile.Open(strIniPath, CFile::modeRead))
    {
    return strDefault;
    }
    if(IniFile.GetLength() == 0)
    {
    IniFile.Close();
    return strDefault;
    }
    WCHAR  *pBuf;
    pBuf = new WCHAR[IniFile.GetLength() / 2 + 1];  
    if(pBuf == NULL)
    {
    IniFile.Close();
    return strDefault;
    }
    if(IniFile.Read(pBuf, IniFile.GetLength()) != IniFile.GetLength())
    {
    delete[]  pBuf;
    IniFile.Close();
    return strDefault;
    }
    pBuf[IniFile.GetLength() / 2] = NULL;
    strCombine.GetBuffer(MAX_LEN);
    strCombine = pBuf;
    delete[]   pBuf; int iIndex1, iIndex2, iIndex3, iIndexT;    
    iIndex1 = strCombine.Find(L"[" + strSection + L"]\r\n");
    if(iIndex1 == -1)
    {
    IniFile.Close();
    return strDefault;
    }
    iIndexT = iIndex1 + 4 + strSection.GetLength();
    iIndex2 = strCombine.Find(strEntry + L"=", iIndexT);
    if(iIndex2 == -1)
    {
    IniFile.Close();
    return strDefault;
    }
    else
    {
    iIndex3 = strCombine.Find(L"\r\n", iIndex2 + 1);
    if(iIndex3 == -1)
    {
    IniFile.Close();
    return strDefault;
    }
    iIndexT = iIndex2 + 1 + strEntry.GetLength();
    IniFile.Close();
    return  strCombine.Mid(iIndexT, iIndex3 - iIndexT);
    }
    }
    CATCH(CFileException, e)
    {
    }
    END_CATCH

    IniFile.Close();  
    return strDefault;
    }
    BOOL  WriteProfileInt(const CString strSection, const CString strEntry, const int iValue, const CString strIniPath)
    {
    wchar_t cBuff[MAX_LEN];
    CString strValue(""); _itow(iValue, cBuff, 10);
    strValue.Format(_T("%s"), cBuff); return WriteProfileString(strSection, strEntry, strValue, strIniPath);

    int  GetProfileInt(const CString strSection, const CString strEntry, const int iDefault, const CString strIniPath)
    {
    wchar_t cBuff[MAX_LEN];
    CString strDefault("");
    CString strReturn(""); _itow(iDefault, cBuff, 10);
    strDefault.Format(_T("%s"), cBuff); strReturn = GetProfileString(strSection, strEntry, strDefault, strIniPath); return (_wtoi(strReturn));
    }
      

  3.   

    编译通过了,我用了函数GetProfileString();里面的最后一个参数不知怎么赋值!我赋的是我的配置软件的绝对路径:如:_T("F:\\VC++学习\\lianxi\\configure1\\ini_test.ini",经调试是if(! IniFile.Open(strIniPath, CFile::modeRead))
    {
    return strDefault;
    }
    这里没打开文件,请问如何解决?