高手帮忙:如何获取应用程序本身所在路径?

解决方案 »

  1.   

    int nDrive = _getdrive();//Get current path
    TCHAR szPath[_MAX_PATH];
    VERIFY( _getdcwd( nDrive, szPath, _MAX_PATH ) != NULL );
    szPath就是应用程序本身所在路径?
      

  2.   

    char szFilename[MAX_PATH];
    DWORD dwPathLen = 0;
    if((dwPathLen = ::GetModuleFileName(
    ::AfxGetInstanceHandle(),
    szFilename,
    MAX_PATH
    )) == 0) {
    return FALSE;
    }
    for(int i=dwPathLen-1; i>=0; i--) {
    if(('\\' == szFilename[i])
    || ('/' == szFilename[i])) {
    break;
    } else {
    szFilename[i] = '\0';
    }
    }
      

  3.   

    char szFilename[MAX_PATH];
    DWORD dwPathLen = 0;
    if((dwPathLen = ::GetModuleFileName(
    ::AfxGetInstanceHandle(),
    szFilename,
    MAX_PATH
    )) == 0) {
    return FALSE;
    }
    for(int i=dwPathLen-1; i>=0; i--) {
    if(('\\' == szFilename[i])
    || ('/' == szFilename[i])) {
    break;
    } else {
    szFilename[i] = '\0';
    }
    }
      

  4.   

    int nDrive = _getdrive();//Get current path
    TCHAR szPath[_MAX_PATH];
    VERIFY( _getdcwd( nDrive, szPath, _MAX_PATH ) != NULL );
    szPath就是应用程序本身所在路径
      

  5.   

    DWORD GetModuleFileName(
      HMODULE hModule,    // handle to module to find filename for
      LPTSTR lpFilename,  // pointer to buffer to receive module path
      DWORD nSize         // size of buffer, in characters
    );
    The GetModuleFileName function retrieves the full path and filename for the executable file containing the specified module.
      

  6.   

    HMODULE hModule=(HMODULE)AfxGetApp()->m_hInstance;
    char lpFn[100];
    // HANDLE hFile;
    ::GetModuleFileName(hModule,lpFn,100);
      

  7.   

    char FileName[1024];GetCurrentDirectory(1024,FileName);CString AppPath =FileName;