Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

assertion fail

Posted on 2003-11-16
1
Medium Priority
?
506 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 200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Suggested Courses

649 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