Click here to Skip to main content
Licence 
First Posted 7 Apr 2005
Views 31,572
Bookmarked 8 times

RasEnumConnections and "632" Error

By | 7 Apr 2005 | Article
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

About the Author

pozhit

Web Developer

United States United States

Member

I was born on the 9th of June 1976, Moscow, USSR. I went to a regular school till the 8th grade and then moved to the school with advanced classes in chemistry. I entered the Chemical Faculty of the Moscow State University in 1993. I successfully finished my studies in 1998 receiving MS in chemistry. In the year 2000 I moved to Germany where I continued my studies in molecular biology and bioinformatics. I received my Ph. D. degree in 2003. Currently I'm a research associate at the University of Washington, Seattle, WA, USA. My research involves bioinformatics, image processing and physical chemistry.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generalanother reason... Pinmembermoze5:54 2 Jan '12  
GeneralRASCONNSTATUS size Pinmemberangel_of_light0:40 14 Apr '10  
GeneralOne of the reason for this error. Pinmemberanand choubey6:55 31 Jul '09  
GeneralThanks! PinmemberbongoMaster0:38 2 Mar '07  
AnswerRe: Thanks! Pinmemberpozhit3:11 2 Mar '07  
QuestionWhat about more than one connection? PinmemberReallyLongNameThatNooneIsUsing10:31 28 Jun '06  
AnswerRe: What about more than one connection? PinmemberScipius1:58 16 Apr '07  
GeneralDoing something similar in C# for Win2K and XP Pinmemberjinksk4:53 19 Apr '05  
GeneralRe: Doing something similar in C# for Win2K and XP PinsussAnonymous5:13 19 Apr '05  

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

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120515.1 | Last Updated 7 Apr 2005
Article Copyright 2005 by pozhit
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid