473,386 Members | 1,754 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,386 software developers and data experts.

EnumDisplayDevices - second attempt

Hi, I posted this in m.p.d.f.interop but did not get any sensible response.
Maybe somebody will be able to point me to right direction here?

Hi,

I am having some issue with EnumDisplayDevices when called from C#.
When I use CharSet.Ansi (note - no unicode) for DISPLAY_DEVICE structure, I
get

0, DISPLAY1, raphics SuperSavage/IXC 1014, 1548305232,
VEN_5333&DEV_8C2E&SUBSYS_01FC1014&REV_05,
ISTRY\Machine\System\ControlSet001\Services\S3SSav age\Device0

1, DISPLAY3, eeting driver, 0, ,
ISTRY\Machine\System\ControlSet001\Services\mnmdd\ Device0

When I try to use unicode (CharSet.Auto) I get garbage in device name, key,
string etc.

Platform SDK help says that display_device structure strings must be
declared as WCHAR, which means unicode. Or not?

And why some strings are losing starting symbols?

Here is declaration I use

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]

public class DISPLAY {

public long cb=0;

[MarshalAs(UnmanagedType.ByValTStr,SizeConst=32)]

public string DeviceName=new String(' ',32);

[MarshalAs( UnmanagedType.ByValTStr, SizeConst=128)]

public string DeviceString=new String(' ',128);

public int StateFlags=0;

[MarshalAs( UnmanagedType.ByValTStr, SizeConst=128)]

public string DeviceID=new String(' ',128);

[MarshalAs( UnmanagedType.ByValTStr, SizeConst=128)]

public string DeviceKey=new String(' ',128);

}

[DllImport("user32.dll")]

extern static bool EnumDisplayDevices(IntPtr lpDevice,

int iDevNum,

[In,Out] DISPLAY lpDisplayDevice,

int dwFlags);

and here is how function is called:

DISPLAY d=new DISPLAY();

d.cb=Marshal.SizeOf(d);

int id=0;

int dwf=0;

while (EnumDisplayDevices(IntPtr.Zero, id, d, dwf)) {

Console.WriteLine(

String.Format("{0}, {1}, {2}, {3}, {4}, {5}",

id,

d.DeviceName,

d.DeviceString,

d.StateFlags,

d.DeviceID,

d.DeviceKey

)

);

id++;

d.cb=Marshal.SizeOf(d);

}

What is wrong here?

Anybody can help?

Thanks

Alex


Nov 16 '05 #1
2 5762
"AlexS" wrote :
Hi, I posted this in m.p.d.f.interop but did not get any sensible response. Maybe somebody will be able to point me to right direction here?
Lets try :)
I am having some issue with EnumDisplayDevices when called from C#.
When I use CharSet.Ansi (note - no unicode) for DISPLAY_DEVICE structure, I get

0, DISPLAY1, raphics SuperSavage/IXC 1014, 1548305232,
VEN_5333&DEV_8C2E&SUBSYS_01FC1014&REV_05,
ISTRY\Machine\System\ControlSet001\Services\S3SSav age\Device0

1, DISPLAY3, eeting driver, 0, ,
ISTRY\Machine\System\ControlSet001\Services\mnmdd\ Device0

Here is declaration I use

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]

public class DISPLAY {

public long cb=0;


Just write "int" instead of "long" here. That will do :)

--
Francois Beaussier
Fr******@3ie.org.remove
Nov 16 '05 #2
Thanks, Francois

Somehow I assumed that long is same as int in this case. My bad.

Alex

"Francois Beaussier" <Fr******@3ie.org.invalid> wrote in message
news:eU**************@TK2MSFTNGP12.phx.gbl...
"AlexS" wrote :
Hi, I posted this in m.p.d.f.interop but did not get any sensible response.
Maybe somebody will be able to point me to right direction here?


Lets try :)
I am having some issue with EnumDisplayDevices when called from C#.
When I use CharSet.Ansi (note - no unicode) for DISPLAY_DEVICE

structure, I
get

0, DISPLAY1, raphics SuperSavage/IXC 1014, 1548305232,
VEN_5333&DEV_8C2E&SUBSYS_01FC1014&REV_05,
ISTRY\Machine\System\ControlSet001\Services\S3SSav age\Device0

1, DISPLAY3, eeting driver, 0, ,
ISTRY\Machine\System\ControlSet001\Services\mnmdd\ Device0

Here is declaration I use

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]

public class DISPLAY {

public long cb=0;


Just write "int" instead of "long" here. That will do :)

--
Francois Beaussier
Fr******@3ie.org.remove

Nov 16 '05 #3

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

Similar topics

5
by: Tobiah | last post by:
What is the purpose of the second argument to super()? What is meant by the returning of an 'unbound' object when the argument is omitted. Also, when would I pass an object as the second...
12
by: Anna | last post by:
Hi all, I posted the same question this afternoon but my message isn't showing up, so I thought I'd give it another try.... in case you should see it later I apologize for posting the same...
31
by: Benno Bös | last post by:
If I use the following construct in the frame "main" for a link to an extern site: <A HREF="http://www.any.xy" TARGET="extern"> the Browser is creating the window "extern", loading the page...
0
by: Frederick Noronha \(FN\) | last post by:
---------- Forwarded message ---------- Solutions to Everyday User Interface and Programming Problems O'Reilly Releases "Access Cookbook, Second Edition" Sebastopol, CA--Neither reference book...
10
by: Sean Berry | last post by:
I need to find the second to last occurence of a "." in a string. Basically I am taking a URL like http://this.is.mydomin.com/path/to/file.txt and want to extract /path/to/file.txt I...
1
by: Jon Pope | last post by:
I've got an application that uses a Mutex to prevent multiple instances of the application from launching. This works great for me. However, what I would like to do is when a second attempt to...
4
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I make a 10 second delay? ----------------------------------------------------------------------- There...
28
by: galathaea | last post by:
On Mar 2, 11:29 pm, galath...@veawb.coop (galathaea) wrote: still being very naive about this whole crackpot / crank thing i accidentally let the engineer inside think too hard about this ...
8
blazedaces
by: blazedaces | last post by:
So I have a program below which writes an excel file with multiple sheets based on inputs of sheet names, data, cell types, etc. It uses Apache POI, which is currently the only thing I found...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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,...

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.