NvAPI_GPU_GetAllDisplayIds函数未按预期工作

时间:2018-01-06 14:07:41

标签: c++ malloc nvapi

我在C ++中使用NVAPI来修改程序中的NVIDIA显示设置。

我无法成功使用libicudata.a功能。通过调用它返回的状态是NvAPI_GPU_GetAllDisplayIds

这是我的代码:

NVAPI_INCOMPATIBLE_STRUCT_VERSION

我是否错误地使用int main() { NvAPI_Status status; NvPhysicalGpuHandle nvGPUHandle[64]; NvU32 gpuCount; status = NvAPI_EnumPhysicalGPUs(nvGPUHandle, &gpuCount); if (NVAPI_OK != status) { cerr << "Failed to run function: NvAPI_EnumPhysicalGPUs\nStatus: " << status << endl; return 1; } if (gpuCount <= 0) { cerr << "No GPU's found" << endl; return 1; } for (unsigned i = 0; i < gpuCount; ++i) { const NvPhysicalGpuHandle& hPhysicalGpu = nvGPUHandle[i]; NvU32 displayIdCount = 0; status = NvAPI_GPU_GetAllDisplayIds(hPhysicalGpu, nullptr, &displayIdCount); if (NVAPI_OK != status) { cerr << "Failed to run function: NvAPI_GPU_GetAllDisplayIds\nStatus: " << status << endl; return 1; } if (displayIdCount <= 0) { cerr << "No display's found" << endl; return 1; } NV_GPU_DISPLAYIDS* displayIds = static_cast<NV_GPU_DISPLAYIDS*>(malloc(sizeof(NV_GPU_DISPLAYIDS) * displayIdCount)); status = NvAPI_GPU_GetAllDisplayIds(hPhysicalGpu, displayIds, &displayIdCount); if (NVAPI_OK != status) { // status is NVAPI_INCOMPATIBLE_STRUCT_VERSION (-9) cerr << "Failed to run function: NvAPI_GPU_GetAllDisplayIds\nStatus: " << status << endl; return 1; } } return 0; } 或其他内容? 谢谢!

1 个答案:

答案 0 :(得分:1)

此功能的NVAPI文档页面中没有直接记录,但您需要在malloc'ed displayIds结构上设置版本,然后再将其传递给NvAPI_GPU_GetAllDisplayIds。在通话前添加此行:

displayIds->version = NV_GPU_DISPLAYIDS_VER;

在整个NVAPI中,这似乎也很标准,还有其他函数调用。