Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. GetVCPFeatureAndVCPFeatureReply fails when called

GetVCPFeatureAndVCPFeatureReply fails when called

Scheduled Pinned Locked Moved C / C++ / MFC
comjsonquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Valentinor
    wrote on last edited by
    #1

    I was trying to get gamma value of monitor using GetVCPFeatureAndVCPFeatureReply[^] to have the default value, and later when using SetVCPFeature[^] to be able to revert to it. But when GetVCPFeatureAndVCPFeatureReply is called, it fails. What am I doing wrong? Here is the code test:

    #include
    #include
    #include
    #include
    #include

    #pragma comment(lib, "Dxva2.lib")

    int main() {
    // Time to click on a different window to test on multiple monitors
    std::this_thread::sleep_for(std::chrono::milliseconds(2000));
    HWND hwnd = GetForegroundWindow();

    HMONITOR hMonitor = NULL;
    DWORD cPhysicalMonitors;
    LPPHYSICAL\_MONITOR pPhysicalMonitors = NULL;
    
    hMonitor = MonitorFromWindow(hwnd, MONITOR\_DEFAULTTONEAREST);
    
    BOOL bSuccess = GetNumberOfPhysicalMonitorsFromHMONITOR(hMonitor, &cPhysicalMonitors);
    if (bSuccess) {
    	pPhysicalMonitors = (LPPHYSICAL\_MONITOR)malloc(cPhysicalMonitors \* sizeof(PHYSICAL\_MONITOR));
    	if (pPhysicalMonitors != NULL) {
    		bSuccess = GetPhysicalMonitorsFromHMONITOR(hMonitor, cPhysicalMonitors, pPhysicalMonitors);
    		if (bSuccess) {
    			DWORD pdwCurrentValue;
    			DWORD pdwMaximumValue;
    			bSuccess = GetVCPFeatureAndVCPFeatureReply(pPhysicalMonitors->hPhysicalMonitor, 0x72, NULL, &pdwCurrentValue, &pdwMaximumValue);
    			if (bSuccess) {
    				std::cout << "Current value: " << pdwCurrentValue << " | MaximumValue: " << pdwMaximumValue;
    			}
    			else {
    				std::cout << "Failed GetVCPFeatureAndVCPFeatureReply" << std::endl;
    			}
    		}
    		else {
    			std::cout << "Failed GetPhysicalMonitorsFromHMONITOR" << std::endl;
    		}
    
    		DestroyPhysicalMonitors(cPhysicalMonitors, pPhysicalMonitors);
    		free(pPhysicalMonitors);
    	}
    	else {
    		std::cout << "Is null" << std::endl;
    	}
    }
    else {
    	std::cout << "Failed GetNumb
    
    C V 2 Replies Last reply
    0
    • V Valentinor

      I was trying to get gamma value of monitor using GetVCPFeatureAndVCPFeatureReply[^] to have the default value, and later when using SetVCPFeature[^] to be able to revert to it. But when GetVCPFeatureAndVCPFeatureReply is called, it fails. What am I doing wrong? Here is the code test:

      #include
      #include
      #include
      #include
      #include

      #pragma comment(lib, "Dxva2.lib")

      int main() {
      // Time to click on a different window to test on multiple monitors
      std::this_thread::sleep_for(std::chrono::milliseconds(2000));
      HWND hwnd = GetForegroundWindow();

      HMONITOR hMonitor = NULL;
      DWORD cPhysicalMonitors;
      LPPHYSICAL\_MONITOR pPhysicalMonitors = NULL;
      
      hMonitor = MonitorFromWindow(hwnd, MONITOR\_DEFAULTTONEAREST);
      
      BOOL bSuccess = GetNumberOfPhysicalMonitorsFromHMONITOR(hMonitor, &cPhysicalMonitors);
      if (bSuccess) {
      	pPhysicalMonitors = (LPPHYSICAL\_MONITOR)malloc(cPhysicalMonitors \* sizeof(PHYSICAL\_MONITOR));
      	if (pPhysicalMonitors != NULL) {
      		bSuccess = GetPhysicalMonitorsFromHMONITOR(hMonitor, cPhysicalMonitors, pPhysicalMonitors);
      		if (bSuccess) {
      			DWORD pdwCurrentValue;
      			DWORD pdwMaximumValue;
      			bSuccess = GetVCPFeatureAndVCPFeatureReply(pPhysicalMonitors->hPhysicalMonitor, 0x72, NULL, &pdwCurrentValue, &pdwMaximumValue);
      			if (bSuccess) {
      				std::cout << "Current value: " << pdwCurrentValue << " | MaximumValue: " << pdwMaximumValue;
      			}
      			else {
      				std::cout << "Failed GetVCPFeatureAndVCPFeatureReply" << std::endl;
      			}
      		}
      		else {
      			std::cout << "Failed GetPhysicalMonitorsFromHMONITOR" << std::endl;
      		}
      
      		DestroyPhysicalMonitors(cPhysicalMonitors, pPhysicalMonitors);
      		free(pPhysicalMonitors);
      	}
      	else {
      		std::cout << "Is null" << std::endl;
      	}
      }
      else {
      	std::cout << "Failed GetNumb
      
      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      On function call failure, why didn't you call GetLastError, as hinted by the documentation[^]? Also, at the very beginning of the linked page, there is:

      The physical monitor configuration functions work using the VESA Monitor Control Command Set (MCCS) standard over an I2C interface. Many monitors don't fully implement that standard; so your use of these commands might result in undefined monitor behavior. We don't recommend using these functions for arbitrary monitors without physically validating that they work as intended.

      "In testa che avete, Signor di Ceprano?" -- Rigoletto

      V 1 Reply Last reply
      0
      • C CPallini

        On function call failure, why didn't you call GetLastError, as hinted by the documentation[^]? Also, at the very beginning of the linked page, there is:

        The physical monitor configuration functions work using the VESA Monitor Control Command Set (MCCS) standard over an I2C interface. Many monitors don't fully implement that standard; so your use of these commands might result in undefined monitor behavior. We don't recommend using these functions for arbitrary monitors without physically validating that they work as intended.

        "In testa che avete, Signor di Ceprano?" -- Rigoletto

        V Offline
        V Offline
        Valentinor
        wrote on last edited by
        #3

        CPallini wrote:

        On function call failure, why didn't you call GetLastError, as hinted by the documentation[^]?

        I don't know how to use it. C/C++ isn't my main language, and only use it when I have to.

        CPallini wrote:

        Also, at the very beginning of the linked page, there is:

        That is not a problem for my monitor.

        C 1 Reply Last reply
        0
        • V Valentinor

          CPallini wrote:

          On function call failure, why didn't you call GetLastError, as hinted by the documentation[^]?

          I don't know how to use it. C/C++ isn't my main language, and only use it when I have to.

          CPallini wrote:

          Also, at the very beginning of the linked page, there is:

          That is not a problem for my monitor.

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #4

          Retrieving the Last-Error Code - Win32 apps | Microsoft Learn[^].

          "In testa che avete, Signor di Ceprano?" -- Rigoletto

          1 Reply Last reply
          0
          • V Valentinor

            I was trying to get gamma value of monitor using GetVCPFeatureAndVCPFeatureReply[^] to have the default value, and later when using SetVCPFeature[^] to be able to revert to it. But when GetVCPFeatureAndVCPFeatureReply is called, it fails. What am I doing wrong? Here is the code test:

            #include
            #include
            #include
            #include
            #include

            #pragma comment(lib, "Dxva2.lib")

            int main() {
            // Time to click on a different window to test on multiple monitors
            std::this_thread::sleep_for(std::chrono::milliseconds(2000));
            HWND hwnd = GetForegroundWindow();

            HMONITOR hMonitor = NULL;
            DWORD cPhysicalMonitors;
            LPPHYSICAL\_MONITOR pPhysicalMonitors = NULL;
            
            hMonitor = MonitorFromWindow(hwnd, MONITOR\_DEFAULTTONEAREST);
            
            BOOL bSuccess = GetNumberOfPhysicalMonitorsFromHMONITOR(hMonitor, &cPhysicalMonitors);
            if (bSuccess) {
            	pPhysicalMonitors = (LPPHYSICAL\_MONITOR)malloc(cPhysicalMonitors \* sizeof(PHYSICAL\_MONITOR));
            	if (pPhysicalMonitors != NULL) {
            		bSuccess = GetPhysicalMonitorsFromHMONITOR(hMonitor, cPhysicalMonitors, pPhysicalMonitors);
            		if (bSuccess) {
            			DWORD pdwCurrentValue;
            			DWORD pdwMaximumValue;
            			bSuccess = GetVCPFeatureAndVCPFeatureReply(pPhysicalMonitors->hPhysicalMonitor, 0x72, NULL, &pdwCurrentValue, &pdwMaximumValue);
            			if (bSuccess) {
            				std::cout << "Current value: " << pdwCurrentValue << " | MaximumValue: " << pdwMaximumValue;
            			}
            			else {
            				std::cout << "Failed GetVCPFeatureAndVCPFeatureReply" << std::endl;
            			}
            		}
            		else {
            			std::cout << "Failed GetPhysicalMonitorsFromHMONITOR" << std::endl;
            		}
            
            		DestroyPhysicalMonitors(cPhysicalMonitors, pPhysicalMonitors);
            		free(pPhysicalMonitors);
            	}
            	else {
            		std::cout << "Is null" << std::endl;
            	}
            }
            else {
            	std::cout << "Failed GetNumb
            
            V Offline
            V Offline
            Valentinor
            wrote on last edited by
            #5

            I'm going to look for other ways to change gamma and brightness as this function has too many limitations on hardware. In the past I used SetDeviceGammaRamp[^] for changing gamma, but now it seems that function shouldn't be used anymore. If anyone has some suggestion, they are welcomed and helpful.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups