怎样取得应用程序所在的路径?

解决方案 »

  1.   

    6:如何得到当前应用程序路径?
     char *str = new char[256]; 
     ::GetModuleFileName(NULL,str,MAX_PATH);
     //str即为所求
     delete []str;
     str=NULL;
      

  2.   

    The GetModuleFileName function retrieves the full path and filename for the executable file containing the specified module
      

  3.   

    (2)****************************************************
    函 数  名: GetExeFilePath
    函数功 能:返回本程序的可执行文件的路径,
    参    数1:无返回值:返回本程序的可执行文件的路径,
    属于的类:
    成员类型:
    示     例:如返回"c:\\123" ******************************************************
    CString GetExeFilePath()
    {
        CString sPath;
        GetModuleFileName(NULL,sPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH);
    sPath.ReleaseBuffer ();
       int len=sPath.GetLength();
    for(;sPath.GetAt(len-1) != '\\';len--);
    sPath= sPath.Left(len);//strPath为全路径名
    return sPath;
    }
      

  4.   

    CString CMainFrame::GetCurPath()
    {
    CString sCurPath;
    TCHAR szCurDir[MAX_PATH];
    DWORD dwResult=GetCurrentDirectory(sizeof(szCurDir)/sizeof(TCHAR),szCurDir);
    if(dwResult==0)
    return "";
    else
    {
    if(dwResult<(sizeof(szCurDir)/sizeof(TCHAR)))
    {
    sCurPath=(CString)szCurDir;
    return sCurPath;
    }
    else
    return "";
    }
    }