Можно ли зделать асинхронную работу с сукитами, не создавая окно? Т.е неиспользуя ресурсы и CreatWidow().. Так чтоб все летело в мою процедурку. Если это возможно то как?
Код (Text): .486 .model flat, stdcall option casemap :none include \masm32\include\windows.inc include \masm32\include\comctl32.inc include \masm32\include\masm32.inc include \masm32\include\user32.inc include \masm32\include\kernel32.inc include \masm32\include\msvcrt.inc include \masm32\include\comdlg32.inc include \masm32\include\shell32.inc include \masm32\include\ws2_32.inc includelib \masm32\lib\comctl32.lib includelib \masm32\lib\masm32.lib includelib \masm32\lib\user32.lib includelib \masm32\lib\kernel32.lib includelib \masm32\lib\msvcrt.lib includelib \masm32\lib\comdlg32.lib includelib \masm32\lib\shell32.lib includelib \masm32\lib\ws2_32.lib CreateSocketInformation proto :dword FreeSocketInformation proto :dword SendData proto :dword WSABUF struct len dd ? buf dd ? WSABUF ends SOCKET_INFORMATION struct Buffer db 8192 dup (?) DataBuf WSABUF <> Socket dd ? BytesSEND dd ? BytesRECV dd ? SOCKET_INFORMATION ends WSANETWORKEVENTS struct lNetworkEvents dd ? iErrorCode dd [FD_MAX_EVENTS] dup (?) WSANETWORKEVENTS ends .data? SocketArray dd 64 dup (?) EventArray dd 64 dup (?) EventTotal dd ? .data ddddgfgh db 1, 0, 8, 8 db 100 dup (0) .code start: call main invoke ExitProcess, 0 ;###################################################### main proc LOCAL Listen :dword LOCAL Accept :dword LOCAL InternetAddr : sockaddr_in LOCAL Event : dword LOCAL NetworkEvents : WSANETWORKEVENTS LOCAL wsaData : WSADATA LOCAL RetVal : dword LOCAL Flags : dword LOCAL RecvBytes : dword invoke WSAStartup, 202h, addr wsaData invoke socket, AF_INET, SOCK_STREAM, 0 mov Listen, eax invoke CreateSocketInformation, Listen mov ecx, EventTotal dec ecx mov edx, EventArray[ecx*4] invoke WSAEventSelect, Listen, edx, FD_ACCEPT or FD_CLOSE mov InternetAddr.sin_family, AF_INET invoke htonl, INADDR_ANY mov InternetAddr.sin_addr, eax invoke htons, 5000 mov InternetAddr.sin_port, ax invoke bind, Listen, addr InternetAddr, sizeof InternetAddr invoke listen, Listen, 5 .while (TRUE) invoke WSAWaitForMultipleEvents, EventTotal, addr EventArray, 0, -1, 0 mov Event, eax .if eax == INVALID_SOCKET ret .endif mov ebx, Event mov esi, SocketArray[ebx*4] invoke WSAEnumNetworkEvents, (SOCKET_INFORMATION ptr [esi]).Socket, EventArray[ebx*4], addr NetworkEvents .if eax == INVALID_SOCKET ret .endif lea edx, NetworkEvents mov eax, (WSANETWORKEVENTS ptr [edx]).lNetworkEvents ;---------------------------------------------------------- .if eax & FD_ACCEPT ;---------------------------------------------------------- lea ecx, (WSANETWORKEVENTS ptr [edx]).iErrorCode add ecx, FD_ACCEPT_BIT .if dword ptr [ecx] != 0 .break .endif invoke accept, (SOCKET_INFORMATION ptr [esi]).Socket, 0, 0 mov Accept, eax .if eax== INVALID_SOCKET .break .endif .if EventTotal > 64 invoke closesocket, Accept .break .endif invoke CreateSocketInformation, Accept mov ecx, EventTotal dec ecx mov edx, EventArray[ecx*4] invoke WSAEventSelect, Accept, edx, FD_READ or FD_WRITE or FD_CLOSE .if eax == SOCKET_ERROR ret .endif ;------------------------------------------------------ .elseif (NetworkEvents.lNetworkEvents & FD_READ ) ;------------------------------------------------------ .if (NetworkEvents.lNetworkEvents & FD_WRITE) && (NetworkEvents.iErrorCode[FD_WRITE_BIT] != 0) .break .endif mov ebx, Event mov esi, SocketArray[ebx*4] .if (dword ptr (SOCKET_INFORMATION ptr [esi]).BytesRECV == 0) lea edi, (SOCKET_INFORMATION ptr [esi]).DataBuf mov (WSABUF ptr [edi]).buf, esi mov (WSABUF ptr [edi]).len, 8192 mov Flags, 0 invoke WSARecv, (SOCKET_INFORMATION ptr [esi]).Socket, edi, 1, addr RecvBytes, addr Flags, NULL, NULL .if (eax == -1) invoke WSAGetLastError .if (eax!= WSAEWOULDBLOCK) invoke FreeSocketInformation, Event ret .endif .else mov eax, RecvBytes mov (SOCKET_INFORMATION ptr [esi]).BytesRECV, eax .endif .endif mov ebx, Event mov esi, SocketArray[ebx*4] lea edi, (SOCKET_INFORMATION ptr [esi]).DataBuf mov (WSABUF ptr [edi]).buf, esi mov (WSABUF ptr [edi]).len, ecx mov (SOCKET_INFORMATION ptr [esi]).BytesRECV, 0 invoke SendData, Event ;----------------------------------------------------- .elseif (NetworkEvents.lNetworkEvents & FD_CLOSE) ;----------------------------------------------------- .if (NetworkEvents.iErrorCode[FD_CLOSE_BIT] != 0) .break .endif invoke FreeSocketInformation, Event .endif .endw ret main endp ;###################################################### CreateSocketInformation proc uses esi hSockt:dword invoke WSACreateEvent mov ecx, EventTotal mov EventArray[ecx*4], eax .if (eax == 0) mov eax, 0 ret .endif invoke GlobalAlloc, GPTR, sizeof SOCKET_INFORMATION mov esi, eax .if (eax == 0) mov eax, 0 ret .endif mov eax, hSockt mov (SOCKET_INFORMATION ptr [esi]).Socket, eax mov (SOCKET_INFORMATION ptr [esi]).BytesSEND, 0 mov (SOCKET_INFORMATION ptr [esi]).BytesRECV, 0 mov ecx, EventTotal mov SocketArray[ecx*4], esi inc EventTotal mov eax, 1 ret CreateSocketInformation endp ;###################################################### FreeSocketInformation proc Event:dword mov ebx, Event mov esi, SocketArray[ebx*4] invoke closesocket, (SOCKET_INFORMATION ptr [esi]).Socket invoke GlobalFree, esi invoke WSACloseEvent, EventArray[ebx*4] .while ebx < EventTotal mov eax, EventArray[ebx*4+1] mov EventArray[ebx], eax mov eax, SocketArray[ebx*4 + 1] mov SocketArray[ebx*4], eax inc ebx .endw dec EventTotal ret FreeSocketInformation endp ;###################################################### SendData proc uses edi esi ebx pEvent:dword LOCAL SendBytes:dword mov ebx, pEvent mov esi, SocketArray[ebx*4] invoke WSASend, (SOCKET_INFORMATION ptr [esi]).Socket, addr (SOCKET_INFORMATION ptr [esi]).DataBuf, 1, addr SendBytes, 0, NULL, NULL .if eax == SOCKET_ERROR invoke WSAGetLastError .if eax != WSAEWOULDBLOCK invoke FreeSocketInformation, pEvent ret .endif .else mov eax, SendBytes mov (SOCKET_INFORMATION ptr [esi]).BytesSEND, eax .endif ret SendData endp ;################################################# end start
Добрый день откопал старую тему, и есть вопросы: 1. зачем нужна эта строка: mov (WSABUF ptr [edi]).buf, esi если мы функции даем буфер скуда записать данные?! invoke WSARecv, (SOCKET_INFORMATION ptr [esi]).Socket, edi, 1, addr RecvBytes, addr Flags, NULL, NULL 2. to Vovane взял Твой исходник откомпилировал, все нормально перенес в свой код у меня в этой строке дает ошибку: invalid instruction operands