I have this small application written in MASM that keeps checking for an Active internet connection and sends a Beep if there is one, now my problem is that the loop uses 99% of the CPU, I have tried putting a Sleep inside the loop but somehow that isn't working ?
This is the code:
;build as a WINDOWS app
.XCREF
.NOLIST
INCLUDE \masm32\include\masm32rt.inc
INCLUDE \masm32\include\wininet.inc
INCLUDELIB \masm32\lib\wininet.lib
.LIST
;-------------------------------------------------------------------------
IsOnline PROTO :LPSTR
Sleep PROTO STDCALL :DWORD
;-------------------------------------------------------------------------
IFNDEF FLAG_ICC_FORCE_CONNECTION
FLAG_ICC_FORCE_CONNECTION EQU 1
ENDIF
;-------------------------------------------------------------------------
.CODE
IsOnline PROC lpszURL:LPSTR
;Test Internet Connection
;
;lpszURL points to a zero-terminated test URL string (must start with "http://")
;
;Returns EAX = FALSE if not connected
; = TRUE if connected
; EDX = connection description (see InternetGetConnectedState documentation)
push eax
mov edx,esp
INVOKE InternetGetConnectedState,edx,0
or eax,eax
jz IsOnl0
INVOKE InternetCheckConnection,lpszURL,FLAG_ICC_FORCE_CONNECTION,0
IsOnl0: pop edx
ret
IsOnline ENDP
;-------------------------------------------------------------------------
szURL db 'http://www.google.com',0
;-------------------------------------------------------------------------
_main PROC
loop00: INVOKE IsOnline,offset szURL
Invoke Sleep,5000
or eax,eax
jz loop00
INVOKE Beep,750,1000
exit
_main ENDP
;-------------------------------------------------------------------------
END _main
Sleep()
may trash registers and so the return value from IsOnline()
may be lost.