【问题标题】:How can I get the Nvidia driver version programatically in x86 program?如何在 x86 程序中以编程方式获取 Nvidia 驱动程序版本?
【发布时间】:2017-01-09 09:58:48
【问题描述】:

我需要的是在c++ 程序中检索到的 Nvidia 驱动程序的 2 号版本(例如 368.39)。使用 Windows 7 64b。

Here 是在 64 位应用程序中使用 Nvidia 的 NVML 库的方法。

但是,与 Nvidia 驱动程序一起分发的 nvml.dll 仅为 64 位。没有办法在我的 32 位程序中动态加载这个库。这是假设您的计算机是 64 位的。我没有在 32 位机器上测试过。

到目前为止,NVML 似乎是唯一允许检索此信息的库。如果有的话,还有什么其他方法可以得到这个?

【问题讨论】:

    标签: c++ driver gpu nvidia


    【解决方案1】:
        // ---------------------------------------------------------------------
    
        // (windows) how to get the nvidea driver version?
    
        // ---------------------------------------------------------------------
    
        #define C(a) {std::cout<<a<<std::endl;} // for easy print out to console
    
        template <class T> inline std::string TOSTR(const T fp){    // a macro
          std::ostringstream o;
          o.setf(std::ios_base::fixed, std::ios_base::floatfield);
          o << fp;  // << ends; (null-terminator character)
          return std::string(o.str());
        }
    
        // ---------------------------------------------------------------------
    
        #pragma comment(lib,"nvapi.lib")    // needed !
    
        #include <nvapi.h>  // needed !
    
        // you have to start nvapi:
    
        NvAPI_Status ret(NVAPI_OK);
        ret = NvAPI_Initialize();
        if(ret != NVAPI_OK) {
          NvAPI_ShortString string;
          NvAPI_GetErrorMessage(ret, string);
          printf("NVAPI NvAPI_Initialize: %s\n", string);
        }
    
        NvAPI_Status s;
        NvU32 v;    // version
        NvAPI_ShortString b;    // branch
        s = NvAPI_SYS_GetDriverAndBranchVersion(&v, b);
        if(s != NVAPI_OK) {
          NvAPI_ShortString string;
          NvAPI_GetErrorMessage(s, string);
          printf("NvAPI_SYS_GetDriverAndBranchVersion: %s\n", string);
        }   
    
        C("Nvidea driver version: " + TOSTR(v));    // app, console output
    
    
    // ...hope i can help ....
    

    【讨论】:

      【解决方案2】:

      我假设您使用的是 Windows,因为您提到了“.dll” 在 Windows 中,您应该能够使用 WMI 来获取您需要的任何硬件信息。对于显示适配器,请使用 Win32_VideoController WMI 类,它有一个名为 driverversion 的字符串字段,应该包含您想要的内容。

      https://msdn.microsoft.com/en-us/library/aa394512(v=vs.85).aspx

      【讨论】:

      • 这为我提供了 Nvidia 驱动程序的文件版本,如问题中的第一个链接所示。我需要 2 号版本标识符。如果有一种方法可以将一个转换为另一个,或者找到一个关联两个标识符的表格,我也想知道。谢谢。
      猜你喜欢
      • 2019-03-23
      • 2012-10-19
      • 1970-01-01
      • 2014-06-09
      • 1970-01-01
      • 2022-07-26
      • 1970-01-01
      • 2016-08-24
      • 2022-06-17
      相关资源
      最近更新 更多