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

C++

Avatar of undefined
Last Comment
Eimund
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
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
Avatar of jkr
jkr
Flag of Germany image

Well, your form does for sure have a window handle, ant that should clear everything up...
Avatar of Eimund
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
Avatar of jkr
jkr
Flag of Germany image

But you need some form to process the messages, since callback functions are not allowed for that notification...
Avatar of Eimund
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
C++
C++

C++ is an intermediate-level general-purpose programming language, not to be confused with C or C#. It was developed as a set of extensions to the C programming language to improve type-safety and add support for automatic resource management, object-orientation, generic programming, and exception handling, among other features.

58K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo