MFC, Winsock 1 & 2 and ping

Posted on 1999-11-16
Medium Priority
Last Modified: 2013-12-23
I have an MFC app.  I need it to be able to ping a remote machine.  I have the sample ping.c code from the MSDN but it uses winsock2.  But, MFC uses winsock 1.1 (I believe).  How do I get MFC to work with winsock2 or how to I get a ping function to work with winsock 1.1 (the ping sample uses WSASocket() which is not available under 1.1).  Is there sample ping code that runs under winsock 1.1 or a way to convince MFC to use winsock 2?

Thanks,  Scott.
Question by:staggart
  • 2
LVL 32

Expert Comment

ID: 2213726
MFC is not bound to a particular version of WINSOCK.  That depends on the WINSOCK library you have installed on your system.  Win98 and NT4.0 use WINSOCK 2 by default.  Win95 can have either.  It shipped with WINSOCK 1 but you can download and install the update.

Author Comment

ID: 2214588
That may be, but when you compile an MFC app, you end up with the winsock.h file which cleary states it is the 1.1 version.  Also, the default link ends up with the 1.1 library which means you can't get to some of the 2.0 functions.  Therefore, while 2.0 may be installed in your system, you can't easily get to it from MFC.  My question clearly stated that I want access to the 2.0 library from MFC.  That's what I need.  If you know the "tricks" to get MFC to play the 2.0 games (bothg compileing and linking issues resolved), I will award youthe points.

LVL 32

Accepted Solution

jhance earned 400 total points
ID: 2214714
>when you compile an MFC app, you end >up with the winsock.h file which >cleary states it is the 1.1 version

This is your fault.  Get the V2.0 WINSOCK2.H from the Windows SDK and use it instead.  This has NOTHING to do with MFC.

>the default link ends up with the 1.1 >library which means you can't get to >some of the 2.0 functions

Not true.  If you have installed WINSOCK 2 on your system, then the WINSOCK 2 library is the ONLY one available as it replaces the WINSOCK 1 DLL.  Since it's a SUPERSET of WINSOCK 1, your existing apps don't break (at least they don't always break.)

You can explicitly link using ws2_32.lib and have access to any of the WINSOCK 2 functions.

>while 2.0 may be installed in your >system, you can't easily get to it >from MFC

I think you are mixed up about the relationship between MFC and WINSOCK.  If you want to use WINSOCK 2 calls, install the WINSOCK 2 library and call your WINSOCK 2 functions.  MFC doesn't care as it only provides classes that make use of high level WINSOCK functions which are all supported in WINSOCK 1.

To call WSASocket() just do it...


Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

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

A common practice in small networks is making file sharing easy which works extremely well when intra-network security is not an issue. In essence, everyone, that is "Everyone", is given access to all of the shared files - often the entire C: drive …
We recently endured a series of broadcast storms that caused our ISP to shut us down for brief periods of time. After going through a multitude of tests, we determined that the issue was related to Intel NIC drivers on some new HP desktop computers …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

599 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