winsock problem

Reply

Join Date: Jul 2007
Posts: 16
Reputation: m_meena is an unknown quantity at this point 
Solved Threads: 0
m_meena m_meena is offline Offline
Newbie Poster

winsock problem

 
0
  #1
Jul 10th, 2007
Hi,

On building a windows service, i m getting the 57 errors and 11 warnings. All the errors are about structure redefinition. Given below are some of them.
:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\winsock2.h(112) : error C2011: 'fd_set' : 'struct' type redefinition
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\winsock2.h(147) : warning C4005: 'FD_SET' : macro redefinition
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\winsock.h(88) : see previous definition of 'FD_SET'
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\winsock2.h(156) : error C2011: 'timeval' : 'struct' type redefinition
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\winsock2.h(212) : error C2011: 'hostent' : 'struct' type redefinition
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\winsock2.h(225) : error C2011: 'netent' : 'struct' type redefinition
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\winsock2.h(232) : error C2011: 'servent' : 'struct' type redefinition
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\winsock2.h(244) : error C2011: 'protoent' : 'struct' type redefinition
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\winsock2.h(400) : error C2011: 'sockaddr_in' : 'struct' type redefinition
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\winsock2.h(410) : error C2011: 'WSAData' : 'struct' type redefinition
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\winsock2.h(470) : warning C4005: 'SO_DONTLINGER' : macro redefinition
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\winsock.h(411) : see previous definition of 'SO_DONTLINGER'
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\winsock2.h(527) : warning C4005: 'AF_IPX' : macro redefinition
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\winsock.h(469) : see previous definition of 'AF_IPX'

I have checked in the code, only winsock2.h is included. but from where winsock.h is getting included, i m not able to track. Also, windows.h is not included in the code. if i remove winsock2.h and include winsock.h then errors are thrown for the structures 'WSOVERLAPPED' used in the code.

Any pointers for the same????
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,851
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: winsock problem

 
0
  #2
Jul 10th, 2007
IIRC, it's
  1. #include <winsock2.h>
  2. #include <windows.h>
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 16
Reputation: m_meena is an unknown quantity at this point 
Solved Threads: 0
m_meena m_meena is offline Offline
Newbie Poster

Re: winsock problem

 
0
  #3
Jul 10th, 2007
hi,

do u mean to include windows.h after winsock2.h??
i tried that also but still the errors exist.
winsock2.h itself prevents the inclusion of winsock.h in windows.h.

i also tried using preprocessor macro WIN32_LEAN_AND_MEAN but then the complier shows error for strncpy(), wcscat() functions.

Why is the redefinition when the files are not included.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,851
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: winsock problem

 
0
  #4
Jul 10th, 2007
I was just going by this thread on another forum.
http://forums.devshed.com/c-programm...ms-456175.html


You could also post the first 10 or so lines (all your #includes) of a file which throws all these errors.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 16
Reputation: m_meena is an unknown quantity at this point 
Solved Threads: 0
m_meena m_meena is offline Offline
Newbie Poster

Re: winsock problem

 
0
  #5
Jul 10th, 2007
Hi,

I looked into winsock2.h where it prevents the inclusion of winsock.h in windows.h
#ifndef _WINSOCK2API_
#define _WINSOCK2API_
#define _WINSOCKAPI_ /* Prevent inclusion of winsock.h in windows.h */

then i checked windows.h. in that file it has included winsock.h without checking if WINSOCKAPI defined or not. so i modified windows.h as given below ( it should not be changed as its standard file but just a trial)
#ifndef _MAC
#include <winperf.h>
//to prevent inclusion of winsock.h. added ifndef and endif statements
#ifndef _WINSOCKAPI_
#include <winsock.h>
#endif


#endif

Now i get the followin errors.
error C2664: 'sprintf' : cannot convert parameter 1 from 'unsigned short [10]' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
XMLQuery.cpp
Communication Service\XMLQuery.cpp(2488) : error C2664: 'wcscat' : cannot convert parameter 2 from 'char [12]' to 'const unsigned short *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Communication Service\XMLQuery.cpp(2490) : error C2664: 'wcscat' : cannot convert parameter 2 from 'char [5]' to 'const unsigned short *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Communication Service\XMLQuery.cpp(2526) : error C2664: 'strncpy' : cannot convert parameter 1 from 'unsigned short [100]' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Communication Service\XMLQuery.cpp(2613) : error C2664: 'wcstok' : cannot convert parameter 2 from 'char [2]' to 'const unsigned short *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Generating Code...
Error executing cl.exe.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,851
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: winsock problem

 
0
  #6
Jul 10th, 2007
> error C2664: 'sprintf' : cannot convert parameter 1 from 'unsigned short [10]' to 'char *
Lemme guess, you're passing a TCHAR to sprintf ?

http://msdn2.microsoft.com/en-us/library/ybk95axf(VS.80).aspx
Scroll down to "Generic-Text Routine Mappings"
Then use the TCHAR macro name for the functions you want to use which automatically resolve to the right function name whether you're compiling with or without UNICODE.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 16
Reputation: m_meena is an unknown quantity at this point 
Solved Threads: 0
m_meena m_meena is offline Offline
Newbie Poster

Re: winsock problem

 
0
  #7
Jul 10th, 2007
hi,

yes you are right. iam passing TCHAR to sprintf. but i dint get what you want to say about using the macro for tchar and all..
can you please explain it more..

thanks a lot!!
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,851
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: winsock problem

 
0
  #8
Jul 10th, 2007
Paste an example sprintf call or two, and I'll show you how to make it UNICODE friendly.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 16
Reputation: m_meena is an unknown quantity at this point 
Solved Threads: 0
m_meena m_meena is offline Offline
Newbie Poster

Re: winsock problem

 
0
  #9
Jul 10th, 2007
Hi,
Given below is the code snippet

BOOL CServiceControl::OpenLog()
{
TCHAR tsFileName[MAX_PATH];
SYSTEMTIME stSystemTime;
TCHAR tsNumber[10];

// Append the file and path
_tcscpy( tsFileName, m_szLogDirectory );
_tcscat( tsFileName, _T("\\") );
_tcscat( tsFileName, m_szLogFile );

// Get the System Time using the getsystem time function Get system time
// function will return the time in UTC format
GetLocalTime(&stSystemTime);

//////////////////////////////////////////////////////////////////////////////
// Append the date/time to the file name in order to create a unique file name
// for this log. Since the service is restarted at least once per day, or more
// often if it crashes or uses more than a specified memory threshold, this
// will make sure that there is a new log file for each run.
sprintf(tsNumber,"%02d",stSystemTime.wMonth);
_tcscat( tsFileName, tsNumber );
sprintf(tsNumber,"%02d",stSystemTime.wDay);
_tcscat( tsFileName, tsNumber );
sprintf(tsNumber,"%04d",stSystemTime.wYear);
_tcscat( tsFileName, tsNumber );
sprintf(tsNumber,"%02d",stSystemTime.wHour);
_tcscat( tsFileName, tsNumber );
sprintf(tsNumber,"%02d",stSystemTime.wMinute);
_tcscat( tsFileName, tsNumber );
_tcscat( tsFileName, _T(".txt") );
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,851
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: winsock problem

 
0
  #10
Jul 10th, 2007
Well you managed to use _tcscat, so why the trouble using _stprintf ? _stprintf(tsNumber,_T("%02d"),stSystemTime.wMinute);
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC