How to detect datacard connect and disconnect event on win32?

爷,独闯天下 提交于 2019-12-23 06:07:43

问题


I have a data card, as soon as I insert the data card, I am getting the events by using wm_device_change event.

But I also want to get event, when my data connect actually connects to the outside world.

I mean to say, as soon as we click on connect/disconnect button of data card, I want to get the event. In other words, I want to know when connection is established and disconnected.

The data card is a Vodaphone data card and I am trying to browse using that data card. Whatever is the SDK, somewhere the OS should get the event of connection and disconnection to network is there any way to access that event which OS is getting. As I can see in notification the changes of Vodaphone connection and LAN connection.

Data card is a USB device having SIM within it, and can be used to access internet through GPRS.

How can I do this in a Win32 C/C++ program?


回答1:


To detect a network change, you can use NotifyAddrChange(0,0); Since this is blocking, you will need a thread. The thread function can be as simple as

while(true) {
  NotifyAddrChange(0,0);
  PostMessage(gHWnd, WM_APP,0,0);
}

Don't bother with the documented asynchronous behavior. That simply doesn't work.




回答2:


Surely this would depend on your "Data Card" sdk or drivers and whether they support such an event.

Otherwise what I would suggest is that when you call the "Connect" or "Disconnect" methods within the SDK that you use any return value indicating suuccess or otherwise to raise your own event.

Without knowing what this data card is and what it is connecting to then I don't see how we can answer your question more fully.



来源:https://stackoverflow.com/questions/1056784/how-to-detect-datacard-connect-and-disconnect-event-on-win32

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!