MFC获取当前程序运行路径


MFC 可以使用 GetModuleFileName 函数经过处理后 , 来获取当前程序运行的路径 , 源码如下 :

CString GetProgramPath()
{
    CString  strProgramPath;
    GetModuleFileName(NULL,strProgramPath.GetBuffer(MAX_PATH),MAX_PATH);
    strProgramPath.ReleaseBuffer(MAX_PATH);
    int nPathPos  = strProgramPath.ReverseFind('\\');
    strProgramPath = strProgramPath.Left(nPathPos + 1);
    return strProgramPath;
}