Sign in to follow this  
FriendlyAlien

Corrupted Stack on Display Enumeration only on Vista :/

Recommended Posts

Hello There guys! I have a little problem with display enumeration. I got the base code from a tutorial. I changed it a little and i used it. It war running perfect.. Using Visual Studio 2005 .NET under windows server 2003 and XP. A had test it at a lot of machines.. and worked fine.. Now.. i have install Windows Vista Ultimate on my machine and a get an error at debug mode: Run-Time Check Failure #2 - Stack around the variable 'devMode' was corrupted. Here is the source:

BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
	{
		//	Should I Use Them? :O
		UNREFERENCED_PARAMETER(hdcMonitor);
		UNREFERENCED_PARAMETER(lprcMonitor);

		MONITORINFOEX monInfo;
		monInfo.cbSize = sizeof(MONITORINFOEX);
		GetMonitorInfo(hMonitor, &monInfo);

		vector<Display>& displays = *((vector<Display>*)dwData);

		int ddIndex = 0;
		bool primaryDisplay = false;
		wstring deviceName = wstring(monInfo.szDevice), deviceString;
		vector<DisplayMode> displayModes;
		NameValuesPairList refreshRates;

		DISPLAY_DEVICE displayDevice;
		displayDevice.cb = sizeof(DISPLAY_DEVICE);

		for (ddIndex = 0; EnumDisplayDevices(0, ddIndex, &displayDevice, 0); ddIndex++)
		{
			if ((wstring(displayDevice.DeviceName) == deviceName) &&
				!((DISPLAY_DEVICE_MIRRORING_DRIVER & displayDevice.StateFlags)!=0) &&
				!((DISPLAY_DEVICE_REMOVABLE & displayDevice.StateFlags)!=0))
			{
				deviceString = wstring(displayDevice.DeviceString);
				primaryDisplay = (DISPLAY_DEVICE_PRIMARY_DEVICE & displayDevice.StateFlags)!=0;

				DEVMODE devMode;
				devMode.dmSize = sizeof(DEVMODE);
				int j = 0;
				while ( EnumDisplaySettingsEx(displayDevice.DeviceName, j, &devMode, 0) != NULL )
				{
					if (devMode.dmPelsWidth < 640 || devMode.dmPelsHeight < 480 || devMode.dmBitsPerPel < 16)
						continue;

					POINTL position;
					position.x = monInfo.rcMonitor.left;
					position.y = monInfo.rcMonitor.top;
					devMode.dmPosition = position;

					devMode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT |
						DM_DISPLAYFREQUENCY | DM_POSITION;
					LONG result = ChangeDisplaySettingsEx(displayDevice.DeviceName, &devMode, 0,
						CDS_TEST, 0);
					if (result != DISP_CHANGE_SUCCESSFUL)
						continue;

					displayModes.push_back(DisplayMode(devMode.dmPelsWidth, devMode.dmPelsHeight,
						devMode.dmDisplayFrequency, devMode.dmBitsPerPel, devMode));
					j+=1;
				}

				break;
			}
		}

		displays.push_back(Display(ddIndex, monInfo.rcMonitor.left, monInfo.rcMonitor.top,
			primaryDisplay, deviceName, deviceString, displayModes, refreshRates));


		return true;
	}

I can't see any errors :/ Any idea what is going on? Thanks for your time!

Share this post


Link to post
Share on other sites
Might this be relevant?
Quote:
lpDevMode
[out] Pointer to a DEVMODE structure into which the function stores information about the specified graphics mode. Before calling EnumDisplaySettingsEx, set the dmSize member to sizeof(DEVMODE), and set the dmDriverExtra member to indicate the size, in bytes, of the additional space available to receive private driver data.

If that is non-zero, EnumDisplaySettingsEx and EnumDisplaySettings should both try to write the private driver data just after the end of the DEVMODE structure, which will corrupt the stack.

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