R
Randy Beckwith
Has anyone successfully used EnumDisplayDevices from C# through the
compact framework?
I keep getting a return code of 0 and a GetLastError value of 87. This
is what I'm doing:
// My wrapper for the Win32 func below
public static int EnumDisplayDevices( ref string DeviceName,
ref string DeviceString,
ref string DeviceID,
ref string DeviceKey,
ref int LastError
)
{
int CB_LEN = Marshal.SizeOf(typeof(int)) ;
int NAME_START = CB_LEN ;
int NAME_LEN = Marshal.SizeOf(typeof(char)) * 32 ;
int STRING_START = NAME_START + NAME_LEN ;
int STRING_LEN = Marshal.SizeOf(typeof(char)) * 128 ;
int FLAGS_START = STRING_START + STRING_LEN ;
int FLAGS_LEN = Marshal.SizeOf(typeof(int)) ;
int ID_START = FLAGS_START + FLAGS_LEN ;
int ID_LEN = STRING_LEN ;
int KEY_START = ID_START + ID_LEN;
int KEY_LEN = STRING_LEN ;
byte[] dd = new byte[KEY_START + KEY_LEN] ;
byte[] buint = BitConverter.GetBytes(dd.Length);
Buffer.BlockCopy(buint, 0, dd, 0, buint.Length);
int result = EnumDisplayDevices(null, 0, ref dd, 0 ) ;
LastError = (int ) GetLastError() ;
DeviceName = UnicodeEncoding.Unicode.GetString( dd, NAME_START,
NAME_LEN) ;
DeviceString = UnicodeEncoding.Unicode.GetString( dd,
STRING_START, STRING_LEN) ;
DeviceID = UnicodeEncoding.Unicode.GetString( dd, ID_START,
ID_LEN) ;
DeviceKey = UnicodeEncoding.Unicode.GetString( dd, KEY_START,
KEY_LEN) ;
return result ;
}//EnumDisplayDevices
// Win32 declaration
[DllImport("Coredll.dll")]
public static extern int EnumDisplayDevices( String lpDevice,
int iDevNum,
ref byte[]
lpDisplayDevice,
int dwFlags
);
Thanks for any advice.
Randy Beckwith
compact framework?
I keep getting a return code of 0 and a GetLastError value of 87. This
is what I'm doing:
// My wrapper for the Win32 func below
public static int EnumDisplayDevices( ref string DeviceName,
ref string DeviceString,
ref string DeviceID,
ref string DeviceKey,
ref int LastError
)
{
int CB_LEN = Marshal.SizeOf(typeof(int)) ;
int NAME_START = CB_LEN ;
int NAME_LEN = Marshal.SizeOf(typeof(char)) * 32 ;
int STRING_START = NAME_START + NAME_LEN ;
int STRING_LEN = Marshal.SizeOf(typeof(char)) * 128 ;
int FLAGS_START = STRING_START + STRING_LEN ;
int FLAGS_LEN = Marshal.SizeOf(typeof(int)) ;
int ID_START = FLAGS_START + FLAGS_LEN ;
int ID_LEN = STRING_LEN ;
int KEY_START = ID_START + ID_LEN;
int KEY_LEN = STRING_LEN ;
byte[] dd = new byte[KEY_START + KEY_LEN] ;
byte[] buint = BitConverter.GetBytes(dd.Length);
Buffer.BlockCopy(buint, 0, dd, 0, buint.Length);
int result = EnumDisplayDevices(null, 0, ref dd, 0 ) ;
LastError = (int ) GetLastError() ;
DeviceName = UnicodeEncoding.Unicode.GetString( dd, NAME_START,
NAME_LEN) ;
DeviceString = UnicodeEncoding.Unicode.GetString( dd,
STRING_START, STRING_LEN) ;
DeviceID = UnicodeEncoding.Unicode.GetString( dd, ID_START,
ID_LEN) ;
DeviceKey = UnicodeEncoding.Unicode.GetString( dd, KEY_START,
KEY_LEN) ;
return result ;
}//EnumDisplayDevices
// Win32 declaration
[DllImport("Coredll.dll")]
public static extern int EnumDisplayDevices( String lpDevice,
int iDevNum,
ref byte[]
lpDisplayDevice,
int dwFlags
);
Thanks for any advice.
Randy Beckwith