Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Handling the device change functionality for HID Devices

Handling the device change functionality for HID Devices

Scheduled Pinned Locked Moved C / C++ / MFC
question
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hariakuthota
    wrote on last edited by
    #1

    Hi all, In my application I want to handle the insert(plug in) and removal(plug out) of the devices so that i have to re enumerate and show the user present devices connected to the system.But my application is limited to re enumeration of HID devices only, so i want to handle the device change only for HID devices. I handled the WindProc() in which I used if(message == WM_DEVICECHANGE) but I am getting in to this loop for every device change but how can I check whether device change is for HID devices or not. Please suggest a right approach for this. Thanks in advance.

    S J 3 Replies Last reply
    0
    • H hariakuthota

      Hi all, In my application I want to handle the insert(plug in) and removal(plug out) of the devices so that i have to re enumerate and show the user present devices connected to the system.But my application is limited to re enumeration of HID devices only, so i want to handle the device change only for HID devices. I handled the WindProc() in which I used if(message == WM_DEVICECHANGE) but I am getting in to this loop for every device change but how can I check whether device change is for HID devices or not. Please suggest a right approach for this. Thanks in advance.

      S Offline
      S Offline
      Sarath C
      wrote on last edited by
      #2

      Registering for a device notification[^] You can check the details of the inserted device by interpreting the LPARAM received to WM_DEVICECHANGE[^] notification. Check documentation for details

      -Sarath. "Great hopes make everything great possible" - Benjamin Franklin

      My blog - Sharing My Thoughts

      1 Reply Last reply
      0
      • H hariakuthota

        Hi all, In my application I want to handle the insert(plug in) and removal(plug out) of the devices so that i have to re enumerate and show the user present devices connected to the system.But my application is limited to re enumeration of HID devices only, so i want to handle the device change only for HID devices. I handled the WindProc() in which I used if(message == WM_DEVICECHANGE) but I am getting in to this loop for every device change but how can I check whether device change is for HID devices or not. Please suggest a right approach for this. Thanks in advance.

        J Offline
        J Offline
        john alex prog
        wrote on last edited by
        #3

        Hi. I am sure you can help me. I want to write a program that just detect that a device has been changed. And in my program it is not concerned which device is changed. I have been trying for 15days but not able to handle windproc function. I am not getting any clue how to handle this function. Please send me a sample code. Please please please. I am getting really sick of this. Send me at john.alex.programmer@gmail.com. Please help me. PLZ PLZ PLZ PLZ PLZ.

        1 Reply Last reply
        0
        • H hariakuthota

          Hi all, In my application I want to handle the insert(plug in) and removal(plug out) of the devices so that i have to re enumerate and show the user present devices connected to the system.But my application is limited to re enumeration of HID devices only, so i want to handle the device change only for HID devices. I handled the WindProc() in which I used if(message == WM_DEVICECHANGE) but I am getting in to this loop for every device change but how can I check whether device change is for HID devices or not. Please suggest a right approach for this. Thanks in advance.

          J Offline
          J Offline
          john alex prog
          wrote on last edited by
          #4

          Hi. I am sure you can help me. I want to write a program that just detect that a device has been changed. And in my program it is not concerned which device is changed. I have been trying for 15days but not able to handle windproc function. I am not getting any clue how to handle this function. Please send me a sample code. Please please please. I am getting really sick of this. Send me at john.alex.programmer@gmail.com. Please help me.

          H 1 Reply Last reply
          0
          • J john alex prog

            Hi. I am sure you can help me. I want to write a program that just detect that a device has been changed. And in my program it is not concerned which device is changed. I have been trying for 15days but not able to handle windproc function. I am not getting any clue how to handle this function. Please send me a sample code. Please please please. I am getting really sick of this. Send me at john.alex.programmer@gmail.com. Please help me.

            H Offline
            H Offline
            hariakuthota
            wrote on last edited by
            #5

            Hi Alex, Did u try with the WindowProc(...) and if(message == WM_DEVICECHANGE ) inside it? This will be triggered if there is any change in the device connected to the system (Like plugging and Unplugging)

            J 1 Reply Last reply
            0
            • H hariakuthota

              Hi Alex, Did u try with the WindowProc(...) and if(message == WM_DEVICECHANGE ) inside it? This will be triggered if there is any change in the device connected to the system (Like plugging and Unplugging)

              J Offline
              J Offline
              john alex prog
              wrote on last edited by
              #6

              I have tried. But you know the main problem with me is that i dont know how to write windproc function and what are the parameters. I just want a running sample of windproc function. Then I will definitely do. Thanx.

              H 1 Reply Last reply
              0
              • J john alex prog

                I have tried. But you know the main problem with me is that i dont know how to write windproc function and what are the parameters. I just want a running sample of windproc function. Then I will definitely do. Thanx.

                H Offline
                H Offline
                hariakuthota
                wrote on last edited by
                #7

                LRESULT ClassName::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { // TODO: Add your specialized code here and/or call the base class if(message == WM_DEVICECHANGE ) { } return CDialog::WindowProc(message, wParam, lParam); } Note : In the first line when i say ClassName it is your respective class name.

                J 1 Reply Last reply
                0
                • H hariakuthota

                  LRESULT ClassName::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { // TODO: Add your specialized code here and/or call the base class if(message == WM_DEVICECHANGE ) { } return CDialog::WindowProc(message, wParam, lParam); } Note : In the first line when i say ClassName it is your respective class name.

                  J Offline
                  J Offline
                  john alex prog
                  wrote on last edited by
                  #8

                  #include <windows.h> #include <dbt.h> #include <strsafe.h> #include<iostream.h> #pragma comment(lib, "user32.lib") void Main_OnDeviceChange (HWND hwnd, WPARAM wParam, LPARAM lParam); char FirstDriveFromMask (ULONG unitmask); //prototype /*------------------------------------------------------------------ Main_OnDeviceChange (hwnd, wParam, lParam) Description Handles WM_DEVICECHANGE messages sent to the application's top-level window. --------------------------------------------------------------------*/ HWND hwnd; WPARAM wParam; LPARAM lParam; void Main_OnDeviceChange (HWND hwnd, WPARAM wParam, LPARAM lParam) { PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR)lParam; char szMsg[80]; switch(wParam) { case DBT_DEVICEARRIVAL: // Check whether a CD or DVD was inserted into a drive. if (lpdb -> dbch_devicetype == DBT_DEVTYP_VOLUME) { PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME)lpdb; if (lpdbv -> dbcv_flags & DBTF_MEDIA) { StringCchPrintf (szMsg, 80, "Drive %c: Media has arrived.\n", FirstDriveFromMask(lpdbv ->dbcv_unitmask)); MessageBox (hwnd, szMsg, "WM_DEVICECHANGE", MB_OK); cout<<"Hi"; } } break; case DBT_DEVICEREMOVECOMPLETE: // Check whether a CD or DVD was removed from a drive. if (lpdb -> dbch_devicetype == DBT_DEVTYP_VOLUME) { PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME)lpdb; if (lpdbv -> dbcv_flags & DBTF_MEDIA) { StringCchPrintf (szMsg, 80, "Drive %c: Media was removed.\n", FirstDriveFromMask(lpdbv ->dbcv_unitmask)); MessageBox (hwnd, szMsg, "WM_DEVICECHANGE", MB_OK); cout<<"Hi"; } } break; default: /* Process other WM_DEVICECHANGE notifications for other devices or reasons. */ ; } } /*------------------------------------------------------------------ FirstDriveFromMask (unitmask) Description Finds the first valid drive letter from a mask of drive letters. The mask must be in the format bit 0 = A, bit 1 = B, bit 2 = C, etc. A valid drive letter is defined when the corresponding bit is set to 1. Re

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups