Link to home
Start Free TrialLog in
Avatar of Eimund
Eimund

asked on

RegisterDeviceNotification(), how to capture the messages?

Hello,

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?

Regards
Eimund Smestad

ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Eimund
Eimund

ASKER

I see. Then what I ask is not possible. My class have to be a form? If so this is not a solution for me.

Is there a way to use the HANDLE to my USB device to check if it is still attached or detached?

Eimnund Smestad
Well, your form does for sure have a window handle, ant that should clear everything up...
Avatar of Eimund

ASKER

CUSB is not of TForm class, and I don't want it to be either!

My question is if this is possible for a regular class?

Eimund Smestad
But you need some form to process the messages, since callback functions are not allowed for that notification...
Avatar of Eimund

ASKER

Yes it is what I realized, I thought initialy that it was a callback function. But since it is not, then my current solution is more appealing to me. I have a function which I can check for a valide respons, the only drawback is that I need a timer to pull this function.

But thank you very much for the clarification.

Eimund Smestad