您的位置:首页 > 其它

MFC 获取当前程序运行目录

2016-02-25 16:02 204 查看
//--------------方式1
CString SetSoftDlg::GetCurrentPath()
{
char lpExePathName[255];
char lpExePath[255];
char lpExeName[255];
char ExeDrive[10];
char exeExt[10];

GetModuleFileName(NULL,lpExePathName,255);
_splitpath(lpExePathName,ExeDrive,lpExePath,lpExeName,exeExt);
charlpIniPathName[255];
char lpTmpFolderName[255];
char lpCurrentExePath[MAX_PATH];
strcpy(lpIniPathName,ExeDrive);
strcat(lpIniPathName,lpExePath);
strcpy(lpTmpFolderName,lpIniPathName);
strcpy(lpCurrentExePath,lpIniPathName);
CString strCurrentPath;
strCurrentPath.Format("%s",lpCurrentExePath);
return strCurrentPath;
}

//--------------方式2
CString  strPathName;
GetModuleFileName(NULL,strPathName.GetBuffer(256),256);
strPathName.ReleaseBuffer(256);
int nPos  = strPathName.ReverseFind('\');
strPathName = strPathName.Left(nPos + 1);
MessageBox(strPathName);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: