[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

assertion fail

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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 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

830 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