怎么得到当前应用程序的路径呢?

解决方案 »

  1.   

    CString CEhpServiceApp::GetWorkPath()
    {
    /*++
    // 函数名:GetWorkPath// 编写者:times// 参考资料:Windows system // 创建时间:2002.07.11// 修改时间:// 功  能:得到应用程序的当前目录// 输入参数:// 输出参数:// 返回值:返回字符串,当前目录// 备  注:--*/
    char FilePath[500];
        int PathLen =::GetModuleFileName(NULL,FilePath,5000);
    while(TRUE)
    {
    if (FilePath[PathLen--]=='\\')
    break;
    }
    FilePath[PathLen+2] = 0x0;
    CString PathName = FilePath;
    return PathName;
    }
      

  2.   

    GetCurrentDirectoryThe GetCurrentDirectory function retrieves the current directory for the current process. DWORD GetCurrentDirectory(
      DWORD nBufferLength,  // size of directory buffer
      LPTSTR lpBuffer       // directory buffer
    );
      

  3.   

    还有一个函数getCurrentDirectory
    CString Memo;
    getCurrentDirectory(MAX_PATH,Memo);
      

  4.   

    vc:
    getcurrentdirectory
    getmodulefilenameunix:
    getcwdtc:
    int    getcurdir(int drive,char *direc)
        此函数返回指定驱动器的当前工作目录名称。成功返回0 
            drive 指定的驱动器(0=当前,1=A,2=B,3=C等) 
            direc 保存指定驱动器当前工作路径的变量
      

  5.   

    DWORD GetModuleFileName(
      HMODULE hModule,    // handle to module
      LPTSTR lpFilename,  // file name of module
      DWORD nSize         // size of buffer
    );
      

  6.   

    c-rumtime function:_getcwd, _wgetcwd -- Get the current working directory.char *_getcwd( char *buffer, int maxlen );wchar_t *_wgetcwd( wchar_t *buffer, int maxlen );
      

  7.   

    // GETCWD.C
    /* This program places the name of the current directory in the 
     * buffer array, then displays the name of the current directory 
     * on the screen. Specifying a length of _MAX_PATH leaves room 
     * for the longest legal path name.
     */#include <direct.h>
    #include <stdlib.h>
    #include <stdio.h>void main( void )
    {
       char buffer[_MAX_PATH];   /* Get the current working directory: */
       if( _getcwd( buffer, _MAX_PATH ) == NULL )
          perror( "_getcwd error" );
       else
          printf( "%s\n", buffer );
    }
      

  8.   

    给你一个函数
    CString CDlg::GetAppPath()
    {
    char PathName[255];
    GetModuleFileName(AfxGetInstanceHandle(), PathName,sizeof( PathName ) );
    char *a,*b;
    a = b = PathName;
    while(b)
    {
         b=strchr(a+1,'\\');
         if(b) a=b;

    *a='\0'; 
    return PathName;
    }