比如我的一个SDI程序编译后生成的.exe文件的路径为:
D:\MyCpp\MySDI\Debug\Mysdi.exe怎样获得:D:\MyCpp\MySDI\Debug\这个路径??

解决方案 »

  1.   

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

  2.   

    DWORD GetCurrentDirectory(
      DWORD nBufferLength,  // size, in characters, of directory buffer
      LPTSTR lpBuffer       // pointer to buffer for current directory
    );
      

  3.   

    楼上获得的不一定是程序所在路径用GetModulePath才是获取exe所在目录,包含了exe名称
    然后自己将后面的exe去掉就是你要的目录路径了
      

  4.   

    char szPath[256];GetModuleFileName( NULL, szPath, 256 );结果中szPath包含绝对路径和文件名,如果你只需要路径的话,你还要自己去掉最后的文件名
      

  5.   

    sorry,应该是这个
    DWORD GetModuleFileName(
      HMODULE hModule,    // handle to module
      LPTSTR lpFilename,  // path buffer
      DWORD nSize         // size of buffer
    );
    hModule 
    [in] Handle to the module whose path is being requested. If this parameter is NULL, GetModuleFileName retrieves the path for the current module. 
    lpFilename 
    [out] Pointer to a buffer that receives the fully-qualified path for the module. If the length of the string exceeds the size specified by the nSize parameter, the string is truncated. 
    Windows NT/2000/XP: The path can have the prefix "\\?\", depending on how the module was loaded. For more information, see File Name Conventions. nSize 
    [in] Specifies the length of the lpFilename buffer, in TCHARs. 
      

  6.   

    GetModuleFileName(NULL, szPath, _MAX_PATH);
    char *p = _tcsrchr(m_szPath, '\\') + 1; 
    *p = '\0';