We help IT Professionals succeed at work.
Get Started

RegisterDeviceNotification(), how to capture the messages?

Eimund asked
Last Modified: 2008-07-28

I'm trying to use the function RegisterDeviceNotification to handle when a USB device attaches or removes.

I have made my own class, CUSB, which contain all my USB handlings. CUSB is not a form class. I want to call CUSB::MyFunction on device change. My first question is, what should I send as HANDLE to  RegisterDeviceNotification? When using TForm classes, which contain a HANDLE, they just send this->Handle; But I do not have such a HANDLE. Can I use just "this" as a HANDLE?

DeviceNotificationHandle = RegisterDeviceNotification(this, &DevBroadcastDeviceInterface, DEVICE_NOTIFY_WINDOW_HANDLE);

The other question is: how do I set CUSB::MyFunction to called when a WM_DEVICECHANGE message occurs?

Eimund Smestad

Watch Question
Top Expert 2012
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE