Solved

MFC versus winsock2.h

Posted on 2001-06-30
4
1,398 Views
Last Modified: 2013-11-20
Hi

I am using Visual C++ 6.0
I have made a "hello world" program via the wizard
I am doing

#include "stdafx.h"
#include "resource.h"
#define WIN32_LEAN_AND_MEAN
#include <process.h>
#include <winsock2.h>



I want to use the "select file" dialog and therefore
added the code

 CString FileFilter = CString("txt files (*.txt)|*.txt")
        + CString("All files (*.*)|*.*||");

 CFileDialog FileDlg ( TRUE, NULL, NULL,
  OFN_PATHMUSTEXIST | OFN_HIDEREADONLY,
  FileFilter);

This gave the following error

:\TEMP\Byggen\SMS\SMS\SMS.cpp(380) : error C2065: 'CString' : undeclared identifier
C:\TEMP\Byggen\SMS\SMS\SMS.cpp(380) : error C2146: syntax error : missing ';' before identifier 'FileFilter'


therfore I included the

#include <afxdlgs.h>

But this gave me another problem

c:\program files\microsoft visual studio\vc98\mfc\include\afxv_w32.h(14) : fatal error C1189: #error :  WINDOWS.H already included.  MFC apps must n

but the winsock2.h do contain a #include "windows.h"


My question is

should I move over to afxdlgs.h and remove the #include "winsock2.h", if so what should I use instead.
What should I use instead of winsock2.h ?








0
Comment
Question by:kung
  • 2
4 Comments
 
LVL 12

Expert Comment

by:migel
Comment Utility
Hi!
did you select MFC application in the wizard. Excuse me for stupped q. but it come first.
also you can directly say that your MFC APP will use WinSockets by selecting "Windows socket" check box in the 4 wizard step.
0
 
LVL 86

Accepted Solution

by:
jkr earned 300 total points
Comment Utility
>>What should I use instead of winsock2.h ?

MFC has its own header file for windows sockets suport - try adding

#include <afxsock.h>

to your 'stdafx.h"
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
>>#include <afxsock.h>

That's what the wizerd does when following migel's suggestion :o)
0
 

Author Comment

by:kung
Comment Utility

That helped, thanks, however to include
#include <afx.h>
before
#include <winsock2.h>
helped aswell
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now