-2

I'm writing an application which check for my usb device and if the device is avialable make a dial-up connection. I use Rasdial to establish the connection. Unfortunately if I remove the USB cable the connection is not getting disconnected or notified to the user. So here I'm in a situation to check for the device removal.

I Planned to run my application in system tray and wait for the device removal. Am I right here?

If am right how to make the application wait for device removal, currently my console application exits once the dial-up connection is made. How to achieve this in Winapi32? Am coding it in C.

2vision2
  • 4,933
  • 16
  • 83
  • 164
  • The title doesn't seem to match the actual question (which I beleive is a duplicate of your previous questions?) Please update thw question or title to suit. – Deanna Jun 27 '12 at 11:18
  • Better. The system tray still doesn't come into it though as that's purely a UI choice. – Deanna Jun 27 '12 at 11:33
  • No my question belongs to system tray. I want my app to be in system tray and monitors the device removal. there is no UI in my current app at all... – 2vision2 Jun 27 '12 at 11:40
  • As I said, the system tray has no bearing on whether you can receive device disconnection notifications. I don't know off hand how you register to receive them if the `registerdevicenotification()` [you've used before](http://stackoverflow.com/q/11151183/588306) doesn't help. – Deanna Jun 27 '12 at 12:48

1 Answers1

2

Your window can handle the WM_DEVICECHANGE broadcast message to tell when something has changed. If you need more detailed information, use RegisterDeviceNotification().

Using the system notification area has no bearing on your ability to use these methods. They all require a window to send the notifications to, but it can be kept hidden.

Deanna
  • 23,876
  • 7
  • 71
  • 156
  • ya if I hide the window its like running my app background rit?? just to get the window handle I went for system tray. But you mean even I can avoid that? Please correct me If am wrong.. – 2vision2 Jun 27 '12 at 13:42
  • Well, the system notification tray needs a window to send its messages back to. It doesn't magically give you one. – Deanna Jun 27 '12 at 15:01
  • this comment may sounds outta place to this post forgive me if so.. Is there a way to find only my device insertion/removal using "registerdevicenotififcation". Can you please give me some tips on it? – 2vision2 Jun 28 '12 at 04:04
  • It depends how you identify your device. That API can filter on device class, it's up to you to detect the actual device by the information it sends you. – Deanna Jun 28 '12 at 08:32