0

i am trying to get the full name of my gpu and my gpu usage using nvapi.dll. i have encounter this post on this website: C# Performance Counter Help, Nvidia GPU.

he uses 2 sources, one in the dll itself (for getting the usage) and for full name he uses the header file of nvapi downloaded from the nevidia website.

There is any way i can avoid this duplication in my project? using only the dll or using only the header files brought by nevidia. Thanks for all the helpers

GrandMasterFlush
  • 6,269
  • 19
  • 81
  • 104
eliyahu levi
  • 108
  • 1
  • 7

2 Answers2

1

you can load DLL file dynamically when you need it,

in c# you can use .Net Reflection (if dll is developed in .Net framework), for example :

var DLL = Assembly.LoadFile(@"path\to\your.dll");

Type t = DLL.GetType("myAssembly.ClassName");
CustomType result = t.InvokeMember("methodName", BindingFlags.InvokeMethod, null, t, new object[] { @"method argument" }); 

if mentioned dll is not developed under .Net framework but you are forced to use .Net framework (for more information see this) :

int hModule = LoadLibrary(@"path\to\your.dll");
if (hModule == 0) return false;
IntPtr intPtr = GetProcAddress(hModule, "yourmethod_PTR");

if you want to use in c/c++ you can use following code :

HINSTANCE hGetProcIDDLL = LoadLibrary("path\\to\\your.dll");

if (hGetProcIDDLL == NULL) {
   std::cout << "dll not found" << std::endl;
} 

int a = function_to_call("arguments");

NOTE: if you want to load dll from unknown source I recommend to use c/c++, because in c/c++ you can manage your memory easier and free all your resources after dll loading,

Ali Bigdeli
  • 1,286
  • 3
  • 17
  • 35
  • Thank you for your answer, this isnt what i asked. – eliyahu levi Aug 02 '20 at 09:47
  • I got 2 sources that are basically the same. I don't want to use both, if i dont have to. But again thank you for your effort – eliyahu levi Aug 02 '20 at 09:54
  • clearly if you want use any of them easily load from dll path and use it, – Ali Bigdeli Aug 02 '20 at 09:57
  • yeah i know, but my question is how do i get the gpu name from nvapi.dll or get the usage from nvapi.h (nevidia website). They act diffrently (in nvapi.dll you query every function using some id) not like in nvapi.h – eliyahu levi Aug 02 '20 at 10:09
  • have you check http://eliang.blogspot.com/2011/05/getting-nvidia-gpu-usage-in-c.html sample code? mentioned link use both load library and print gpu usage. – Ali Bigdeli Aug 02 '20 at 10:16
  • yes, that is one of the sources i was talking about. He query using nvapi_queryinterface. I cant find any refrence to it any where. or the id for the function i am looking for (NvAPI_GetFullNAme) for quering it. – eliyahu levi Aug 02 '20 at 10:22
  • see https://stackoverflow.com/q/15709958/1513086 link, I think the question sample code is exactly what you want, – Ali Bigdeli Aug 02 '20 at 10:51
0

I have found the list of functions id in https://github.com/processhacker/plugins-extra/blob/master/NvGpuPlugin/nvidia.c

In addition to http://eliang.blogspot.com/2011/05/getting-nvidia-gpu-usage-in-c.html

i declared typedef int(*nvAPI_GPU_getFullName_t)(int *handle , char* name); nvAPI_GPU_getFullName_t nvAPI_GPU_getFullName=NULL; nvAPI_GPU_getFullName=(nvAPI_GPU_getFullName_t)(*NvAPI_QueryInterface)(0xCEEE8e9FUL);

eliyahu levi
  • 108
  • 1
  • 7