Disconnect modem from app
-
Does anyone know how to close a modem connection? The connection was opened by the user, so I don't have a handle to it. But my app needs to hang up the modem when it terminates. Afterthought: I guess I need to query the state of the list of RAS connections and hang up the one that's active. Have to go find some RAS code at CP... /ravi Let's put "civil" back into "civilization" http://www.ravib.com ravib@ravib.com
-
Does anyone know how to close a modem connection? The connection was opened by the user, so I don't have a handle to it. But my app needs to hang up the modem when it terminates. Afterthought: I guess I need to query the state of the list of RAS connections and hang up the one that's active. Have to go find some RAS code at CP... /ravi Let's put "civil" back into "civilization" http://www.ravib.com ravib@ravib.com
I wrote a function that disconnects the modem:
#include <windows.h>
#include <ras.h>void HangUp(){
RASCONN *rasc=malloc(1000);
DWORD bs,nc,i,j,dwRet;
RASCONNSTATUS rcs;
MSG msg;
TCHAR s[257];
rcs.dwSize=160;
rasc->dwSize=412;
dwRet=RasEnumConnections(rasc,&bs,&nc);
if(!bs)return;
rasc=realloc(rasc,bs);
if(RasEnumConnections(rasc,&bs,&nc))
return;
for(i=0;i<bs/412;i++){
HRASCONN hrc=rasc[i].hrasconn;
dwRet = RasGetConnectStatus(hrc, &rcs);
if (dwRet != ERROR_INVALID_HANDLE){
RasHangUp(hrc);
while (dwRet != ERROR_INVALID_HANDLE){
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
dwRet = RasGetConnectStatus(hrc, &rcs);
}
}
}
free(rasc);
}
Peter O.
-
I wrote a function that disconnects the modem:
#include <windows.h>
#include <ras.h>void HangUp(){
RASCONN *rasc=malloc(1000);
DWORD bs,nc,i,j,dwRet;
RASCONNSTATUS rcs;
MSG msg;
TCHAR s[257];
rcs.dwSize=160;
rasc->dwSize=412;
dwRet=RasEnumConnections(rasc,&bs,&nc);
if(!bs)return;
rasc=realloc(rasc,bs);
if(RasEnumConnections(rasc,&bs,&nc))
return;
for(i=0;i<bs/412;i++){
HRASCONN hrc=rasc[i].hrasconn;
dwRet = RasGetConnectStatus(hrc, &rcs);
if (dwRet != ERROR_INVALID_HANDLE){
RasHangUp(hrc);
while (dwRet != ERROR_INVALID_HANDLE){
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
dwRet = RasGetConnectStatus(hrc, &rcs);
}
}
}
free(rasc);
}
Peter O.
Thanks very much, Peter! /ravi Let's put "civil" back into "civilization" http://www.ravib.com ravib@ravib.com