Sign in to follow this  

ChangeDisplaySettingsEx() always returns DISP_CHANGE_BADPARAM

Recommended Posts



I am attempting to set the Display Mode of my Monitor using WinAPI C++ functions.

My Problem: Calling ChangeDisplaySettingsEx() always returns DISP_CHANGE_BADPARAM. What am I doing wrong?

I think it may be my devMode.dmDriverExtra value thats causing the error. I've read MSDN and the explaination of devMode.dmDriverExtra is confusing. What is it and how do I find out the Monitors' dmDriverExtra?

Whats causing my code below to always return `DISP_CHANGE_BADPARAM`?

DEVMODE devMode;
    POINTL p                = {0,0};
    _tcscpy(devMode.dmDeviceName, _T("\\Device\\00000072")); 
    devMode.dmSpecVersion    = DM_SPECVERSION;
    devMode.dmDriverVersion = 1;  // How do I determine the driver version?
    devMode.dmSize            = sizeof(DEVMODE);
    devMode.dmDriverExtra   = 0x5c0000; //
    devMode.dmFields        = DM_POSITION;
    devMode.dmPosition        = p;

    LONG res = ChangeDisplaySettingsEx(_T("\\Device\\00000072"), &devMode, mainHwnd, CDS_UPDATEREGISTRY | CDS_NORESET, NULL);
    _tprintf(_T("%s: %d\n\n\n"), _T("\\Device\\00000072"), res);
    // The above printf always prints out "\Device\00000072: -5" (DISP_CHANGE_BADPARAM=-5)


Share this post

Link to post
Share on other sites
For ChangeDisplaySettingsEx MSDN says: To ensure that the DEVMODE structure passed to ChangeDisplaySettingsEx is valid and contains only values supported by the display driver, use the DEVMODE returned by the EnumDisplaySettings function. I'd suggest following the MSDN instructions for EnumDisplaySettings (or EnumDisplaySettingsEx). Note: this in turn might lead to using EnumDisplayDevices if you expect there to be multiple monitors. I also looked for some examples of using these functions. The best one I could find is here: It's about 10 years old and written for the console so you'll need to adapt it to your own needs, but it wasn't that hard to understand.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this