MFC, Winsock 1 & 2 and ping

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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
staggartAuthor Commented:
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.

>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...


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Networking

From novice to tech pro — start learning today.