Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
AfxSocketInit
TRY
Collapse the table of content
Expand the table of content

AfxSocketInit

Call this function in your CWinApp::InitInstance override to initialize Windows Sockets.

BOOL AfxSocketInit( 
   WSADATA* lpwsaData = NULL  
);

lpwsaData

A pointer to a WSADATA structure. If lpwsaData is not equal to NULL, then the address of the WSADATA structure is filled by the call to WSAStartup. This function also ensures that WSACleanup is called for you before the application terminates.

Nonzero if the function is successful; otherwise 0.

When using MFC sockets in secondary threads in a statically linked MFC application, you must call AfxSocketInit in each thread that uses sockets to initialize the socket libraries. By default, AfxSocketInit is called only in the primary thread.

Code

if (!AfxSocketInit())
{
   AfxMessageBox(_T("Failed to Initialize Sockets"), MB_OK | MB_ICONSTOP);
   return FALSE;
}

Header: afxsock.h

Community Additions

ADD
Show:
© 2015 Microsoft