配置文件路径的有关问题
配置文件路径的问题!
我写了个配置文件这样读取是对的
CString strServerIp;
CString strIpFileName = "C:\\ip.config ";
CString ipInfo, ipstr;
GetPrivateProfileString( "ip info ", "IP Address ", " ",ipstr.GetBuffer(100),100, strIpFileName);
ipstr.ReleaseBuffer();
ipInfo += (ipstr + "\r\n ");
strServerIp = ipInfo;
可是我把配置文件放在Release下,上面的第二行改成这样的
CString strIpFileName = ".\\Release\\ip.config ";就不对了,怎么回事呢??大家告诉我下啊!!
大家的配置文件打包时都放在哪呀?
------解决方案--------------------
跟应用程序放在一起
CString strIpFileName = GetApPath() + "config.ini ";
CString GetApPath()
{
TCHAR exeFullPath[MAX_PATH];
CString strPath;
// GetModuleFileName(NULL,exeFullPath,MAX_PATH);
GetModuleFileName(AfxGetInstanceHandle(),exeFullPath,MAX_PATH);
strPath=(CString)exeFullPath;
int position=strPath.ReverseFind( '\\ ');
strPath=strPath.Left(position+1);
return strPath;
}
------解决方案--------------------
CString GetExePath()
{
CString strPathName;
GetModuleFileName(NULL,strPathName.GetBuffer(256),256);
strPathName.ReleaseBuffer();
int nPos = strPathName.ReverseFind( '\\ ');
strPathName = strPathName.Left(nPos + 1);
return strPathName;
}
我写了个配置文件这样读取是对的
CString strServerIp;
CString strIpFileName = "C:\\ip.config ";
CString ipInfo, ipstr;
GetPrivateProfileString( "ip info ", "IP Address ", " ",ipstr.GetBuffer(100),100, strIpFileName);
ipstr.ReleaseBuffer();
ipInfo += (ipstr + "\r\n ");
strServerIp = ipInfo;
可是我把配置文件放在Release下,上面的第二行改成这样的
CString strIpFileName = ".\\Release\\ip.config ";就不对了,怎么回事呢??大家告诉我下啊!!
大家的配置文件打包时都放在哪呀?
------解决方案--------------------
跟应用程序放在一起
CString strIpFileName = GetApPath() + "config.ini ";
CString GetApPath()
{
TCHAR exeFullPath[MAX_PATH];
CString strPath;
// GetModuleFileName(NULL,exeFullPath,MAX_PATH);
GetModuleFileName(AfxGetInstanceHandle(),exeFullPath,MAX_PATH);
strPath=(CString)exeFullPath;
int position=strPath.ReverseFind( '\\ ');
strPath=strPath.Left(position+1);
return strPath;
}
------解决方案--------------------
CString GetExePath()
{
CString strPathName;
GetModuleFileName(NULL,strPathName.GetBuffer(256),256);
strPathName.ReleaseBuffer();
int nPos = strPathName.ReverseFind( '\\ ');
strPathName = strPathName.Left(nPos + 1);
return strPathName;
}