Jump to content
  • Advertisement
Sign in to follow this  

Corrupted Stack on Display Enumeration only on Vista :/

This topic is 4300 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

		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)

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

					LONG result = ChangeDisplaySettingsEx(displayDevice.DeviceName, &devMode, 0,
						CDS_TEST, 0);
					if (result != DISP_CHANGE_SUCCESSFUL)

					displayModes.push_back(DisplayMode(devMode.dmPelsWidth, devMode.dmPelsHeight,
						devMode.dmDisplayFrequency, devMode.dmBitsPerPel, devMode));


		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?
[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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!