MFC编程时取得当前可执行文件的路径的方法

下面的代码片段演示了
1.取得当前应用程序的路径
2.判断某一路径是否存在
3.取得和格式化当前时间
4.写二进制文件
_TCHAR path[MAX_PATH];
::GetModuleFileName(NULL, path, MAX_PATH);
CString strPath(path);
CString strWorkDir = strPath.Left(strpath.ReverseFind(*(str.GetBuffer())));
CString tempPath;
tempPath.Format(_T("%s\\work"), strWorkDir);

CFileFind f;
if(f.FindFile(tempPath)){
  strWorkDir = tempPath;
}

CTime t=CTime::GetTickCount();
CString strFilePathName;
strFilePathName.Format(_T("%s\\data%s.dat"),strWorkDir, t.Format(_T("%Y%m%d%H%M%S")));
CFile oFile(strFilePathName, CFile::modeCreate|CFile::modeWrite);
oFile.Write(pData, dataLen);
oFile.Close();

以上代码为写博时录入,可能存在拼写错误。
标签: MFC
评论: 0 | 引用: 0 | 阅读: 556
发表评论
昵 称: (必须)
密 码: (未注册用户可不填)
网 址: 邮 箱:
验证码: 验证码图片 选 项:
头 像:
内 容: