Solved

MFC versus winsock2.h

Posted on 2001-06-30
4
1,409 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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.

896 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

15 Experts available now in Live!

Get 1:1 Help Now