0

我正在尝试使用 nvapi.dll 获取我的 gpu 的全名和我的 gpu 使用情况。我在这个网站上遇到过这篇文章:C# Performance Counter Help, Nvidia GPU

他使用了 2 个源,一个在 dll 本身中(用于获取使用),对于全名,他使用从 nevidia 网站下载的 nvapi 头文件。

有什么办法可以避免我的项目中出现这种重复?只使用dll或者只使用nevidia自带的头文件。感谢所有的帮助者

4

2 回答 2

1

您可以在需要时动态加载 DLL 文件,

在 c# 中,您可以使用 .Net Reflection(如果 dll 是在 .Net 框架中开发的),例如:

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" }); 

如果提到的 dll 不是在 .Net 框架下开发的,但您被迫使用 .Net 框架(有关更多信息,请参阅):

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

如果要在 c/c++ 中使用,可以使用以下代码:

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

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

int a = function_to_call("arguments");

注意:如果您想从未知来源加载 dll,我建议使用 c/c++,因为在 c/c++ 中,您可以更轻松地管理内存并在加载 dll 后释放所有资源,

于 2020-08-02T09:15:17.653 回答
0

我在https://github.com/processhacker/plugins-extra/blob/master/NvGpuPlugin/nvidia.c中找到了函数 ID 列表

除了 http://eliang.blogspot.com/2011/05/getting-nvidia-gpu-usage-in-c.html

我宣布 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);

于 2020-08-02T11:16:38.570 回答