在VB中有App.path可以得到程序的当前路径,那么在VC中呢?就是很菜,大家不要笑话,CString str=GetCurrentPathName()不知道可不可以,我用了一下,不行,难道是因为没包含相应的头文件?如果哪位哥哥有相应的函数可以麻烦你告诉我函数名,还有应该包含的头文件。谢谢了!

解决方案 »

  1.   

    GetModuleFileName,然后去掉文件名
      

  2.   

    DWORD GetCurrentDirectory(
      DWORD nBufferLength,
      LPTSTR lpBuffer
    );reference MSDN
      

  3.   

    我都是用这种方式来做的:调用AfxGetApp()->m_pszHelpFilePath,然后去掉文件名称。 CString paths=AfxGetApp()->m_pszHelpFilePath ;
    char sCurPath[256];
    int nPos=paths.ReverseFind('\\');
    paths=paths.Left(nPos);
    strcpy(sCurPath,paths);
      

  4.   

    不要使用getcwd的方式,cwd(current work directory),因为,如果你打开一个d:\tmp目录,那么当前的工作目录就是d:\tmp了,而不是你的程序的目录,我以前吃过这个亏。
      

  5.   

    这样做:
       CFile file;
        CFileException fe;
        TCHAR LFileName[MAX_PATH];
        GetModuleFileName(NULL,LFileName,MAX_PATH);
        if(strchr(LFileName,'\\'))
    *strrchr(LFileName,'\\')='\0';
        strcat(LFileName,"\\Log.txt");
        if(!file.Open(LFileName,CFile::modeWrite,&fe))
        {
            fe.ReportError();
            return FALSE;
        }
      

  6.   

    CString GetCurDir()
    {
    CString strPath; 
    //获得当前的路径
    int FullLength = GetModuleFileName(NULL,strPath.GetBufferSetLength (MAX_PATH+1),MAX_PATH); 
    strPath.ReleaseBuffer ();
    int nPos;
    nPos=strPath.ReverseFind ('\\');
    strPath=strPath.Left (nPos+1);
    return strPath;
    }一个字不露得复制就可以了,嘿嘿
    你要是再懒就下载
    http://www.monocers.com/jon/shitmp3/shitClass.rar
    我得SManageFile类里直接有这个静态得函数!
      

  7.   

    LPTSTR temp = (LPTSTR)0;
    char szPathTmp[256],szPath[256];
    ZeroMemory(szPath,256);
    GetModuleFileName(0, szPathTmp, 256);
    temp = strrchr(szPathTmp, '\\');
    strncpy(szPath,szPathTmp,strlen(szPathTmp)-strlen(temp));
    AfxMessageBox(szPath);