Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Error when create socket

Posted on 1999-07-19
Medium Priority
Last Modified: 2006-11-17
 I'm using MSVC6.0 . I'm tring do make a client app (I use sample Chatter as model) but when I can't create the socket:
      m_pSocket = new CChatSocket(this);
      if (!m_pSocket->Create())
            delete m_pSocket;
            m_pSocket = NULL;
            AfxMessageBox("Socket can't be create!");
            return FALSE;
because it's an error at runtime(I got i=10093) and in help i've found 10093 = WSANOTINITIALISED .
  Can anyone help?
Question by:goyam
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 22

Expert Comment

ID: 1200481
This error is returned when you use a socket function before WSAStartup() has been called.  Do you call WSAStartup()?   (I'm not sure if you have to however, as MFC may do this for you.)

Author Comment

ID: 1200482
No, I don't call WSAStartup(), because I've understood that MFC will (just as I said before I use sample chatter as model and I copyed the socket class, and on OnNewDocument I call a function to create the socket, function that calls CSocket::Create.)
LVL 86

Accepted Solution

jkr earned 200 total points
ID: 1200483
nietod is basically right, in a 'normal' Win32 app you'd use

    WORD            wVersionRequested;
    WSADATA         wsaData;

    wVersionRequested   =   MAKEWORD(   1,  1);

    if  (   nErr    =   WSAStartup  (   wVersionRequested,  &wsaData))
            //  error

When using MFC, make sure to call 'AfxSocketInit()' (which will also maintain the MFC state):

(From the docs)

BOOL AfxSocketInit( WSADATA* lpwsaData = NULL );

Return Value

Nonzero if the function is successful; otherwise 0.


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.


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

See Also   CWinApp::InitInstance

NOTE that you'll have to place this call explicitly in your 'CWinApp::InitInstance()' - MFC doesn't do that automatically!

Author Comment

ID: 1200484
Thanks a lot,

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question