Hi
this code snippet should check if a website is up or not.

i cant fix this problem:

invoke InternetCheckConnection,ADDR adress,1,0
.IF (!eax)
invoke MessageBox,NULL,ADDR finns_ej,ADDR titel,MB_OK
.ELSE
invoke MessageBox,NULL,ADDR finns,ADDR titel,MB_OK
.ENDIF

it always goes to .ELSE but i dont understand why..:mad:
in .ELSE is if the website is up...

pls help me, and excuse my bad english :tongue:
Posted on 2003-08-07 05:39:03 by bj1500
It worked for me :confused:


...
include wininet.inc
includelib wininet.lib
...

.data
finns_ej db "Finns ej!",0
finns db "Finns!",0
adress db "http://www.google.com",0
titel db "Internet test",0

.code


invoke InternetCheckConnection,ADDR adress,1,0
.IF (!eax)
invoke MessageBox,NULL,ADDR finns_ej,ADDR titel,MB_OK
.ELSE
invoke MessageBox,NULL,ADDR finns,ADDR titel,MB_OK
.ENDIF
Posted on 2003-08-07 06:27:24 by Delight
have you tried with a URL that not work? it alwasy goes in to the else part...even if it is a URL like:
http://www.fgiuregiuegiurehgurehgiueg.com
:mad:
Posted on 2003-08-07 06:47:11 by bj1500
Here is an example that works for me
Posted on 2003-08-07 07:03:50 by Delight
it still dont work...
i post all my code here so you can take a look at it:
.386
.model flat,stdcall
option casemap:none
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
include C:\bj\include\wininet.inc
includelib C:\bj\lib\wininet.lib
include C:\bj\include\windows.inc
include C:\bj\include\kernel32.inc
includelib C:\bj\lib\kernel32.lib
include C:\bj\include\user32.inc
includelib C:\bj\lib\user32.lib
.data
ClassName db "mj?l",0
AppName db "bj internetcheck v2.00",0
knapptext db "Kolla sida",0
button db "BUTTON",0
static db "STATIC",0
edit db "EDIT",0
static1text db "Skriv adress:",0
finns_ej db "Sidan fanns inte!",0
finns db "Sidan fanns!",0
titel db "helloj",0
edittext db "http://www.google.com",0
.DATA? ; Uninitialized data
hInstance HINSTANCE ? ; Instance handle of our program
CommandLine LPSTR ?
hwndButton HWND ?
hwndEdit HWND ?
hEdit HWND ?
adress db ?
error DWORD ?
.const
ButtonID equ 1
EditId equ 2
.code
start:
invoke GetModuleHandle, NULL
mov hInstance,eax

invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT ; call the main function
invoke ExitProcess, eax ; quit our program. The exit code is returned in eax from WinMain.

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX ; create local variables on stack
LOCAL msg:MSG
LOCAL hwnd:HWND

mov wc.cbSize,SIZEOF WNDCLASSEX ; fill values in members of wc
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,NULL
push hInstance
pop wc.hInstance
mov wc.hbrBackground,COLOR_WINDOW
mov wc.lpszMenuName,NULL
mov wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,NULL,IDI_APPLICATION
mov wc.hIcon,eax
mov wc.hIconSm,eax
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax
invoke RegisterClassEx, addr wc ; register our window class
invoke CreateWindowEx,NULL,\
ADDR ClassName,\
ADDR AppName,\
WS_OVERLAPPEDWINDOW,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
250,\
100,\
NULL,\
NULL,\
hInst,\
NULL
mov hwnd,eax
invoke ShowWindow, hwnd,CmdShow ; display our window on desktop
invoke UpdateWindow, hwnd ; refresh the client area

.WHILE TRUE ; Enter message loop
invoke GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDW
mov eax,msg.wParam ; return exit code in eax
ret
WinMain endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL buf[100]:BYTE
.IF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.ELSEIF uMsg==WM_CREATE
invoke CreateWindowEx,NULL, ADDR button,\
ADDR knapptext,\
WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON,\
0,36,140,25,hWnd,ButtonID,hInstance,NULL
mov hwndButton,eax
invoke CreateWindowEx,NULL, ADDR static, ADDR static1text,WS_CHILD or WS_VISIBLE,0,0,250,14,hWnd,1,hInstance,NULL
invoke CreateWindowEx,WS_EX_CLIENTEDGE, ADDR edit, ADDR edittext,WS_CHILD or

WS_VISIBLE,0,15,250,20,hWnd,EditId,hInstance,NULL
mov hwndEdit,eax
.ELSEIF uMsg==WM_COMMAND
mov eax,wParam
.IF ax==ButtonID
invoke GetDlgItemText,hWnd,EditId,addr buf,sizeof buf

invoke InternetCheckConnection,ADDR buf,1,0

.IF (!eax)
invoke MessageBox,NULL,ADDR finns_ej,ADDR titel,MB_OK
.ELSE
invoke MessageBox,NULL,ADDR finns,ADDR titel,MB_OK
.ENDIF
.ENDIF
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam ; Default message processing
ret
.ENDIF
xor eax,eax
ret
WndProc endp
end start
Posted on 2003-08-07 08:01:05 by bj1500
It worked OK for me. Strange.

--*
Jag hade inga problem med din kod, fungerade perfekt. Har du kollat din internetanslutning?
Posted on 2003-08-07 08:28:19 by Delight
yes.. ih ave done that....very strange..
i'm just trying to translate my C++ program... who are in 156kb.. in assmbler it is 4kb with same functions :D
Posted on 2003-08-07 09:11:48 by bj1500