I have made a dll which contain this function:
Then later in another function i have:
;===================================================================== ; LoadDll() ;===================================================================== LoadDll PROC lpLoadInfo:DWORD invoke WSAStartup, 101h, ADDR ws_data ret LoadDll ENDP
and guess what, socket() fails with WSAEINVAL on W2K whilst on 95/98 and ME it works without a problem. Does ANYONE know why??
invoke socket, PF_INET, SOCK_DGRAM, NULL
Well I did this as a test :- WsaData WSADATA > invoke WSAStartup,101h,addr WsaData ; startup WinSock invoke socket,AF_INET,SOCK_DGRAM,0 ; open a socket cmp eax,WSAEINVAL jne allok ret allok: and it was ok, give that a go. umbongo
That's because socket() itself does not return WSAEINVAL. It returns INVALID_SOCKET which means you should call WSAGetLastError (which returns WSAEINVAL) try:
Then tell me if it still works...
invoke WSAStartup,101h,addr WsaData invoke socket, AF_INET, SOCK_DGRAM, 0 .IF eax == INVALID_SOCKET invoke WSAGetLastError ... .ELSE ... .ENDIF
All my TCP/IP stuff works on W2K, it's just the UDP/IP i have problems with. But i have yet to test my latest version so it might be fixed. I dissasembled a program i know uses UDP and that i know works on W2K, and the socket call is exactly the same as mine. Also the WSAStartup call was the same. It might have had something to do with me having the two calls in different dll functions. We'll see...
Having the call in different DLLs might be the problem, I'd keep your WSAStartup and socket calls together. If you have a function called OpenSocket and CloseSocket, one can call WSAStartup the other WSAShutdown(?) I know they are reference counted so calling it more than once doesn't matter. Just as long as the calls are matched. To be honest, I don't think the WSAShutdown calls matter, Windows will do it for you if you do not bother it's just good practice to do it. umbongo
I found out what the problem is (sort of), but i don't think it's fixable. The dll i wrote is written to be called by mIRC's $dll() identifier. On Win95/98/ME it still works if i remove the WSAStarup/WSACleanup calls from the dll, because apparently it is OK if the calling process has already issued them. On Win2k it doesn't work if i have them in or not. So my conclusion is that it is either a mIRC or Win2k issue that i can't fix. My bet is on Win2k. As a test i wrote a simple .exe that opens an UDP socket and it ran without a problem on Win2k so now im gonna write a program that calls my dll (instead of having mIRC to call it) and see if still works.