0

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.

Richard C
  • 2,176
  • 5
  • 30
  • 40

2 Answers2

1

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!

Jeff Winn
  • 804
  • 8
  • 14
  • Many thanks for this information! I switched to using the DotRas project and it made my life much easier! – Richard C Sep 13 '11 at 07:19
-1

Here you should find your answer http://msdn.microsoft.com/en-us/library/aa920538.aspx this is the enum values of RASCONNSTATE returned by RasGetConnectStatus. The value 6 should equal to RASCS_AuthNotify and you will find this description:

An authentication event has occurred. If dwError is zero, this event will be immediately followed by one of the more specific authentication states following. If dwError is nonzero, authentication has failed, and the error value indicates why.

Maybe is related with some firewall rules that block the connection.

update the link is from windows mobile 6.5 documentation. for the windows one this link.

Iridio
  • 9,213
  • 4
  • 49
  • 71
  • This is not correct. The function does not return the ras state. It returns 0 on success, or an error value. The actual status is saved in the second parameter which is passed to this function. This is always set to 0 when an error occurs, which is what I'm finding. – Richard C Mar 22 '11 at 09:18
  • @RichieACC from the link I posted the third row say clearly: "Also, use the RasGetConnectStatus function to get the connection state for a specified connection.". So I guess this is the enum you get in response. It's also specify in the doc of RasGetConnectStatus. that the LPRASCONNSTATUS is a "Pointer to the RASCONNSTATUS structure that, on output, receives the status information." Inside this structure you will find rasconnstate. Sorry if it can not be of help :( – Iridio Mar 22 '11 at 09:23
  • The problem is that I'm getting dwError = 6. I'm obviously doing something wrong, but I'm not sure what, and none of the documentation that I've read tells me what error is indicated by 6. – Richard C Mar 22 '11 at 09:49