Could you look at this snippet and tell me what is wrong?

.code
...
invoke WSAStartup, 0202h, addr wsadata ; OK
.if eax == SOCKET_ERROR
; error
int 3
ret
.endif
invoke socket, AF_INET, SOCK_STREAM, 0 ; OK
.if eax == INVALID_SOCKET
; error
int 3
ret
.endif
mov , eax
invoke WSAAsyncSelect, eax, 0, WM_SOCKET, FD_CONNECT or FD_READ ; ALWAYS SOCKET_ERROR
.if eax == SOCKET_ERROR
; error
int 3
ret
.endif


I have Win98...
Posted on 2002-11-10 14:29:33 by slonik
Well, I believe you should pass in the handle of the window and not 0. Other than that I would look at GetLastError and see what the error returned is.

Another thing...I am still learning assembly but why are you using the 'int 3' .. you said you are using Win98 so why use that, and what does it do?

Also why mov , eax why mess with pointers dealing with one variable?

Again I am still a newb
Posted on 2002-11-10 17:18:00 by gorshing
Slonik,
Why do you use the instruction 'int 3'? Do you use it for some
debugging reasons?

Anyway, when you call the 'WSAAsyncSelect' api you should also
specify the handle to the window wich is to recieve those messages(hWnd).

This is probably the error message you would have seen by calling 'WSAGetLastError':
ERROR: WSAEINVAL
ERROR.DESC: Indicates that one of the specified parameters was invalid such as the window handle not referring to an existing window, or the specified socket is in an invalid state.

invoke WSAAsyncSelect, eax, hWnd, WM_SOCKET, FD_CONNECT or FD_READ
Posted on 2002-11-10 17:54:39 by natas
Yes, you are right. Without a valid handle it won't work. Now it is OK. Thanks.
I use "int 3" for debugging purposes only. It much more simple to write 'int 3' instead of 'invoke MessageBoxA, bla, addr szERROR, addr bla, bla' for example. When error occurs debugger breaks and I know where is something wrong... That's all.
I use 'mov , eax' because this handle has to be stored as it is needed for many other APIs.
Thanks again for reply.
Posted on 2002-11-11 05:13:18 by slonik
Correct me if I am wrong but doesn't "mov , eax" that puts eax in the address that socket_ contains? So you are messing with pointers.. So why not just use mov socket_, eax

That is what I was confused about.
Posted on 2002-11-11 10:30:29 by gorshing
Well, I am not sure whether there is any difference between these two instructions, but since everything is working fine... :)
I think it would be like you said if I used "mov dword ptr , eax" instruction...
Posted on 2002-11-11 12:10:35 by slonik

Correct me if I am wrong but doesn't "mov , eax" that puts eax in the address that socket_ contains? So you are messing with pointers.. So why not just use mov socket_, eax


mov , eax is exactly the same as mov socket_, eax, which can be confusing. MASM does not require you to use brackets around a variable to indicate memory access :rolleyes:.

Besides, mov , eax could never mean "*socket_ = eax" (in C), as there's no mov instruction that allows that kind of indirection (only with registers, like mov , eax).

Thomas
Posted on 2002-11-11 12:39:01 by Thomas
Thanks for correcting me
Posted on 2002-11-11 13:06:56 by gorshing
Yes, the problem is that you are passing an invalid HWND to WSAAsyncSelect.
Just a comment:
Calling WSAStartup function will return NULL if every was OK. Or will return 3 kind of errors that you can find in the Windows Socket API.
In your code you must check if eax!=NULL then do whatever you want..."int 3"...etc...
(do not call WSAGetLastError because the library you are asking was not loaded)
Posted on 2002-11-14 09:33:07 by Kecol