Click here to Skip to main content
15,907,395 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I' m using this sample to check if the machine is connected to Internet, but it gives me 3 errors. Why' s that?

Here is the sample:

<br />using System;<br />using System.Runtime;<br />using System.Runtime.InteropServices;<br /><br />class IsConnected<br />{<br />    //Creating the extern function...<br />    [DllImport("wininet.dll")]<br />    private extern static bool InternetGetConnectedState(int out Description, int ReservedValue);<br /><br />    //Creating a function that uses the API function...<br />    public static bool IsConnectedToInternet()<br />    {<br />        int Desc;<br /><br />        return InternetGetConnectedState(out Desc, 0);<br />    }<br />}<br />

Here are the errors:
<br />Error 1: Identifier expected; 'out' is a keyword | Line: 9<br />Error 2: Invalid token ',' in class, struct, or interface member declaration | Line: 9<br />Error 3: ; expected | Line: 9<br />


I guess you have to write InternetGetConnectedState(out int Description, ....

Share this answer
change to this line...

private extern static bool InternetGetConnectedState(out int Description, int ReservedValue);

Share this answer

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900