The RasEnumConnections function in VB returns a 632 error resolution

  • 2021-07-10 18:59:01
  • OfStack

Today, I used the RasEnumConnections function under 1, and found that the example on MSDN was wrong.

The documentation for RasEnumConnections on MSDN says this:


To determine the required buffer size, call RasEnumConnections with lprasconn set to NULL. The variable pointed to by lpcb should be set to zero. The function will return the required buffer size in lpcb and an error code of ERROR_BUFFER_TOO_SMALL.

The sample code provided on MSDN also reads as follows:


DWORD __cdecl wmain(){     DWORD dwCb = 0;
    DWORD dwRet = ERROR_SUCCESS;
    DWORD dwConnections = 0;
    LPRASCONN lpRasConn = NULL;
   
    dwRet = RasEnumConnections(lpRasConn, &dwCb, &dwConnections);     if (dwRet == ERROR_BUFFER_TOO_SMALL) {
        // ......
    }

Unfortunately, this example is wrong, at least on XP SP3, and the RasEnumConnections function returns ERROR_INVALID_SIZE (632) instead of ERROR_BUFFER_TOO_SMALL. The solution is that the first parameter should not be passed into NULL, but an RASCONN structure with dwSize correctly set, and dwSize can be set to sizeof (RASCONN); But if your program is to run on an earlier system, you need HARD CODE to be the target system value.


Related articles: