I am trying to put together a function that returns whether the current machine is offline. I am working from VB code, and thought that I had it worked out, but am getting the same result whether or not the machine is connected or not. Here is what I have:
FUNCTION ConnectedToInternet
SET PROC TO CLSHeap
INTERNET_OPTION_CONNECTED_STATE = 50
INTERNET_STATE_CONNECTED = 1
INTERNET_STATE_DISCONNECTED = 2
DECLARE INTEGER InternetQueryOption ;
IN wininet.dll ;
LONG hInternet, ;
LONG lOption, ;
STRING @sBuffer, ;
LONG @lBufferLength
lsConnectionInfo = SPACE(8)
lnCILen = 8
lnResult = InternetQueryOption(0, INTERNET_OPTION_CONNECTED_STATE, @lsConnectionInfo, @lnCILen)
IF DWordtoNum(lsConnectionInfo) = INTERNET_STATE_CONNECTED
RETURN .T.
ELSE
RETURN .F.
ENDIF
ENDFUNC
DWordtoNum is a function in Ed Rauh's class heap class that does as the name implies: converts a 4 byte DWord to a VFP number.
lsConnectionInfo is an 8 byte string that substitutes for a structure declared in VB like:
PUBLIC TYPE INTERNET_CONNECTED_INFO
dwConnectedState AS LONG
dwFlags AS LONG
END TYPE
The funky things I have noticed: I pass in the size of the lsConnectionInfo string as 8, but after the function call, it is sized to 4. What happened to the other DWord?
The other thing I am not sure about is the syntax in te following VB sample:
ret = InternetQueryOption(0&, INTERNET_OPTION_CONNECTED_STATE, ci,ci_len)
what is the "&" in the first parameter?
I am not sure if my code is not working, or the wininet function is returning a value I am not expecting- anybody care to explain where what I might be going wrong?
FYI, the VB code I am working from is in KB article Q200027.
Erik Moore
Clientelligence