private void Initialize() { int lastError = ErrorHelpers.GetLastError(); Data[ErrorCodeKey] = lastError; Data[ErrorMessageKey] = ErrorHelpers.GetErrorMessage(lastError); }
protected override bool LoadValue(DeviceInfo deviceInfo, out DeviceRegistryPropertyType propertyType, out Api.Buffer buffer) { if (!SetupDi.GetDeviceRegistryProperty(deviceInfo, Key, out propertyType, out buffer)) { // Only "not found" errors are valid failures. var lastError = ErrorHelpers.GetLastError(); if (lastError == ErrorCode.NotFound) { return(false); } // Everything else is an unexpected failure. throw new DeviceManagerWindowsException("Unable to query device registry property."); } return(true); }
public IEnumerable <DeviceInfo> GetDevices() { for (var index = 0; ; ++index) { DeviceInfo deviceInfo; if (!SetupDi.EnumDeviceInfo(this, index, out deviceInfo)) { if (ErrorHelpers.GetLastError() != ErrorCode.NoMoreItems) { throw new DeviceManagerWindowsException("Unable to enumerate devices."); } yield break; } yield return(deviceInfo); } }