ChangeDisplaySettingsEx Grrrrrrrrrrrrrrrrr!!

F

Franky

I try to change for landscape orientation.
i use the ChangeDisplaySettingsEx function.
----
[DllImport("coredll.dll", EntryPoint="ChangeDisplaySettingsEx",
SetLastError=true)]
internal static extern long ChangeDisplaySettingsEx(
string lpszDeviceName,
out DEVMODE lpDevMode,
IntPtr hwnd,
int dwflags,
IntPtr lParam);
---
my struct DEVMODE is
---
[StructLayout(LayoutKind.Sequential)]
public struct DEVMODE
{
string dmDeviceName;
public int dmSpecVersion;
public int dmDriverVersion;
public int dmSize;
public int dmDriverExtra;
public long dmFields;
public short dmOrientation;
public short dmPaperSize;
public short dmPaperLength;
public short dmPaperWidth;
public short dmScale;
public short dmCopies;
public short dmDefaultSource;
public short dmPrintQuality;
public short dmColor;
public short dmDuplex;
public short dmYResolution;
public short dmTTOption;
public short dmCollate;
public string dmFormName;
public int dmLogPixels;
public int dmBitsPerPel;
public int dmPelsWidth;
public int dmPelsHeight;
public int dmDisplayFlags;
public int dmDisplayFrequency;
public int dmDisplayOrientation;
}
---


I try different way... a got always a Unmanaged Exception!

Can someone HELP ME PLEASE!!!!!
 
P

Paul G. Tobey [eMVP]

Just a quick couple of questions before we dig into this:

1. Are you sure that your target device supports this?
2. Have you tried it from C/C++ to verify that sending the structure with
the data you want to send actually works?

Paul T.
 
A

Alex Feinman [MVP]

There are several problems with your PInvoke definition.
1) The function return value should be int not long. 32-bit is int and long
is 64 bit and is not supported for PInvoke
2) DEVMODE structure should be passed as ref not out
3) DEVMODE structure contains two embedded strings and as such cannot be
marshalled. You need to use byte array instead
Use technique described here:
http://msdn.microsoft.com/library/en-us/dnnetcomp/html/ProcessManager.asp
 
F

Franky

Wow ok it's a lot of work....
I start to convert the DEVMODE in C# class but they miss me a lot of
information...
How about the offset of each member? in the exemple is vary for the type
size! So how can I determine the correct size?


No body never make a warpper??

____________________
Franky
(e-mail address removed)



Alex Feinman said:
There are several problems with your PInvoke definition.
1) The function return value should be int not long. 32-bit is int and long
is 64 bit and is not supported for PInvoke
2) DEVMODE structure should be passed as ref not out
3) DEVMODE structure contains two embedded strings and as such cannot be
marshalled. You need to use byte array instead
Use technique described here:
http://msdn.microsoft.com/library/en-us/dnnetcomp/html/ProcessManager.asp



Franky said:
I try to change for landscape orientation.
i use the ChangeDisplaySettingsEx function.
----
[DllImport("coredll.dll", EntryPoint="ChangeDisplaySettingsEx",
SetLastError=true)]
internal static extern long ChangeDisplaySettingsEx(
string lpszDeviceName,
out DEVMODE lpDevMode,
IntPtr hwnd,
int dwflags,
IntPtr lParam);
---
my struct DEVMODE is
---
[StructLayout(LayoutKind.Sequential)]
public struct DEVMODE
{
string dmDeviceName;
public int dmSpecVersion;
public int dmDriverVersion;
public int dmSize;
public int dmDriverExtra;
public long dmFields;
public short dmOrientation;
public short dmPaperSize;
public short dmPaperLength;
public short dmPaperWidth;
public short dmScale;
public short dmCopies;
public short dmDefaultSource;
public short dmPrintQuality;
public short dmColor;
public short dmDuplex;
public short dmYResolution;
public short dmTTOption;
public short dmCollate;
public string dmFormName;
public int dmLogPixels;
public int dmBitsPerPel;
public int dmPelsWidth;
public int dmPelsHeight;
public int dmDisplayFlags;
public int dmDisplayFrequency;
public int dmDisplayOrientation;
}
---


I try different way... a got always a Unmanaged Exception!

Can someone HELP ME PLEASE!!!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top