各位,请问在Win32的程序中,我如何才能取到程序目录下的一个名为"File.ini"的路径然后让到一个BSTR的变量(FilePath)中呢?谢谢了.......(不用MFC)

解决方案 »

  1.   

    GetModuleFileName
    获得exe的路径
      

  2.   


    GetCurrentDirectory(length,path);
    strcat(path,"\\File.ini");
      

  3.   


    const DWORD length = 1024 ;
    char path[length] ;GetCurrentDirectory(length,path) ;
    strcat(path,"\\File.ini") ;//path即你要的路径
      

  4.   

    GetCurrentDirectory好像不行吧,因为我在使用配置文件之前,用OpenDlg打开了别的文件,所以路径就不对了....
      

  5.   

    char strExePath[MAX_PATH];
    memset(strExePath, 0, sizeof(strExePath));
    GetModuleFileName(NULL, strExePath, MAX_PATH);
    char *str = strrchr(strExePath, '\\');
    str++;
    *str = '\0;
    strcat(strExePath, "File.ini");
      

  6.   

    *str = '\0;  ????这句话编译不通过啊
      

  7.   

    关于GetModuleFileName(NULL,strExePath,MAX_PATH);  
    strExePath不能是char型,定义是LPWCH型,可以用TCHAR或WCHAR定义的变量得到,然后怎样与"File.ini"拼接得到一个BSTR型的变量呢?
      

  8.   

    首先感谢大家的帮助。6楼的函数GetModuleFileName编译不通过呀,参数strExePath类型错误...
      

  9.   

    工程为unicode的?
    改成anci的