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);

 

posted @ 2016-02-25 16:02  風行  阅读(8929)  评论(0编辑  收藏  举报