PatchInetSession->QueryOption(INTERNET_OPTION_CONNECTED_STATE, dwconnection);
if ((dwconnection & INTERNET_STATE_CONNECTED) == 0)
return -1;
But (dwconnection) becomes INTERNET_STATE_CONNECTED regardless of the connection status.
Any ideas?
How do I know if I have an Internet Connection?
I'm using a little MFC and recently made the switch from FTP to HTTP (much faster btw). It turns out, however, that CInternetSession::OpenURL() will crash if the prog does not have an Internet connection. OpenURL will crash before returning, it is supposed to throw a CInternetException, but I am unable to catch it because it crashes too early. This may only happen in my debug build, I haven't tested with release yet.
So how can I tell if I'm online. I tried using QueryOption:
I suppose that you only check whether you're connected to a network - i.e. if a cable is plugged into your network adapter and there's some kind of network equipment on the other end.
Basically it's hard for a computer to know how large a network it's connected to. I think the only solution is to try connecting to the remote host you're interested in, and see whether it fails or not. Maybe doing it in another thread if you don't want it to block your main one? (I don't know how MFC works btw)
Basically it's hard for a computer to know how large a network it's connected to. I think the only solution is to try connecting to the remote host you're interested in, and see whether it fails or not. Maybe doing it in another thread if you don't want it to block your main one? (I don't know how MFC works btw)
If you can't get that to work, the catch-all would be to use structured exception handling.
There are some caveats with SEH vs regular exceptions vs objects with destructors, and you have no guarantee that your heap will be in a useable state after the crash is caught, but you can at least bring up a dialog box and exit the program cleanly in the exception handler.
__try { crash goes here}__except(EXCEPTION_EXECUTE_HANDLER) { oops, I crashed! clean up and continue}
There are some caveats with SEH vs regular exceptions vs objects with destructors, and you have no guarantee that your heap will be in a useable state after the crash is caught, but you can at least bring up a dialog box and exit the program cleanly in the exception handler.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement