public void Initialise() { IntPtr parsedData; HidCaps caps; this.Handle = KFile.CreateFile(Path, KFile.EFileAccess.GenericRead | KFile.EFileAccess.GenericWrite, 0, IntPtr.Zero, KFile.ECreationDisposition.OpenExisting, KFile.EFileAttributes.Overlapped, IntPtr.Zero); if (Handle == null || Handle.IsInvalid) { Handle = null; Kernel.Error.GetLastError(); } if (!HID.HID.HidD_GetPreparsedData(Handle, out parsedData)) { Kernel.Error.GetLastError(); } try { if ((uint)HID.Structures.ntStatus.HIDP_STATUS_SUCCESS != HID.HID.HidP_GetCaps(parsedData, out caps)) { Kernel.Error.GetLastError(); } HidCap = caps; File = new System.IO.FileStream(Handle, System.IO.FileAccess.Read | System.IO.FileAccess.Write, HidCap.InputReportByteLength, true); BeginAsyncRead(); } catch (Exception ex) { throw ex; } finally { HID.HID.HidD_FreePreparsedData(ref parsedData); } }
/// <summary> /// Disposer called by both dispose and finalise /// </summary> /// <param name="bDisposing">True if disposing</param> protected virtual void Dispose(bool bDisposing) { try { if (bDisposing) // if we are disposing, need to close the managed resources { if (File != null) { File.Close(); File = null; } } if (Handle != null) // Dispose and finalize, get rid of unmanaged resources { KFile.CloseHandle(Handle); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }