以下是代码片段: // 函 数 名:ReadIni // 功能描述:读配置文件database.ini(用来配置oracle数据库的用户名、密码和服务名的),成功返回true,否则返回false // 输入参数:void // 输出参数:bool // 创建日期:2006-5-25 // 修改日期:2006-5-25 // 作 者:joinclear // 附加说明:无 bool ReadIni() { char databuf[1024]; char filepath[1024]; memset(databuf,0,1024); memset(filepath,0,1024); GetCurrentDirectory(1024,filepath); strcat(filepath ,"//" ); strcat(filepath ,"database.ini" ); CFile file; if ( !file.Open(filepath,CFile::modeRead)) { return false; } file.Close(); memset(databuf,0,1024); GetPrivateProfileString("oracle","user id","",databuf,1024,filepath); m_sUserId = databuf; memset(databuf,0,1024); GetPrivateProfileString("oracle","password","",databuf,1024,filepath); m_sPassword = databuf; memset(databuf,0,1024); GetPrivateProfileString("oracle","data source","",databuf,1024,filepath); m_sDataSource = databuf; memset(databuf,0,1024); memset(filepath,0,1024); return true; } bool ReadIni() { char databuf[1024]; CString sPath; GetModuleFileName(NULL,sPath.GetBufferSetLength(1023),1024); sPath.ReleaseBuffer(); int nPos; nPos = sPath.ReverseFind(’//’); sPath = sPath.Left(nPos); CString str = sPath + "//database.ini"; char filepath[1024]; strcpy(filepath,(LPSTR)(LPCTSTR)str); CFile file; if ( !file.Open(filepath,CFile::modeRead)) { return false; } file.Close(); memset(databuf,0,1024); GetPrivateProfileString("oracle","user id","",databuf,1024,filepath); m_sUserId = databuf; memset(databuf,0,1024); GetPrivateProfileString("oracle","password","",databuf,1024,filepath); m_sPassword = databuf; memset(databuf,0,1024); GetPrivateProfileString("oracle","data source","",databuf,1024,filepath); m_sDataSource = databuf; memset(databuf,0,1024); memset(filepath,0,1024); return true; } |