Search code examples
c#ras

What does it indicate when RasGetConnectStatus returns a value of 6?


I'm trying to query the RasStatus of a connection. When I call the RasGetConnectStatus method, it returns 6. I've not found that particular return value in any of the documentation that I've read.

Here are some of the pages that I've looked at:

http://www.cs.scranton.edu/~beidler/Ada/win32/win32-raserror.html

http://msdn.microsoft.com/en-us/library/aa920162.aspx

http://msdn.microsoft.com/en-us/library/bb530704(v=vs.85).aspx

I'm using C# and .net 4.0

Edit: The code that actually calls follows:

uint result;
RASCONNSTATUS rasconnstatus; // http://pinvoke.net/default.aspx/Structures/RASCONNSTATUS.html
// _handle is previously set to the hwnd of the ras connection
result = RASAPI.RasGetConnectStatus(_handle, out rasconnstatus);

return rasconnstatus;

When this returns, result == 6 and rasconnstatus.rasconnstate == 0

What I need to find out is why result == 6.


Solution

  • The easiest way to look up Win32 error codes is by looking at the header files directly in the Windows SDK. Most of them are in the WinError.h file in the include folder wherever you installed the Windows SDK. For the RAS specific errors (the result would be between 600 and 900) those are in the RasError.h file.

    In the case of your result being 6, it's indicating ERROR_INVALID_HANDLE; which in RAS that means it didn't like the connection handle you passed to the function. In your code sample, that would be _handle.

    By the way, you may want to look at using the DotRas project on CodePlex, it's a .NET wrapper around the RAS API. The particular method you're interested in would be RasConnection.GetConnectionStatus, it returns the data from that structure.

    foreach (RasConnection conn in RasConnection.GetActiveConnections())
    {
        RasConnectionStatus status = conn.GetConnectionStatus();
        // Do something useful.
    }
    

    The WinError.h file is also available online here: http://msdn.microsoft.com/en-us/library/ms819772.aspx

    Hope that helps!