Good evening.
I am posting today to ask tips to connect or disconnect to internet, to the default connection. Checked foruns and multiple codes, but I am unable to connect or disconnect.
Here are the subs and declares I am using (checkconnection works as supposed, but connect or disconnect always give me 0 in return):
SUB Connect(), INT
'make a internet connection
'returns 1 if action was succesfull, else returns 0
ICINFO ConInfo
INT lRetValue
ConInfo.dwConnectedState = 1 :'INTERNET_STATE_CONNECTED
lRetValue = InternetSetOptionA(0, 50, ConInfo, LEN(ConInfo))
RETURN lRetValue
ENDSUB
SUB Disconnect(), INT
'disconnect from internet
'returns 1 if action was succesfull, else returns 0
ICINFO ConInfo
INT lRetValue
ConInfo.dwConnectedState = 16 :'INTERNET_STATE_DISCONNECTED_BY_USER
ConInfo.dwFlags = 1 :'ISO_FORCE_DISCONNECTED
lRetValue = InternetSetOptionA(0, 50, ConInfo, LEN(ConInfo))
RETURN lRetValue
ENDSUB
SUB CheckConnection(),INT
'check if there is an connection to internet
'returns 1 if there is a connection, else returns 0
INT lRetVal, lpdwFlags, c
lRetVal = InternetGetConnectedState(lpdwFlags, 0)
IF (lpdwFlags & 32) = 0
c=1 :'there is a connection
ELSE
c=0 :'there is no connection
ENDIF
RETURN c
ENDSUB
DECLARE IMPORT, InternetSetOptionA(hInternet:INT, dwOption:INT, lpBuffer:POINTER, dwBufferLength:INT),INT
DECLARE IMPORT,InternetGetConnectedState(lpdwFlags:pointer, dwReserved:INT),INT
DECLARE CheckConnection(),INT
DECLARE Disconnect(), INT
DECLARE Connect(), INT
TYPE ICINFO
INT dwConnectedState, dwFlags
ENDTYPE
ICINFO myvar
DECLARE gdh(),string
Any tip will be wonderful. Thanks in advance.
You can force the default dialup connection dialog to come up with:
InternetAttemptConnect
You can attempt to force the default dialup connection to dial with:
InternetAutodial
And of course you can force the default dialup connection to hang up with:
InternetAutodialHangup
See the MSDN docs for usage. Security settings, and the users preferences can cause these functions not to work. If the default connection is a LAN, or DSL modem then they will do nothing of course.
http://msdn.microsoft.com/en-us/library/aa384005(VS.85).aspx
By the way...InternetSetOptions can't be used to dial a connection, it just sets the values used by the instance of IE used by your process.
Paul.
Changed soubroutines slightly after checking your suggestions and Microsoft site, and still no results. Also checked wininet.lib. Checkconnection now is always giving me connection is on, even when it isnt. Also, using connect or disconnect always returns 1, which I assume it's TRUE, but not changing nothing in the default connection.
DECLARE IMPORT,InternetGetConnectedState(lpdwFlags:pointer, dwReserved:INT),INT
DECLARE IMPORT, InternetAutodial(dwFlags:POINTER,hwndParent:INT),INT
DECLARE IMPORT, InternetAutodialHangup(dwReserved:INT),INT
DECLARE CheckConnection(),INT
DECLARE Disconnect(), INT
DECLARE Connect(), INT
' Flags for InternetAutodial
$define INTERNET_AUTODIAL_FORCE_ONLINE 1
$define INTERNET_AUTODIAL_FORCE_UNATTENDED 2
$define INTERNET_AUTODIAL_FAILIFSECURITYCHECK 4
$define INTERNET_AUTODIAL_OVERRIDE_NET_PRESENT 8
SUB Connect(), INT
'make a internet connection
'returns 1 if action was succesfull, else returns 0
INT lRetValue
lRetValue=InternetAutodial(INTERNET_AUTODIAL_FORCE_ONLINE,0)
' lRetValue=InternetAutodial(INTERNET_AUTODIAL_FORCE_UNATTENDED,0)
' lRetValue=InternetAutodial(INTERNET_AUTODIAL_FAILIFSECURITYCHECK,0)
' lRetValue=InternetAutodial(INTERNET_AUTODIAL_OVERRIDE_NET_PRESENT,0)
RETURN lRetValue
ENDSUB
SUB Disconnect(), INT
'disconnect from internet
'returns 1 if action was succesfull, else returns 0
INT lRetValue
lRetValue=InternetAutodialHangup(0)
RETURN lRetValue
ENDSUB
SUB CheckConnection(),INT
'check if there is an connection to internet
'returns 1 if there is a connection, else returns 0
INT lRetVal, lpdwFlags, c
lRetVal = InternetGetConnectedState(lpdwFlags, 0)
IF (lpdwFlags & 32) = 0
c=1 :'there is a connection
ELSE
c=0 :'there is no connection
ENDIF
RETURN c
ENDSUB
Which security and user settings should I check, btw? Dunno that's the problem, because all functions are giving me TRUE and they shouldn't...
Modem is one of those Vodafone modems to access via 3G, and I use windows connection icon to access to it, not their software.
I guess I could turn this problem around if I can create 2 shortcuts to connect and disconnect, and in my program use "system" to them... but even in this way I dunno how to work.
I tried in spite of InternetAutodial, InternetDial, and had some results, but still not what I pretend.
declare import, InternetDial alias InternetDialW(hwndParent:INT,lpszConnectoid:STRING,dwFlags:INT,lpdwConnection:STRING,dwReserved:INT),INT
declare import, InternetHangUp(dwConnection:POINTER,dwReserved:INT),INT
$define INTERNET_DIAL_FORCE_PROMPT 0x2000
$define INTERNET_DIAL_SHOW_OFFLINE 0x4000
$define INTERNET_DIAL_UNATTENDED 0x8000
and to run
SUB Connect(), INT
'make a internet connection
'returns 1 if action was succesfull, else returns 0
INT lRetValue
lRetValue=InternetDial(0,"Rede fixa",INTERNET_DIAL_UNATTENDED,con_id,0)
RETURN lRetValue
ENDSUB
When I call a Connect() it opens the dial window, but not the connection called "Rede fixa" (I guess it opens the first connection in my connection list).
If this function works, and considering I checked many foruns and posts of InternetAutodial, it makes me think I am missing something easy.
Figured out I needed to disable in control panel, internet options, connections tab, the option which says "never establish a connection". Now InternetAutodial works just fine.