OT? EnumDisplaySettings()

Hello!

Im having some troble getting the current display setting. I’ve looked everywhere, but this should be the way:

DEVMODE DMsaved;
DMsaved.dmSize = sizeof(DEVMODE);
EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS, &DMsaved);

BoundsChecker says:
Static memory overrun
Copying 156 bytes to rnvid_DMsaved
Starting offset: 0, destination size: 148 bytes

My program crashes later on, but I dont know if its related to this error.

Can anybody find anything wrong with this code?

Thanks!
/Fredrik Olsson

A buffer overrun will cause large problems at some time. To be sure that line really is the source of your crash, remove it (and fill the devmode structure yourself with some values) and see what happens. I don’t see anything wrong with that piece of code.

When i fill the DMsaved struct with 1’s nothing goes wrong.

memset(&DMsaved, 1, sizeof(DEVMODE))

In MSDN it says this about the lpDevMode parameter of EnumDisplaySettings():

[out] Pointer to a DEVMODE structure into which the function stores information about the specified graphics mode. Before calling EnumDisplaySettings, 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.

Try setting the dmDriverExtra member to 0.

Just as an extra note, it’s usually a good idea to zero out structs used in the Win32 API before setting values in them by using something like ZeroMemory or memset.

[This message has been edited by Deiussum (edited 09-11-2002).]

dmDriverExtra is zero.
I tried clearing the struct to, but it doesn’t help.

i think you have to fill out the devMode.dmfields
with the your desired flags like DM_PELSWIDTH etc… to obtain the value that is stored last in the registry for that setting
CU