Recently I was working on a small application that was dealing with active dial-up connections. Dial-up networking is provided by the Windows Remote Access Service (RAS) and primarily used for connecting to the Internet by a modem. I tried to use the
RasEnumConnections function to enumerate the active dial-up connections to obtain a connection handle for further processing. Unfortunately, no matter what my compiler settings were, on Win2k Professional, the function persistently returned 632, which means “Invalid size of the
RASCONN structure”. Searching through the Internet and CodeProject pages I figured out that many people noticed the same effect and so far no solution has been published. The focus of this article is to provide a fix for this annoying error.
In order to figure out why the function always failed, I went step-by-step through the internals of this function and noticed that the function expects different sizes of the
RASCONN structure (i.e. versions of the structure) but there was nothing like the value provided by
sizeof(RASCONN). The closest match was 0x53c. I tried to cheat the function by supplying 0x53c as the size of the
RASCONN structure. It worked! The code shown below represents a program that enumerates a live dial-up connection and hangs it up.
int APIENTRY WinMain(HINSTANCE hInstance,
DWORD iNumBytes = 0x53c;
rsc.dwSize = 0x53c;
int iErr = RasEnumConnections(rsc, &iNumBytes, &iRcvd);
if(!iErr && iRcvd)
The trick is to make
dwSize equal to 0x53c. Note that 0x53c is smaller than
sizeof(RASCONN), therefore the function will not corrupt the memory.