Skip to content

Commit

Permalink
Put more in to the error message
Browse files Browse the repository at this point in the history
  • Loading branch information
www committed Jul 28, 2019
1 parent 398f725 commit e268db3
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Hid.Net/Windows/WindowsHidDeviceFactory.cs
@@ -1,4 +1,5 @@
using Device.Net;
using Device.Net.Exceptions;
using Device.Net.Windows;
using Microsoft.Win32.SafeHandles;
using System;
Expand All @@ -17,8 +18,14 @@ protected override ConnectedDeviceDefinition GetDeviceDefinition(string deviceId
{
try
{
using (var safeFileHandle = APICalls.CreateFile(deviceId, APICalls.GenericRead | APICalls.GenericWrite, APICalls.FileShareRead | APICalls.FileShareWrite, IntPtr.Zero, APICalls.OpenExisting, 0, IntPtr.Zero))
const uint desiredAccess = APICalls.GenericRead | APICalls.GenericWrite;
const uint shareMode = APICalls.FileShareRead | APICalls.FileShareWrite;
const uint creationDisposition = APICalls.OpenExisting;

using (var safeFileHandle = APICalls.CreateFile(deviceId, desiredAccess, shareMode, IntPtr.Zero, creationDisposition, 0, IntPtr.Zero))
{
if (safeFileHandle.IsInvalid) throw new DeviceException($"CreateFile call with Id of {deviceId} failed. Desired Access: {desiredAccess} (GenericRead / GenericWrite). Share mode: {shareMode} (FileShareRead / FileShareWrite). Creation Disposition: {creationDisposition} (OpenExisting)");

return GetDeviceDefinition(deviceId, safeFileHandle);
}
}
Expand Down

0 comments on commit e268db3

Please sign in to comment.