private void Open() { try { Handle = IoCtl.CreateFile( @"\\.\PHYSICALDRIVE" + DiskId.ToString(), IoCtl.GENERIC_READ, 0, IntPtr.Zero, IoCtl.OPEN_EXISTING, 0, IntPtr.Zero); if (Handle.IsInvalid) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } } catch (Exception ex) { throw ex; } }
unsafe static void Main(string[] args) { if (args.Length < 1) { ShowHelp(); return; } // Find DFR Device var instancePath = DfrDeviceDiscovery.FindDfrDevice(); if (string.IsNullOrEmpty(instancePath)) { System.Console.WriteLine("No DFR device found"); return; } System.Console.WriteLine($"Found DFR instance {instancePath}"); var deviceHandle = IoCtl.CreateFile( instancePath, FileAccess.Write, FileShare.None, IntPtr.Zero, FileMode.Open, FileOptions.None, IntPtr.Zero ); if (deviceHandle == IntPtr.Zero) { System.Console.WriteLine("Failed to open DFR device"); return; } bool bResult = false; bool commandFound = true; switch (args[0].ToLowerInvariant()) { case "clear": bResult = ClearDfrFrameBuffer(deviceHandle); break; case "draw": ushort x = 0, y = 0; // Optional X if (args.Length >= 3) { if (ushort.TryParse(args[2], out ushort tX)) { x = tX; } } // Optional Y if (args.Length >= 4) { if (ushort.TryParse(args[3], out ushort tY)) { y = tY; } } bResult = DrawBitmap(deviceHandle, args[1], x, y); break; default: ShowHelp(); commandFound = false; break; } if (!bResult && commandFound) { System.Console.WriteLine("Failed to run the command"); } IoCtl.CloseHandle(deviceHandle); }