如何在C ++中使用NvAPI_DISP_SetDisplayConfig函数?

时间:2013-06-10 12:56:22

标签: c++ scaling nvidia nvapi

我成功地使用NvAPI_DISP_GetDisplayConfig函数连续三次获取显示配置(如另一个线程中所述),现在想要更改我的某个显示的缩放选项。

但是,即使我尝试不更改任何设置(或只是更改缩放选项)并简单地应用检索到的pathInfo,NvAPI_DISP_SetDisplayConfig也会失败。有人知道为什么吗?

NvAPI_Status status = NVAPI_OK;
NvU32 deviceCount = 0;
NV_DISPLAYCONFIG_PATH_INFO_V2 *  pathInfo = NULL;

status = NvAPI_Initialize();

if (status == NVAPI_OK) {
status = NvAPI_DISP_GetDisplayConfig(&deviceCount, pathInfo);
if ((status == NVAPI_OK) && (deviceCount > 0)) {

    printf("\nFirst pass ok. \n");
    pathInfo = new NV_DISPLAYCONFIG_PATH_INFO_V2[deviceCount];

    for (int i = 0; i < deviceCount; i++)
    {
        pathInfo[i].targetInfo = 0;
        pathInfo[i].targetInfoCount = 0;
        pathInfo[i].version = NV_DISPLAYCONFIG_PATH_INFO_VER2;
        pathInfo[i].sourceModeInfo = 0;
        pathInfo[i].reserved = 0;
    }

    status = NvAPI_DISP_GetDisplayConfig(&deviceCount, pathInfo);

    if (status == NVAPI_OK) {

         printf("\nSecond pass ok. \n");
        for (int i = 0; i < deviceCount; i++)
        {
            pathInfo[i].sourceModeInfo = new NV_DISPLAYCONFIG_SOURCE_MODE_INFO_V1;
            pathInfo[i].sourceModeInfo->reserved = 0;
            pathInfo[i].targetInfo = new NV_DISPLAYCONFIG_PATH_TARGET_INFO_V2[pathInfo[i].targetInfoCount];
            for (int j = 0; j < pathInfo[i].targetInfoCount; j++) {
                pathInfo[i].targetInfo[j].details = new NV_DISPLAYCONFIG_PATH_ADVANCED_TARGET_INFO_V1;
                            pathInfo[i].targetInfo[j].details->version = NV_DISPLAYCONFIG_PATH_ADVANCED_TARGET_INFO_VER1;
                pathInfo[i].targetInfo[j].details->reserved = 0;
            }
        }
    }

    status = NvAPI_DISP_GetDisplayConfig(&deviceCount, pathInfo);
    if (status == NVAPI_OK) {
          printf("\nThird pass ok. \n");
    }

      for (int i = 0; i < deviceCount; i++)
        { 
            for (int j = 0; j < pathInfo[i].targetInfoCount; j++) {
                switch(pathInfo[i].targetInfo[j].details->scaling)
                {
                case NV_SCALING_DEFAULT:
                    printf("Default");
                    break;
                case NV_SCALING_GPU_SCALING_TO_CLOSEST:
                    printf("GPU Scaling to closest");
                    break;
                case NV_SCALING_GPU_SCALING_TO_NATIVE :
                    printf("GPU scaling to native");
                    break;
                case NV_SCALING_GPU_SCANOUT_TO_NATIVE :
                    printf("Gpu scanout to native");
                    break;
                case NV_SCALING_GPU_SCALING_TO_ASPECT_SCANOUT_TO_NATIVE :
                    printf("GPU scaling to aspect scanout to native");
                    break;
                case NV_SCALING_GPU_SCALING_TO_ASPECT_SCANOUT_TO_CLOSEST :
                    printf("Gpu scaling to aspect scanout to closest");
                    break;
                case NV_SCALING_GPU_SCANOUT_TO_CLOSEST :
                    printf("Gpu scanout to closest");
                    break;
                case NV_SCALING_CUSTOMIZED :
                    printf("Scaling customized");
                default:
                    printf("Nothing");
                    break;
               }             
            }     
        }

    //FAILS !!!!!!!!!!
      status = NvAPI_DISP_SetDisplayConfig(deviceCount,pathInfo,NV_DISPLAYCONFIG_VALIDATE_ONLY  );
    }

}

非常感谢任何帮助,非常感谢!

2 个答案:

答案 0 :(得分:0)

你似乎只是提到SetDisplayConfig失败了...它可能有助于解决你的问题,确切知道什么是错的...你能否给出具体的错误:例如,这是从NVAPI programming documentation获取的:

/*
This function is used to print to the command line a text message
describing the nvapi error and quits
*/
void PrintError(NvAPI_Status status)
{
    NvAPI_ShortString
    szDesc = {0};
    NvAPI_GetErrorMessage
    (status, szDesc);
    printf(" NVAPI error: %s\n", szDesc);
    exit(-1);
}

答案 1 :(得分:0)

这是因为IsNonNVIDIAAdapter设置为true,但未传递pOSAdapterID。 如果您确定自己拥有nVidia显卡,请在使用之前对{/ 1}}进行路径信息。