MFC 获取当前程序运行目录


//--------------方式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);

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM