Using the Rasenumconnections function today, we found that the example on MSDN is wrong.
This is what the Rasenumconnections documentation on MSDN says:
Copy the Code code as follows:
To determine the required buffer size, call Rasenumconnections with Lprasconn set to NULL. The variable pointed to by LPCB should is set to zero. The function would return the required buffer size in LPCB and an error code of Error_buffer_too_small.
The sample code provided on MSDN is also written like this:
Copy the Code code 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, the Rasenumconnections function returns error_invalid_size (632) instead of Error_buffer_too_small. The solution is not to pass the first parameter to NULL, but to pass in a properly set dwsize rasconn structure, General dwsize is set to sizeof (Rasconn), but if your program to run on an earlier system, you need to hard Code into the value of the target system.