Alex Rivera | Logout

How do you determine if an Internet connection is available for your WinForms App?

Asked 2008-10-11T22:23:32.233
13

What is the best way to determine whether there is an available Internet connection for a WinForms app. (Programatically of course) I want to disable/hide certain functions if the user is not connected to the Internet.

Edit
Report

1 Answer

10

sbeskur's response has a bug in the translation of InternetGetConnectedState. The parameters are both DWORD's (first one is an LPDWORD). Both of these translate to int's in C# (technically, uint but int will work for most scenarios).

Correct translation below.


[DllImport("wininet.dll", SetLastError=true)] 
public static extern bool InternetGetConnectedState(out int flags,int reserved);
answered 2008-10-12T02:24:53.340

Your Answer