Sergio Basurco
Sergio Basurco

Reputation: 4338

How can I get the Nvidia driver version programatically in x86 program?

What I need is the 2 number version (e.g. 368.39) of the Nvidia drivers retrieved in a c++ program. Using Windows 7 64b.

Here is how to do this in 64bit applications using NVML library from Nvidia.

However, the nvml.dll distributed with Nvidia drivers is 64bit only. There is no way to dynamically load this library in my 32bit program. This is assuming your computer is 64bit. I have not tested this on a 32bit machine.

So far the NVML seems to be the only library that allows retrieving this information. What other methods are there to get this if any?

Upvotes: 1

Views: 4256

Answers (2)

user5755892
user5755892

Reputation:

    // ---------------------------------------------------------------------

    // (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 ....

Upvotes: 2

jhbh
jhbh

Reputation: 317

I assume you are using windows since you mention ".dll" In windows you should be able to use WMI to get any hardware information you need. For a display adapter use the Win32_VideoController WMI class it has a string field called driverversion that should have what you want.

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

Upvotes: 1

Related Questions