/* close device */ private static void Close(IntPtr handle) { /* try to close handle */ if (Native.CloseHandle(handle) == false) { /* fail! */ throw new Win32Exception(); } }
/* close hid device */ public void Close() { /* deal with file stream */ if (_fileStream != null) { /* close stream */ _fileStream.Close(); /* get rid of object */ _fileStream = null; } /* close handle */ Native.CloseHandle(handle); }
/* dispose */ public void Dispose() { try { /* deal with file stream */ if (_fileStream != null) { /* close stream */ _fileStream.Close(); /* get rid of object */ _fileStream = null; /* close handle */ if (handle != IntPtr.Zero) { Native.CloseHandle(handle); } } } catch (Exception ex) { handle = IntPtr.Zero; } }