用GetCurrentDirectory虽然很方便,但是不准啊,因为用户可以通过SetCurrentDirectory来改变;如果添加一个全局变量,再在程序入口处使用GetCurrentDirectory又十分繁索,有没有其它的办法????????????大侠教我!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

解决方案 »

  1.   

    用GetModuleFileName:
    char szFilePath[MAX_PATH];
    if(GetModuleFileName(NULL,szFilePath,MAX_PATH)>0)
    {
       (*strrchr(szFilePath,'\\'))='\0';//丢掉文件名,得到路径
    }
      

  2.   

    GetModuleFileName(NULL,lpfilepath,szfilepath),可以获取路径包括文件
      

  3.   

    char szPath[256];
    memset( szPath, 0, 256 );
    GetModuleFileName( NULL, szPath, 240 );
    char * p = strrchr( szPath, '\\' );
    if( p != NULL ) *p = 0;
      

  4.   

    // 取得当前执行文件路径
    char chModualName[_MAX_PATH];
    GetModuleFileName(NULL, chModualName, _MAX_PATH);
    CString strExeName(chModualName);
    int t = strExeName.ReverseFind('\\');
    strExeName.Left(t);
      

  5.   

    char buffer[256];
    memset(buffer,0,256);
    GetModuleFileName(AfxGetInstanceHandle(),buffer,256);
    int k=strlen(buffer);
    while(buffer[k]!=92)
    k--;
    buffer[k+1]='\0';