怎么才能得到应用程序存放的路径?好像GetCurrentDirectory函数经常会改变路径的,哪位大虾能指点一下吗?

解决方案 »

  1.   

    char CurrentPathName[MAX_PATH]; // 应用程序存放的路径GetModuleFileName(NULL, CurrentPathName, MAX_PATH);
      

  2.   

    GetModuleFileName的确可以
    GetModuleFileName
    The GetModuleFileName function retrieves the fully qualified path for the specified module. To specify the process that contains the module, use the GetModuleFileNameEx function. DWORD GetModuleFileName(
      HMODULE hModule,    // handle to module
      LPTSTR lpFilename,  // path buffer
      DWORD nSize         // size of buffer
    );
    Parameters
    hModule 
    [in] Handle to the module whose path is being requested. If this parameter is NULL, GetModuleFileName retrieves the path for the current module.
      

  3.   

    获得当前应用程序路径
    #include < windows.h >
    #include < string.h > HINSTANCE hInst;
    char szBuf[256];
    char *p; //拿到全部路径
    GetModuleFileName(hInst,szBuf,sizeof(szBuf)); //分离路径和文件名。
    p = szBuf;
    while(strchr(p,'\\')) {
    p = strchr(p,'\\');
    p++;
    }
    *p = '\0';
    //路径在szBuf理了。