Solved

Using Winsock in a DLL

Posted on 2000-04-27
4
351 Views
Last Modified: 2010-08-05
Hi,

I am trying to write a simple socket program for a C++ DLL. I am getting the errors

c:\program files\microsoft visual studio\vc98\include\winsock.h(520) : error C2011: 'linger' : 'struct' type redefinition

I have the following code to protect redefinition in all .h files:

#ifndef __WIN32_H
#define __WIN32_H

#include <winsock.h>
#include .....

#endif

I am also getting the following warnings. They seem very odd to me

c:\program files\microsoft visual studio\vc98\include\winsock.h(551) : warning C4005: 'FD_READ' : macro redefinition
        c:\program files\microsoft visual studio\vc98\include\winsock2.h(598) : see previous definition of 'FD_READ'  

I have the ws2_32.lib in the project-link tab

please help :)

Sonya Klose


0
Comment
Question by:sklose
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
pellep earned 60 total points
ID: 2754429
Try to include winsock2.h instead of winsock.h
Also, i beleive that if you include windows.h, it will include winsock headers for you.
0
 
LVL 4

Expert Comment

by:saurabh_dasgupta
ID: 2754458
If you are linking with ws2_32.lib then you better include WINSOCK2.H

I think that, the problem mentioned by you is occurring because, somewhere you
are including both WINSOCK.H and WINSOCK2.H . Only one of them can be included.

#include <WINSOCK.H>
#include <WINSOCK.H>
will work fine , but

#include <WINSOCK.H> //this could be be //in some other header file , and that //file is getting included here
#include <WINSOCK2.H>
will lead to errors similar to what you have stated.


Hope this helps.
0
 

Author Comment

by:sklose
ID: 2757507
Thankyou!!!!
0
 

Author Comment

by:sklose
ID: 2757521
It works now!

windows.h sure does include winsock.h
All I had to do was replace winsock.h with windows.h and presto it work!

Thanks a million
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

707 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