Solved

assertion fail

Posted on 2003-11-16
1
500 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
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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Find Visual Studio Tools 2 105
convert char array to number in c 5 85
Arduino EDI - Programming language 3 95
Problem with SqlConnection 4 171
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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…
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 learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

832 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