# HG changeset patch # User StephaneLenclud # Date 1441226147 -7200 # Node ID 703daa997f596a4bd36e99ae07ccf26d36560b3e # Parent 5ecbb2f57a16514d43eb868344957f490fa72636 v0.5.3.0 Publishing version with eject drive selection. Updating to newest SharpLibWin32. Adding ejection error checks. diff -r 5ecbb2f57a16 -r 703daa997f59 Server/MainForm.Hid.cs --- a/Server/MainForm.Hid.cs Wed Sep 02 19:50:34 2015 +0200 +++ b/Server/MainForm.Hid.cs Wed Sep 02 22:35:47 2015 +0200 @@ -8,6 +8,7 @@ using System.Runtime.InteropServices; using System.Windows.Forms; using Microsoft.Win32.SafeHandles; +using System.ComponentModel; // using Hid = SharpLib.Hid; using SharpLib.Win32; @@ -146,6 +147,16 @@ /// /// /// + /// + private void CheckLastError(string aPrefix) + { + string errorMessage = new Win32Exception(Marshal.GetLastWin32Error()).Message; + Debug.WriteLine(aPrefix + Marshal.GetLastWin32Error().ToString() + ": " + errorMessage); + } + + /// + /// + /// /// /// private IntPtr MarshalToPointer(object data) @@ -196,6 +207,8 @@ tries++; } + CheckLastError("Lock volume: "); + return success; } @@ -211,7 +224,9 @@ //Should not be needed but I'm not sure how to pass NULL in there. OVERLAPPED overlapped=new OVERLAPPED(); - return Function.DeviceIoControl(aVolume, Const.FSCTL_DISMOUNT_VOLUME, IntPtr.Zero, 0, IntPtr.Zero, 0, dwBytesReturned, ref overlapped); + bool res = Function.DeviceIoControl(aVolume, Const.FSCTL_DISMOUNT_VOLUME, IntPtr.Zero, 0, IntPtr.Zero, 0, dwBytesReturned, ref overlapped); + CheckLastError("Dismount volume: "); + return res; } @@ -234,7 +249,7 @@ IntPtr preventMediaRemovalParam = MarshalToPointer(preventMediaRemoval); bool result = Function.DeviceIoControl(aVolume, Const.IOCTL_STORAGE_MEDIA_REMOVAL, preventMediaRemovalParam, Convert.ToUInt32(Marshal.SizeOf(preventMediaRemoval)), IntPtr.Zero, 0, dwBytesReturned, ref overlapped); - + CheckLastError("Media removal: "); Marshal.FreeHGlobal(preventMediaRemovalParam); return result; @@ -252,7 +267,9 @@ //Should not be needed but I'm not sure how to pass NULL in there. OVERLAPPED overlapped=new OVERLAPPED(); - return Function.DeviceIoControl(aVolume, Const.IOCTL_STORAGE_EJECT_MEDIA, IntPtr.Zero, 0, IntPtr.Zero, 0, dwBytesReturned, ref overlapped); + bool res = Function.DeviceIoControl(aVolume, Const.IOCTL_STORAGE_EJECT_MEDIA, IntPtr.Zero, 0, IntPtr.Zero, 0, dwBytesReturned, ref overlapped); + CheckLastError("Media eject: "); + return res; } /// @@ -267,7 +284,9 @@ //Should not be needed but I'm not sure how to pass NULL in there. OVERLAPPED overlapped=new OVERLAPPED(); - return Function.DeviceIoControl(aVolume, Const.IOCTL_STORAGE_LOAD_MEDIA, IntPtr.Zero, 0, IntPtr.Zero, 0, dwBytesReturned, ref overlapped); + bool res = Function.DeviceIoControl(aVolume, Const.IOCTL_STORAGE_LOAD_MEDIA, IntPtr.Zero, 0, IntPtr.Zero, 0, dwBytesReturned, ref overlapped); + CheckLastError("Media load: "); + return res; } /// @@ -284,7 +303,7 @@ bool res = Function.DeviceIoControl(aVolume, Const.IOCTL_STORAGE_CHECK_VERIFY2, IntPtr.Zero, 0, IntPtr.Zero, 0, dwBytesReturned, ref overlapped); - Debug.WriteLine("Check Verify: " + Marshal.GetLastWin32Error().ToString()); + CheckLastError("Check verify: "); return res; } @@ -307,7 +326,7 @@ SafeFileHandle handle = OpenVolume(drive); if (handle.IsInvalid) { - Debug.WriteLine("ERROR: Failed to open volume."); + CheckLastError("ERROR: Failed to open volume: "); return; } @@ -317,7 +336,7 @@ if (PreventRemovalOfVolume(handle,false)) { - //StorageCheckVerify(handle); + StorageCheckVerify(handle); if (MediaEject(handle)) { diff -r 5ecbb2f57a16 -r 703daa997f59 Server/SharpDisplayManager.csproj --- a/Server/SharpDisplayManager.csproj Wed Sep 02 19:50:34 2015 +0200 +++ b/Server/SharpDisplayManager.csproj Wed Sep 02 22:35:47 2015 +0200 @@ -33,7 +33,7 @@ index.htm false 0 - 0.5.2.%2a + 0.5.3.%2a false true true @@ -121,7 +121,7 @@ False - ..\packages\SharpLibWin32.0.0.6\lib\net20\SharpLibWin32.dll + ..\packages\SharpLibWin32.0.0.7\lib\net20\SharpLibWin32.dll diff -r 5ecbb2f57a16 -r 703daa997f59 Server/packages.config --- a/Server/packages.config Wed Sep 02 19:50:34 2015 +0200 +++ b/Server/packages.config Wed Sep 02 22:35:47 2015 +0200 @@ -3,5 +3,5 @@ - + \ No newline at end of file