News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

About WSAStartup

Started by ragdogz, February 06, 2009, 05:01:14 PM

Previous topic - Next topic

ragdogz

Hi, i made a program using 2 winsocks. and i wrote 2 codes as exercise and both of them are working properly. but i'm stil confusing with my codes.

1st code:

.data
wsadata WSADATA <>

.code
start:
...
...

DlgProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.if uMsg==WM_INITDIALOG
...
...
invoke WSAStartup, 2,addr wsadata
.if eax!=NULL
invoke SetDlgItemText,hwwnd,TEXT_MAIN,addr MsgError1
.else
invoke WinsockProc01,addr Address,Port,hWnd
invoke WinsockProc02,addr Address,Port,hWnd
.endif
...
...
DlgProc endp


2nd code:

.data
wsadata1 WSADATA <>
wsadata2 WSADATA <>

.code
start:
...
...

DlgProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.if uMsg==WM_INITDIALOG
...
...
invoke WSAStartup, 2,addr wsadata1
.if eax!=NULL
invoke SetDlgItemText,hwwnd,TEXT_MAIN,addr MsgError1
.else
invoke WinsockProc01,addr Address,Port,hWnd
.endif

invoke WSAStartup, 2,addr wsadata2
.if eax!=NULL
invoke SetDlgItemText,hwwnd,TEXT_MAIN,addr MsgError1
.else
invoke WinsockProc02,addr Address,Port,hWnd
.endif
...
...
DlgProc endp


WinsockProc in my code is the procedure for creating and connecting winsock. more winsocks i use, then the output exe file from 1st code is smallest than 2nd one..
as far as i know, WSAStartup is for initializing wsock32.dll or ws2_32.dll right? so why do i use it repeatedly in 2nd code? the reason is because Iczelion said this:

QuoteSay, if you call WSAStartup three times, you must also call WSACleanup three times as well else the winsock library will not be able to free any unused resource

that's why i use WSAStartup several times..
i wonder, which 1 is the right code and the most efficient?
thx..

ragdogz

after several times and hours in testing, now i decide to use my 1st code since there's nothing wrong with the testing. and also cross my mind that why i have to call WSAStartup several times if i only need to initialize winsock library once. now i think my 1st code is the right one..

but stil i'm confused with what iczelion said..
actually, in what condition do we have to call WSAStartup three or several times?