|
-
May 4th, 1999, 07:33 AM
#1
How do you detect a Dial Up Network connection
I have an application which uses sockets to communicate across the internet. At present when opening the socket the windows API automagically starts up the DUN connection. But it does not automatically close the connection, therefore the connection can still be active after the app has been exited. This causes DUN (and Explorer) to crash when you manually disconnect.
I think to get round this I need to detect whether a DUN connection is already available for use and if not startup and disconnect the connection. I've found code on this site to connect/disconnect but how can I detect if there is already a connection.
Thanx in advance.
ps. betters solutions would also be welcome.
-
May 4th, 1999, 08:35 AM
#2
Re: How do you detect a Dial Up Network connection
I do it like this-
#include <wininet.h>
if( InternetGetConnectedState(&lpdwFlags ,0) == FALSE)
{
AfxMessageBox( "No network connected" );
}
else
{
AfxMessageBox("Connected");
}
Lorn "ljp" Potter
Trolltech Qtopia Community Liaison
irc.freenode.net #qtopia, #qt
-
May 4th, 1999, 09:11 AM
#3
Re: How do you detect a Dial Up Network connection
My version of wininet.h does not have InternetGetConnectedState(). I think I may be right in thinking this is a Explorer4/5 function. Can you mail me a copy of wininet.h.
-
May 10th, 1999, 09:28 AM
#4
Re: How do you detect a Dial Up Network connection
Found some info on the subject in MSDN under: main: "A Programmer’s Perspective on New System DLL Features in Windows NT 5.0, Part II" sub: "New WinInet Fun with Windows NT 5.0".
Does it really work with NT4/Win9X?
-
May 14th, 1999, 12:35 AM
#5
Re: How do you detect a Dial Up Network connection
Hi!
Try the following:
// Checking existing connections
RASCONN rasExCon[3];
DWORD dwSize = 3*sizeof(RASCONN);
DWORD dwExist = 0;
rasExCon[0].dwSize = sizeof(RASCONN);
if(dwRet = ::RasEnumConnections( rasExCon, &dwSize, &dwExist))
{
char szBuf[513];
if (!::RasGetErrorString( (UINT) dwRet, (LPSTR)szBuf, 512))
{
AfxMessageBox (szBuf, MB_OK | MB_ICONSTOP);
return FALSE;
}
AfxMessageBox (IDS_CANTENUMRASCON_E, MB_OK | MB_ICONSTOP);
return FALSE;
}
// Look for our phone entry among opened connections
for (int i=0; i<(int)dwExist; i++)
{
if (stricmp(rasExCon[i].szEntryName, m_ConInfo.m_csPhoneEntry) == 0)
{
// Here TCP/IP can be used
PostMessage (WM_NEXT_ACTION, NA_USEIP);
return TRUE;
}
}
if (dwExist != 0)
{
int nRet = AfxMessageBox (IDS_USEEXISTRASCON_E, MB_OKCANCEL | MB_ICONQUESTION);
if (nRet == IDOK)
{
PostMessage (WM_NEXT_ACTION, NA_USEIP);
return TRUE;
}
return FALSE;
}
Best Regards, IVS
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|