Click here to Skip to main content
Licence 
First Posted 9 Jan 2000
Views 83,592
Bookmarked 18 times

Calling RasHangUp without errors.

By | 9 Jan 2000 | Article
A way to call RasHangUp without hanging your applications or your modem

Problem

The RasHangUp function terminates a remote access connection. The connection is specified with a RAS connection handle. The function releases all RASAPI32.DLL resources associated with the handle. (MSDN)

Then, in remarks, it is mentioned that the application should sleep about 3 seconds, or until RasGetConnectStatus returns ERROR_INVALID_HANDLE. If you realy just call RasHangUp and exit you can "hang" both the modem and rnaapp (the application that implements Dial-Up Services). Furthermore, if you do everything as described in MSDN you may still receive the following error message:

RNAAPP caused an invalid page fault in module xxxx.

Solution

This problem was a besetting sin when I wrote my Dial-up dialer program, until I found a solution that works in my program:

DWORD dwRet;
RASCONNSTATUS rStatus;
ZeroMemory(&rStatus, sizeof(RASCONNSTATUS));
rStatus.dwSize = sizeof(RASCONNSTATUS);
dwRet = RasGetConnectStatus(hRasConn, &rStatus);
if (dwRet != ERROR_INVALID_HANDLE)
{
	RasHangUp(hRasConn);  // hRasConn - valid handle to the RAS connection
	MSG msg;
	while (dwRet != ERROR_INVALID_HANDLE)
	{
		while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
	   		TranslateMessage(&msg);
		   	DispatchMessage(&msg);
		}
		dwRet = RasGetConnectStatus(hRasConn, &rStatus);
	}
}

Note: I removed some unimportant stuff so check this code before using...

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

Alexander Fedorov

Web Developer
SEO
Ukraine Ukraine

Member

AlexF's Blog in Russian
Owner Spy competition analysis
Rating Burner Rating of blogs

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
GeneralWindows's dialer list Pinmemberphi-161821:49 16 Oct '07  
GeneralI've some question... PinsussLee Joung Soo9:01 22 May '05  
QuestionHow to use RasDial() WITHOUT phonebook entry? Pinmembersoniko4:10 5 Oct '03  
AnswerRe: How to use RasDial() WITHOUT phonebook entry? PinmemberRamkrishna Pawar3:29 14 May '04  
GeneralTelephone number PinmemberAnonymous1:30 5 Jun '01  
GeneralRe: Telephone number - and - Does anyone know how to get the user and password ? PinmemberRichard Broadhurst22:57 12 Sep '01  
GeneralRe: Telephone number - and - Does anyone know how to get the user and password ? PinmemberHackMan4:56 5 Dec '01  
QuestionThanks But ??? PinsussDavid Fields11:26 31 Mar '00  
QuestionThanks But ??? PinsussDavid Fields11:25 31 Mar '00  
GeneralRE: PinsussMartijn Hoogendoorn10:44 6 Mar '00  
GeneralRe: RE: PinmemberAldamo19:56 3 May '02  

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.120517.1 | Last Updated 10 Jan 2000
Article Copyright 2000 by Alexander Fedorov
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid