c# - SetupDiGetDeviceRegistryProperty fails with ERROR_INVALID_DATA -
i'm trying display names appear in "screen resolution" window (win8.1 x64).
first tried enumdisplaydevices
var deviceinfo = new display_devicew(); uint = 0; while (true) { if (!nativemethods.enumdisplaydevices(null, i++, deviceinfo, 0)) { break; } printdeviceinfo(deviceinfo); nativemethods.enumdisplaydevices(deviceinfo.devicename, 0, deviceinfo, edd_get_device_interface_name); printdeviceinfo(deviceinfo); }
the sec phone call enumdisplaydevices
(with edd_get_device_interface_name
) indeed yielded display name appears main display (in display_devicew.devicestring). hdmi-connected tv field contains generic pnp monitor, instead of samsung appears in "screen resolution" window. perhaps fact it's connected hdmi somehow related?
i tried setup api
var hdevinfo = nativemethods.setupdigetclassdevs(ref guid_devinterface_monitor, null, intptr.zero, digcf_deviceinterface | digcf_present); if (hdevinfo == invalid_handle_value) return; var spdeviceinterfacedata = new sp_device_interface_data(); uint memberindex = 0; while (true) { bool success = nativemethods.setupdienumdeviceinterfaces(hdevinfo, null, ref guid_devinterface_monitor, memberindex++, spdeviceinterfacedata); if (!success) { break; } printinterfacedata(spdeviceinterfacedata); uint requiredsize; var devinfodata = new sp_devinfo_data(); nativemethods.setupdigetdeviceinterfacedetail(hdevinfo, spdeviceinterfacedata, intptr.zero, 0, out requiredsize, devinfodata); printdevinfodata(devinfodata); var interfacedetail = marshal.allochglobal((int)requiredsize); var cbsize = (marshal.sizeof(typeof(uint)) + marshal.systemdefaultcharsize); marshal.writeint32(interfacedetail, 0, cbsize); nativemethods.setupdigetdeviceinterfacedetail(hdevinfo, spdeviceinterfacedata, interfacedetail, requiredsize, intptr.zero, null); var dynamictype = getdeviceinterfacedetaildatatype(requiredsize); var interfacedetailstruct = marshal.ptrtostructure(interfacedetail, dynamictype); marshal.freehglobal(interfacedetail); printinterfacedetail(interfacedetailstruct); uint propertyregdatatype; nativemethods.setupdigetdeviceregistryproperty(hdevinfo, devinfodata, spdrp_friendlyname, out propertyregdatatype, null, 0, out requiredsize); console.writeline(marshal.getlastwin32error()); }
looking @ returned values different methods, seems work, lastly phone call setupdigetdeviceregistryproperty
fails error_invalid_data
(that is, method returns false , getlastwin32error
yields 13
). according docs, means the requested property not exist device or if property info not valid.
i looped on possible spdrp
values (0-24) , result in same failure. clarify, expected method fail, error_insufficient_buffer
, having requiredsize
set (the latter retains previous value, unmanaged code doesn't alter it).
here's signature setupdigetdeviceregistryproperty
(all other methods work expected):
[structlayout(layoutkind.sequential)] public class sp_devinfo_data { public uint cbsize = (uint) marshal.sizeof(typeof (sp_devinfo_data)); public guid classguid; public uint devinst; public intptr reserved; } [dllimport("setupapi.dll", charset = charset.auto, setlasterror = true)] public static extern bool setupdigetdeviceregistryproperty( intptr deviceinfoset, sp_devinfo_data deviceinfodata, uint property, out uint propertyregdatatype, byte[] propertybuffer, uint propertybuffersize, out uint requiredsize);
looks i'm looking impossible:
there not supported way figour out ids referred programmatically. never design goal provide way applications label monitors same ids screen resolution command panel uses
c# winapi interop
No comments:
Post a Comment