PC Review


Reply
Thread Tools Rate Thread

ChangeDisplaySettingsEx Grrrrrrrrrrrrrrrrr!!

 
 
Franky
Guest
Posts: n/a
 
      20th Feb 2004
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!!!!!



 
Reply With Quote
 
 
 
 
Paul G. Tobey [eMVP]
Guest
Posts: n/a
 
      20th Feb 2004
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.

"Franky" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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!!!!!
>
>
>



 
Reply With Quote
 
Alex Feinman [MVP]
Guest
Posts: n/a
 
      20th Feb 2004
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...essManager.asp



"Franky" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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!!!!!
>
>
>



 
Reply With Quote
 
Franky
Guest
Posts: n/a
 
      23rd Feb 2004
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 Removed)



"Alex Feinman [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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...essManager.asp
>
>
>
> "Franky" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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!!!!!
> >
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Grrrrrrrrrrrrrrrrr!!! =?Utf-8?B?R3dlbiBI?= Microsoft Access Form Coding 7 2nd Nov 2006 07:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:42 AM.