| | |
winsock problem
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2007
Posts: 16
Reputation:
Solved Threads: 0
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????
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????
•
•
Join Date: Jul 2007
Posts: 16
Reputation:
Solved Threads: 0
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.
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.
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.
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.
•
•
Join Date: Jul 2007
Posts: 16
Reputation:
Solved Threads: 0
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.
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.
> 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.
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.
•
•
Join Date: Jul 2007
Posts: 16
Reputation:
Solved Threads: 0
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") );
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") );
![]() |
Similar Threads
- could winsock be the problem (Windows NT / 2000 / XP)
- Winsock Problem (Visual Basic 4 / 5 / 6)
Other Threads in the C++ Forum
- Previous Thread: Reducing floating point numbers.
- Next Thread: Programming Problem
| Thread Tools | Search this Thread |
api array based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






