NvAPI_DRS_SaveSettings()在某些应用程序上失败,并显示NVAPI_ERROR

时间:2019-04-27 02:19:56

标签: gpu nvapi

我已经用nvapi编写了一些代码来创建应用程序配置文件。该代码在一个应用程序中有效,但在另一应用程序中失败。两者都是Windows MFC应用程序。在故障实例中,销毁会话之前调用的NvAPI_DRS_SaveSettings()返回NVAPI_ERROR。有谁对如何调试有任何想法?还是为什么它只能在一个应用程序中工作而不能在另一个应用程序中工作?

我尝试使用最新的nvapi并更新到最新的驱动程序,但结果相同。

    NvAPI_Status status = NVAPI_OK;
    status = NvAPI_Initialize();
    if (status != NVAPI_OK)
    {
        return false;
    }
    NvDRSSessionHandle hSession = 0;
    status = NvAPI_DRS_CreateSession(&hSession);
    if (status != NVAPI_OK)
    {
        return false;
    }
    status = NvAPI_DRS_LoadSettings(hSession);
    if (status != NVAPI_OK)
    {
        return false;
    }
    NvDRSProfileHandle hProfile = 0;
    NvAPI_UnicodeString profile_name;
    memcpy_s(profile_name, sizeof(profile_name), L"my_profile", 16 * sizeof(wchar_t));
    status = NvAPI_DRS_FindProfileByName(hSession, profile_name, &hProfile);
    if (status == NVAPI_OK) {
        status = NvAPI_DRS_DeleteProfile(hSession, hProfile);
        if (status != NVAPI_OK)
        {
            return false;
        }
        status = NvAPI_DRS_SaveSettings(hSession);
        if (status != NVAPI_OK)
        {
            return false;
        }
        status = NvAPI_DRS_LoadSettings(hSession);
        if (status != NVAPI_OK)
        {
            return false;
        }
    }

    NVDRS_PROFILE drsProfile = { 0 };
    drsProfile.version = NVDRS_PROFILE_VER;
    drsProfile.isPredefined = 0;
    memcpy_s(drsProfile.profileName, sizeof(drsProfile.profileName), L"my_profile", 16 * sizeof(wchar_t));
    status = NvAPI_DRS_CreateProfile(hSession, &drsProfile, &hProfile);
    if (status != NVAPI_OK)
    {
        return false;
    }
    NVDRS_APPLICATION app;
    app.version = NVDRS_APPLICATION_VER;
    app.isPredefined = 0;
    wchar_t current_app[2048];
    if (GetModuleFileNameW(0, current_app, 2048)) {

        memcpy_s(app.appName, sizeof(app.appName), current_app, 2048 * sizeof(wchar_t));
        memcpy_s(app.userFriendlyName, sizeof(app.appName), current_app, 2048 * sizeof(wchar_t));
        status = NvAPI_DRS_CreateApplication(hSession, hProfile, &app);
        if (status != NVAPI_OK)
        {
            return false;
        }
    }

    NVDRS_SETTING drsSetting = { 0 };
    drsSetting.version = NVDRS_SETTING_VER;
    drsSetting = NVDRS_SETTING();
    drsSetting.version = NVDRS_SETTING_VER;
    drsSetting.settingId = SHIM_MCCOMPAT_ID;
    drsSetting.settingType = NVDRS_DWORD_TYPE;
    drsSetting.u32CurrentValue = SHIM_MCCOMPAT_ENABLE;
    status = NvAPI_DRS_SetSetting(hSession, hProfile, &drsSetting);
    if (status != NVAPI_OK)
    {
        return false;
    }

    drsSetting = NVDRS_SETTING();
    drsSetting.version = NVDRS_SETTING_VER;
    drsSetting.settingId = SHIM_RENDERING_MODE_ID;
    drsSetting.settingType = NVDRS_DWORD_TYPE;
    drsSetting.u32CurrentValue = SHIM_RENDERING_MODE_ENABLE;
    status = NvAPI_DRS_SetSetting(hSession, hProfile, &drsSetting);
    if (status != NVAPI_OK)
    {
        return false;
    }

    drsSetting = NVDRS_SETTING();
    drsSetting.version = NVDRS_SETTING_VER;
    drsSetting.settingId = SHIM_RENDERING_OPTIONS_ID;
    drsSetting.settingType = NVDRS_DWORD_TYPE;
    drsSetting.u32CurrentValue = SHIM_RENDERING_OPTIONS_DEFAULT_RENDERING_MODE;
    status = NvAPI_DRS_SetSetting(hSession, hProfile, &drsSetting);
    if (status != NVAPI_OK)
    {
        return false;
    }
    status = NvAPI_DRS_SaveSettings(hSession);
    if (status != NVAPI_OK)
    {
        return false;
    }
    status = NvAPI_DRS_DestroySession(hSession);
    if (status != NVAPI_OK)
    {
        return false;
    }
    hSession = 0;

我希望由于上述代码可在一个应用程序中使用,因此它也应在另一个应用程序中使用。

0 个答案:

没有答案