private static void OnHotPlug(KHOT_HANDLE hotHandle, KLST_DEVINFO_HANDLE deviceInfo, KLST_SYNC_FLAG plugType) { string plugText; int totalPluggedDeviceCount = (int) hotHandle.GetContext().ToInt64(); if (totalPluggedDeviceCount == int.MaxValue) { Console.WriteLine("OnHotPlug is being called for the first time on handle:{0}", hotHandle.Pointer); totalPluggedDeviceCount = 0; } switch (plugType) { case KLST_SYNC_FLAG.ADDED: plugText = "Arrival"; totalPluggedDeviceCount++; break; case KLST_SYNC_FLAG.REMOVED: plugText = "Removal"; totalPluggedDeviceCount--; break; default: throw new ArgumentOutOfRangeException("plugType"); } hotHandle.SetContext(new IntPtr(totalPluggedDeviceCount)); Console.WriteLine("\n[OnHotPlug] Device {0}:{1} \n", plugText, deviceInfo); Console.WriteLine("Total Plugged Device Count: {0}", totalPluggedDeviceCount); }
private void OnHotPlugInvoked(KHOT_HANDLE hotHandle, KLST_DEVINFO_HANDLE deviceInfo, KLST_SYNC_FLAG plugType) { string symbolicLink = deviceInfo.SymbolicLink; switch (plugType) { case KLST_SYNC_FLAG.ADDED: int iRow = dgvDevices.Rows.Add(new object[] {symbolicLink, deviceInfo.DeviceDesc, deviceInfo.DeviceID}); dgvDevices.Rows[iRow].Cells[1].ToolTipText = deviceInfo.ToString(); dgvDevices.Rows[iRow].Cells[2].ToolTipText = deviceInfo.Common.ToString(); break; case KLST_SYNC_FLAG.REMOVED: foreach (DataGridViewRow row in dgvDevices.Rows) { if (row.Cells[0].Value as string != symbolicLink) continue; dgvDevices.Rows.Remove(row); break; } break; default: throw new ArgumentOutOfRangeException("plugType"); } }
protected virtual void Dispose(bool disposing) { if (!mbDisposed) { if (mHandleStruct.Pointer != IntPtr.Zero) { AllKFunctions.HotK_Free(mHandleStruct); Debug.Print("{0} Dispose: Freed Handle:{1:X16}h Explicit:{2}", GetType().Name, mHandleStruct.Pointer.ToInt64(), disposing); } else Debug.Print("{0} Dispose: [WARNING] Handle is null", GetType().Name); mHandleStruct = new KHOT_HANDLE(IntPtr.Zero); mbDisposed = true; } }
protected override void WndProc(ref Message m) { /* When using the HotK UserHwnd and UserMsg, the add/remove events are seperated into to different messages. * Removal = UserMsg + 0 * Arrival = UserMsg + 1 */ if (m.Msg == WM_USER_HOT_REMOVAL || m.Msg == WM_USER_HOT_ARRIVAL) { KHOT_HANDLE hotHandle = new KHOT_HANDLE(m.WParam); KLST_DEVINFO_HANDLE deviceInfo = new KLST_DEVINFO_HANDLE(m.LParam); KLST_SYNC_FLAG plugType = (m.Msg == WM_USER_HOT_REMOVAL) ? KLST_SYNC_FLAG.REMOVED : KLST_SYNC_FLAG.ADDED; OnHotPlugInvoked(hotHandle, deviceInfo, plugType); return; } base.WndProc(ref m); }