1

I'm trying to change the screen resolution in C# (there are already several questions in regards to that on StackOverflow, like this one). I'm following the links that are given with this question, and I'm trying to implement the solution using the ChangeDisplayFunction.

This ChangeDisplayFunction as a field called DEVMODE, but when I use it, it always gives me the error:

The type or namespace name 'DEVMODE' could not be found.

I'm not even doing anything with it. I only initialized the functions from the user32.dll library from which it comes. I declared everything like this:

[DllImport("user32.dll")]
public static extern int ChangeDisplaySettings( ref DEVMODE devMode, int flags);

I'm rather new to C# so I don't know which namespace I should use to resolve this. I've tried googling it and I looked to the documentation from Microsoft but all of the namespaces it mentioned worked.

marijnr
  • 121
  • 3
  • 4
    `DEVMODE` is a Type you need to create, See https://www.pinvoke.net/default.aspx/Structures.DEVMODE – Alex K. Aug 08 '18 at 11:50
  • Creating a type as described in the link creates even more unknown types (namely DM and POINTL). In any case, it seems strange tat a library knows this type, but you have to define it outside of the library to use it. – marijnr Aug 08 '18 at 12:03
  • They are also Types that need to be created, use the same site to look them up. – Alex K. Aug 08 '18 at 12:07
  • *"a library knows this type"* - This would be true if you were using a .Net Assembly or COM DLL but you are using a different mechanism (pinvoke) to call user32.dll which is a DLL that simply allows you to call a function it exports, there is no exchange of type information when you do that. – Alex K. Aug 08 '18 at 12:09
  • it now gives me the following error message when running: System.TypeLoadException: Could not load type 'DEVMODE' from assembly ... , Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' because it contains an object field at offset 70 that is incorrectly aligned or overlapped by a non-object field. – marijnr Aug 08 '18 at 12:27

0 Answers0