Solved

assertion fail

Posted on 2003-11-16
1
504 Views
Last Modified: 2008-02-01
The following code when built (0 error, 0 warning) gives a message:
Debug Assertion failed! program C:\...\..exe, file: afxwin1.inl line:19

#include "stdafx.h"
#include <afxsock.h>
#include <afxwin.h>

in WinMain:
{
      CString serverName="mail.earthlink.net";
      UINT nPort=25;
       CSocket socket;
      AfxSocketInit();

      if(!socket.Create())return 1;
      if(!socket.Connect(serverName, nPort))return 1;
      return 0;
}

If I comment out the "create()" line, I don't get that message..

What's the problem?
0
Comment
Question by:samliam
[X]
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
1 Comment
 
LVL 48

Accepted Solution

by:
AlexFM earned 50 total points
ID: 9757937
Since you are using the MFC CSocket class, you should initialize MFC properly. You can learn this creating the console application with MFC support using Application Wizard.
Make the following changes:

#include "stdafx.h"
#include <afxsock.h>
#include <afxwin.h>

CWinApp theApp;       // add this line


int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
    // Add these lines to WinMain start
    if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
    {
        return 1;
    }


    CString serverName="mail.earthlink.net";
    UINT nPort=25;
     CSocket socket;
    AfxSocketInit();

    if(!socket.Create())return 1;
    if(!socket.Connect(serverName, nPort))return 1;
    return 0;
}
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
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.

688 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