请问如何取得当前程序的路径啊?
我用在程序里打开一个文件,为什么用GetCurrentDirectory()得到的总是那个文件的路径,我如何才能得到程序的路径啊?
请大家指点。

解决方案 »

  1.   

    GetCurrentDirectory()得到的是当前操作的目录
    类似你的情况
    方法:
    1、程序运行开始时得到目录(程序当前目录),保存下来。后面调用。
    2、得到系统目录GetSystemDirectory、GetWindowsDirectory
    想法用这些目录。
      

  2.   

    ::GetModuleFileName(NULL, m_szPath, MAX_PATH);
    char *pSep = strrchr(m_szPath, '\\');
    int nLen = pSep - m_szPath;
    m_szPath[nLen] = '\0';
    ATLTRACE("program running in path %s.\r\n", m_szPath);
      

  3.   

    #define MAX_PATH          256
    char szAppDrive[MAX_PATH];
    char szAppDir[MAX_PATH];
    char szAppfname[MAX_PATH];
    char szAppext[MAX_PATH];
    char szAppFullPath[MAX_PATH];
    //Get Current Path
    ::GetModuleFileName(NULL, szAppFullPath, MAX_PATH);
    _splitpath(szAppFullPath,szAppDrive,szAppDir,szAppfname,szAppext);