Solved

MFC versus winsock2.h

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Installing Microsoft R server on REDHAT or SUSE Linux 4 137
if loop in java 3 142
firstChar challenge 13 115
Detect file exist or not 3 157
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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. …
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.

778 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