Jump to content

Recommended Posts

Posted

I am trying to make my own multi-monitor resolution changer. (yes, there are already examples of this.) I am trying to better understand what is going on here.

When I look up the Microsoft TechNet info for these functions I see this:

EnumDisplaySettings function (Windows)

http://msdn.microsoft.com/en-us/library/windows/desktop/dd162611%28v=vs.85%29.aspx

Which says it needs a DevMode struct, described here:

DEVMODE structure (Windows)

http://msdn.microsoft.com/en-us/library/windows/desktop/dd183565%28v=vs.85%29.aspx

Okay, that DevMode struct is huge, many many lines.

But when I search the forums for examples of people getting the screen resolutions, their DevMode struct is tiny. It looks nothing like that:

Local $DEVMODE = DllStructCreate("byte[32];int[10];byte[32];int[6]")

Local $DEVMODE = DllStructCreate("byte[32];int[10];byte[32];int[6]")

I am not a DLLCall expert at all, but it is mysterious to me how Windows knows to put the right data in the right spot in that tiny struct that doesn't look anything like the proper struct in the Microsoft specifications.

Posted

As far as windows is constant, that struct is a block of memory of a known size. It stores the data at a given offset in the struct, which is hard coded at compile time.

Local $tFirst = DllStructCreate("int Foo; int Bar; int Meh")
DllStructSetData($tFirst, "Foo", 123)
DllStructSetData($tFirst, "Bar", 456)
DllStructSetData($tFirst, "Meh", 789)

ConsoleWrite("Before: " & @LF)
ConsoleWrite(@TAB & "Foo: " & DllStructGetData($tFirst, "Foo") & @LF)
ConsoleWrite(@TAB & "Bar: " & DllStructGetData($tFirst, "Bar") & @LF)
ConsoleWrite(@TAB & "Meh: " & DllStructGetData($tFirst, "Meh") & @LF)

; Using the 2nd parameter of DllStructCreate, the structures now overlap
Local $tSecond = DllStructCreate("int Meh", DllStructGetPtr($tFirst) + 8)

DllStructSetData($tSecond, "Meh", 987)

ConsoleWrite("After: " & @LF)
ConsoleWrite(@TAB & "Foo: " & DllStructGetData($tFirst, "Foo") & @LF)
ConsoleWrite(@TAB & "Bar: " & DllStructGetData($tFirst, "Bar") & @LF)
ConsoleWrite(@TAB & "Meh: " & DllStructGetData($tFirst, "Meh") & @LF)

However, by my maths those structs are only 128 bytes, and the one on msdn is 220. Don't suppose that really matters as long as you set dmSize.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...