Microsoft KB Archive/155133

= PRB: ClassWizard Doesn't Bring in Proper Header File =

Article ID: 155133

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 4.2 Enterprise Edition

 Microsoft Visual C++ 5.0 Enterprise Edition

 Microsoft Visual C++ 6.0 Enterprise Edition

 Microsoft Visual C++ 4.2 Professional Edition</li></ul>

 Microsoft Visual C++ 5.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q155133

<div class="symptoms_section">

SYMPTOMS
After creating a new class derived from either CSocket or CAsyncSocket using the ClassWizard, one of the following errors occur during compilation:

<pre class="fixed_text">  error C2504: 'CSocket' : base class undefined error C2504: 'CAsyncSocket' : base class undefined

<div class="cause_section">

CAUSE
ClassWizard allows you to derive a class directly from CSocket or CAsyncSocket; however, it does not pull in the required header file where these classes are declared. Therefore, the compiler displays an error message reflecting that CSocket or CAsyncSocket was not defined.

<div class="resolution_section">

RESOLUTION
Include the header file, afxsock.h, into your project, preferably in your project's StdAfx.h header file: ...    #include <afxsock.h>  //MFC support for Sockets ...

<div class="status_section">

STATUS
Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article.

<div class="moreinformation_section">

MORE INFORMATION
The header file, afxsock.h, contains the class definitions for CAsyncSocket and CSocket. If you are using these classes or any classes that are derived from these classes, you must make sure to include afxsock.h in your project. Also note that if you use AppWizard to start your project and select the Socket Support option on the fourth page of the wizard, you will automatically get afxsock.h inserted into your StdAfx.h file. In addition, you will get the function call, AfxSocketInit, inserted into your project. This is very important because you must make a call to AfxSocketInit if you want to use Sockets in your MFC application. This function is usually called from your InitInstance method of your CWinApp derived object. BOOL CMyApp::InitInstance {

if (!AfxSocketInit) {            AfxMessageBox("Socket Initialization Failed"); return FALSE; }

...  }

Keywords: kbcode kbprb kbwinsock kbwizard KB155133

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.