16,471
社区成员
发帖
与我相关
我的任务
分享
bool ParseDefPath()
{
bool bDefPath = false;
ZeroMemory(m_strDefPath,sizeof(m_strDefPath));
//m_strDefPath = TEXT("");
TCHAR szFilePath[256] = {0};
GetModuleFileName(theApp.m_hInstance,szFilePath,sizeof(szFilePath)/sizeof(TCHAR));
CString strRunPath;
strRunPath.Format(TEXT("%s"),szFilePath);
int nSep = strRunPath.ReverseFind(TEXT('\\'));
CString strRunIni;
strRunIni = strRunPath.Left(nSep) + TEXT("\\defpath.txt");
OutputDebugString(strRunIni);
if (!PathFileExists(strRunIni))
{
OutputDebugString(TEXT("can't find ini"));
return bDefPath;
}
OutputDebugString(TEXT("1....\n"));
CFile pFile;
bDefPath = pFile.Open(strRunIni,CFile::modeReadWrite);
OutputDebugString(TEXT("2....\n"));
if (!bDefPath)
{
CString strFail;
strFail.Format(TEXT("open ini failed,path = %s ,failed value = %d"),strRunIni,GetLastError());
OutputDebugString(strFail);
return bDefPath;
}
OutputDebugString(TEXT("3....\n"));
char strMsg[200] = {0};
pFile.Read(strMsg,200);
pFile.Close();
OutputDebugString(TEXT("4....\n"));
if (sscanf(strMsg,"defaultpath = %s",m_strDefPath))
{
CString strFail;
strFail.Format(TEXT("parse ini succeed,path = %s ,m_strDefPath = %s"),strRunIni,m_strDefPath);
OutputDebugString(strFail);
return true;
}
OutputDebugString(TEXT("5....\n"));
CString strFail;
strFail.Format(TEXT("parse ini failed,path = %s ,failed value = %d"),strRunIni,GetLastError());
OutputDebugString(strFail);
return false;
}
CString strRunCmd;
.... //此处略去为strRunCmd赋路径,路径没问题。
STARTUPINFOA si;
ZeroMemory(&si, sizeof(STARTUPINFOA));
si.cb = sizeof(STARTUPINFOA);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
PROCESS_INFORMATION pi;
bSucceed = CreateProcessA(NULL,W2A(strRunCmd.GetBuffer()),NULL,NULL,0,0,NULL,NULL,
&si,&pi);
{
TCHAR szFilePath[MAX_PATH+1] = {0};
GetModuleFileName(NULL, szFilePath, MAX_PATH);
PathRemoveFileSpec(szFilePath);
_tcscat_s(szFilePath, TEXT("\\defpath.txt"));
try
{
char strMsg[200] = {0};
CFile pFile(szFilePath,CFile::modeReadWrite);
pFile.Read(strMsg,200);
pFile.Close();
if (sscanf(strMsg,"defaultpath = %s",m_strDefPath))
{
CString strFail;
strFail.Format(TEXT("parse ini succeed,path = %s ,m_strDefPath = %s"),szFilePath,m_strDefPath);
OutputDebugString(strFail);
return true;
}
}
catch (CFileException *e)
{
e->ReportError();
e->Delete();
}
return false;
}
CFileException ex;
bDefPath = pFile.Open(strRunIni,CFile::modeReadWrite,&ex);
CFileException ex;
bDefPath = pFile.Open(strRunIni,CFile::modeReadWrite);