Calling RasHangUp without errors.






3.83/5 (3 votes)
Jan 10, 2000

107062
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...