Solved

MFC versus winsock2.h

Posted on 2001-06-30
4
1,422 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
ID: 6241254
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
ID: 6241261
>>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
ID: 6241262
>>#include <afxsock.h>

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

Author Comment

by:kung
ID: 6241950

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

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
cat dog challenge 18 127
Named range not carried over 10 65
post4 challenge 28 104
wordappend challenge 8 201
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

828 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