Question

I'm checking the Internet connection state and want to send a MessageBox if no internet connection is present what I have is this:

;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 Sleep,5000 ;Sleep so it doesn't use 99% CPU
        INVOKE  IsOnline,offset szURL    
        or      eax,eax
        jz      loop00

        INVOKE  Beep,750,1000
        exit

_main   ENDP

;-------------------------------------------------------------------------

        END     _main

Now I thought to add something like this

 .data
    MyTitle db "No internet",0
    MyText db "No active internet connection found, retrying in 5 seconds.",0

            push 0
            push offset MyTitle
            push offset MyText
            push 0
            call MessageBoxA

But I can't really figure out where I would have to put that

Was it helpful?

Solution

How about this:

_main   PROC

loop00: 
        INVOKE  IsOnline,offset szURL    
        or      eax,eax
        jnz      done

        push 0
        push offset MyTitle
        push offset MyText
        push 0
        call MessageBoxA

        Invoke Sleep,5000 ;Sleep so it doesn't use 99% CPU

        jmp loop00

done:
        INVOKE  Beep,750,1000
        exit

_main   ENDP

.data
    MyTitle db "No internet",0
    MyText db "No active internet connection found, retrying in 5 seconds.",0

That will first wait test for IsOnline, and if it fails, will wait 5 seconds and try again. Otherwise it goes to the beep before exiting.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top