Click here to Skip to main content
15,860,972 members
Articles / Desktop Programming / MFC
Article

RasEnumConnections and "632" Error

Rate me:
Please Sign up or sign in to vote.
4.50/5 (6 votes)
7 Apr 20051 min read 53.6K   8   10
Why RasEnumConnections fails on Win2k and how to fix it.

Introduction

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.

#include "stdafx.h"
/*make sure to define _UNICODE, UNICODE, _WIN32_WINNT = 0x0500 */
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
    DWORD iNumBytes = 0x53c;
    DWORD iRcvd;
    RASCONN rsc[1];
    rsc[0].dwSize = 0x53c;
 
    int iErr = RasEnumConnections(rsc, &iNumBytes, &iRcvd);
    if(!iErr && iRcvd)
        RasHangUp(rsc[0].hrasconn);
    return 0;
}

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.

Enjoy RAS.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Team Leader University of Washington
United States United States
I was born in Moscow, USSR. In 1998, I earned Master’s degree in Chemistry from the Moscow State University. In 2000, I moved to Germany to pursue a PhD degree in Genetics. Currently I live with my family in the United States.
I have been always involved is a multidisciplinary research side-by-side with biologists. The research involves physical chemistry, bioinformatics and electrical engineering.

Comments and Discussions

 
Generalanother reason... Pin
moze2-Jan-12 5:54
moze2-Jan-12 5:54 
GeneralRASCONNSTATUS size Pin
Sorin.B14-Apr-10 0:40
Sorin.B14-Apr-10 0:40 
GeneralRe: RASCONNSTATUS size Pin
Dr. APo23-May-12 21:29
professionalDr. APo23-May-12 21:29 
GeneralOne of the reason for this error. Pin
anand choubey31-Jul-09 6:55
anand choubey31-Jul-09 6:55 
GeneralThanks! Pin
bongoMaster2-Mar-07 0:38
bongoMaster2-Mar-07 0:38 
AnswerRe: Thanks! Pin
Dr. APo2-Mar-07 3:11
professionalDr. APo2-Mar-07 3:11 
QuestionWhat about more than one connection? Pin
ReallyLongNameThatNooneIsUsing28-Jun-06 10:31
ReallyLongNameThatNooneIsUsing28-Jun-06 10:31 
AnswerRe: What about more than one connection? Pin
Scipius16-Apr-07 1:58
Scipius16-Apr-07 1:58 
GeneralDoing something similar in C# for Win2K and XP Pin
jinksk19-Apr-05 4:53
jinksk19-Apr-05 4:53 
GeneralRe: Doing something similar in C# for Win2K and XP Pin
Anonymous19-Apr-05 5:13
Anonymous19-Apr-05 5:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.