473,394 Members | 1,878 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Call api EnumDisplaySettings error

MSDN:
BOOL EnumDisplaySettings(
LPCTSTR lpszDeviceName, // display device
DWORD iModeNum, // graphics mode
LPDEVMODE lpDevMode // graphics mode settings
);

typedef struct _devicemode {
BCHAR dmDeviceName[CCHDEVICENAME];
WORD dmSpecVersion;
WORD dmDriverVersion;
WORD dmSize;
WORD dmDriverExtra;
DWORD dmFields;
union {
struct {
short dmOrientation;
short dmPaperSize;
short dmPaperLength;
short dmPaperWidth;
short dmScale;
short dmCopies;
short dmDefaultSource;
short dmPrintQuality;
};
POINTL dmPosition;
DWORD dmDisplayOrientation;
DWORD dmDisplayFixedOutput;
};

short dmColor;
short dmDuplex;
short dmYResolution;
short dmTTOption;
short dmCollate;
BYTE dmFormName[CCHFORMNAME];
WORD dmLogPixels;
DWORD dmBitsPerPel;
DWORD dmPelsWidth;
DWORD dmPelsHeight;
union {
DWORD dmDisplayFlags;
DWORD dmNup;
}
DWORD dmDisplayFrequency;
#if(WINVER >= 0x0400)
DWORD dmICMMethod;
DWORD dmICMIntent;
DWORD dmMediaType;
DWORD dmDitherType;
DWORD dmReserved1;
DWORD dmReserved2;
#if (WINVER >= 0x0500) || (_WIN32_WINNT >= 0x0400)
DWORD dmPanningWidth;
DWORD dmPanningHeight;
#endif
#endif /* WINVER >= 0x0400 */
} DEVMODE;

I Have this C# code:

[DllImport("user32.dll",
EntryPoint="EnumDisplaySettingsA")]
public static extern bool EnumDisplaySettings (
string lpszDeviceName,
Int32 iModeNum,
ref DEVMODE lpDevMode);

[StructLayout(LayoutKind.Sequential)]
public struct DEVMODE
{
//[ MarshalAs( UnmanagedType.LPStr)]
public string dmDeviceName;
public int dmSpecVersion;
public int dmDriverVersion;
public int dmSize;
public int dmDriverExtra;
public int dmFields;
public int dmOrientation;
public int dmPaperSize;
public int dmPaperLength;
public int dmPaperWidth;
public int dmScale;
public int dmCopies;
public int dmDefaultSource;
public int dmPrintQuality;
public int dmColor;
public int dmDuplex;
public int dmYResolution;
public int dmTTOption;
public int dmCollate;
//[ MarshalAs( UnmanagedType.LPStr)]
public string dmFormName;
public int dmUnusedPadding;
public int dmBitsPerPel;
public int dmPelsWidth;
public int dmPelsHeight;
public int dmDisplayFlags;
public int dmDisplayFrequency;
}

private void button1_Click(object sender,
System.EventArgs e)
{
DEVMODE DevM=new DEVMODE();
bool mybool;
mybool=EnumDisplaySettings("", 0,ref DevM);
MessageBox.Show(result.ToString()
+DevM.dmPelsWidth.ToString()+DevM.dmPelsHeight.ToS tring
());

}
But the MessageBox return mybool=false!!
I don't know where I make mistake???

Nov 15 '05 #1
6 4752
[DllImport("user32.dll",
EntryPoint="EnumDisplaySettingsA")]
Change this to

[DllImport("user32.dll", CharSet=CharSet.Auto)]

[StructLayout(LayoutKind.Sequential)]
public struct DEVMODE
{
//[ MarshalAs( UnmanagedType.LPStr)]
public string dmDeviceName;
public int dmSpecVersion;
public int dmDriverVersion;
public int dmSize;
public int dmDriverExtra;
public int dmFields;
public int dmOrientation;
public int dmPaperSize;
public int dmPaperLength;
public int dmPaperWidth;
public int dmScale;
public int dmCopies;
public int dmDefaultSource;
public int dmPrintQuality;
public int dmColor;
public int dmDuplex;
public int dmYResolution;
public int dmTTOption;
public int dmCollate;
//[ MarshalAs( UnmanagedType.LPStr)]
public string dmFormName;
public int dmUnusedPadding;
public int dmBitsPerPel;
public int dmPelsWidth;
public int dmPelsHeight;
public int dmDisplayFlags;
public int dmDisplayFrequency;
}
Make that

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
public struct DEVMODE
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=32)]
public string dmDeviceName;
public short dmSpecVersion;
public short dmDriverVersion;
public short dmSize;
public short dmDriverExtra;
public int 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;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=32)]
public string dmFormName;
public short dmLogPixels;
public int dmBitsPerPel;
public int dmPelsWidth;
public int dmPelsHeight;
public int dmDisplayFlags;
public int dmDisplayFrequency;
}

private void button1_Click(object sender,
System.EventArgs e)
{ DEVMODE DevM=new DEVMODE();
bool mybool;
mybool=EnumDisplaySettings("", 0,ref DevM);


"" is not the same as NULL if that was what you intended to pass as
the first parameter. Use null instead.

You must also set the DevM.dmSize member before the call, with

DevM.dmSize = (short)Marshal.SizeOf(typeof(DEVMODE));

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 15 '05 #2


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #3
thank your very much!
now i can get mybool=true!
but,whatever my screen set is,the "dmPelsWidth " always is 320,and the
"dmPelsHeight" always is 200,why??

and,how to use ChangeDisplaySettings,is that correct:

[DllImport("user32.dll",CharSet=CharSet.Auto)]
private static extern long ChangeDisplaySettings(ref DEVMODE
lpDevMode,int dwflags);

DevM.dmPelsWidth = 800;
DevM.dmPelsHeight = 600;
long result=ChangeDisplaySettings(ref DevM, 0);

thank you !!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #4
thank you very much!
now i can get mybool=true!
but whatever my screen set is ,the "dmPelsWidth" always is 320,and the
"dmPelsHeight" always is 200,why???

and ,how to use ChangeDisplaySettings,is that correct:

[DllImport("user32.dll",CharSet=CharSet.Auto)]
private static extern long ChangeDisplaySettings(ref DEVMODE
lpDevMode,int dwflags);

DEVMODE DevM=new DEVMODE();
DevM.dmSize = (short)Marshal.SizeOf(typeof(DEVMODE));
bool mybool;
mybool=EnumDisplaySettings(null,0,ref DevM);
MessageBox.Show(mybool.ToString()+DevM.dmPelsWidth .ToString()+","+DevM.d
mPelsHeight.ToString());
DevM.dmPelsWidth = 800;
DevM.dmPelsHeight = 600;
long result=ChangeDisplaySettings(ref DevM, 0);

after excute it ,my screen is change to 800*600,but the color set is
change to 8bit,it isn't my excepted,i don't want to change my color set
,how can i do ,thank you!!
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #5
thank you very much!
now i can get mybool=true!
but whatever my screen set is ,the "dmPelsWidth" always is 320,and the
"dmPelsHeight" always is 200,why???

and ,how to use ChangeDisplaySettings,is that correct:

[DllImport("user32.dll",CharSet=CharSet.Auto)]
private static extern long ChangeDisplaySettings(ref DEVMODE
lpDevMode,int dwflags);

DEVMODE DevM=new DEVMODE();
DevM.dmSize = (short)Marshal.SizeOf(typeof(DEVMODE));
bool mybool;
mybool=EnumDisplaySettings(null,0,ref DevM);
MessageBox.Show(mybool.ToString()+DevM.dmPelsWidth .ToString()+","+DevM.d
mPelsHeight.ToString());
DevM.dmPelsWidth = 800;
DevM.dmPelsHeight = 600;
long result=ChangeDisplaySettings(ref DevM, 0);

after excute it ,my screen is change to 800*600,but the color set is
change to 8bit,it isn't my excepted,i don't want to change my color set
,how can i do ,thank you!!


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #6
thank you very much!
now i can get mybool=true!
but whatever my screen set is ,the "dmPelsWidth" always is 320,and the
"dmPelsHeight" always is 200,why???

and ,how to use ChangeDisplaySettings,is that correct:

[DllImport("user32.dll",CharSet=CharSet.Auto)]
private static extern long ChangeDisplaySettings(ref DEVMODE
lpDevMode,int dwflags);

DEVMODE DevM=new DEVMODE();
DevM.dmSize = (short)Marshal.SizeOf(typeof(DEVMODE));
bool mybool;
mybool=EnumDisplaySettings(null,0,ref DevM);
MessageBox.Show(mybool.ToString()+DevM.dmPelsWidth .ToString()+","+DevM.d
mPelsHeight.ToString());
DevM.dmPelsWidth = 800;
DevM.dmPelsHeight = 600;
long result=ChangeDisplaySettings(ref DevM, 0);

after excute it ,my screen is change to 800*600,but the color set is
change to 8bit,it isn't my excepted,i don't want to change my color set
,how can i do ,thank you!!
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Dario | last post by:
This is a technical C++ post regarding the Microsoft runtime error R6025 Pure Virtual Function Call that sometime occurs in programs compiled with Microsoft Visual C++ 6.0. Please consider the...
0
by: Eugene Safrankow | last post by:
Hello All! I've encountered with the error when I call a method of dependency library (written in managed VC++) from Smart Client placed on a web page. In general, I make a call to the Windows...
6
by: Colin Young | last post by:
I am creating some code that runs in Excel using VSTO. I am trying to get some xml from a webservice, using the following code: GBWPipeline.PipelineService pipeline = new...
0
by: Dave Sisk | last post by:
I've created a system or external trigger on an AS/400 file a.k.a DB2 table. (Note this is an external trigger defined with the ADDPFTRG CL command, not a SQL trigger defined with the CREATE...
5
by: Kurt Van Campenhout | last post by:
Hi, I am trying to get/set Terminal server information in the active directory on a windows 2000 domain. Since the ADSI calls for TS don't work until W2K3, I need to do it myself. I'm fairly...
3
by: Mark Snyder | last post by:
I want to call EnumDisplaySettings from a VB.Net project. Is there simply no way to do this? Mark
13
by: Larry Menard | last post by:
Test code: $dbconn = odbc_connect($dbname, $username, $password); $path = "C:\Temp\myJar.jar"; $statement = "CALL SQLJ.INSTALL_JAR('file://$path', 'myJarId')"; $result = odbc_exec($dbconn,...
6
by: alho | last post by:
The web service is called by a program running on pocket pc. When to call the web service, the first call is still ok, but for the second or later calls, it will throw "403 Forbidden" WebException....
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.