Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IP sort in clistctrl

Status
Not open for further replies.

kaya17

Programmer
Feb 9, 2004
78
SG
hi,

i found this website to do the listctrol column sorting. for the IP sort, a person pasted something like this,

//********************
Ok here's code to make it sort IP Addresses. Note: this will make the code depend on the winsock libraries for inet_addr, you could re-implement inet_addr yourself if you wanted to avoid this dependencies. To the code...

You need to add these 2 functions to SortListCtrl.cpp:

bool IsIPAddr(LPCSTR pszText)
{
ASSERT_VALID_STRING( pszText );

if (inet_addr(pszText) != INADDR_NONE)
return true;
else
return false;
}

int IPAddrCompare(LPCTSTR pszIP1, LPCTSTR pszIP2)
{
ASSERT_VALID_STRING( pszIP1 );
ASSERT_VALID_STRING( pszIP2 );

long lIP1 = inet_addr(pszIP1);
long lIP2 = inet_addr(pszIP2);

if( lIP1 < lIP2 )
return -1;
if( lIP1 > lIP2 )
return 1;

return 0;
}

then you need to change the CSortListCtrl::CompareFunction function comparison part to:

if( IsNumber( pszText1 ) )
return pListCtrl->m_bSortAscending ? NumberCompare( pszText1, pszText2 ) : NumberCompare( pszText2, pszText1 );
else if (IsIPAddr(pszText1))
return pListCtrl->m_bSortAscending ? IPAddrCompare(pszText1, pszText2) : IPAddrCompare(pszText2, pszText1);
else if( IsDate( pszText1 ) )
return pListCtrl->m_bSortAscending ? DateCompare( pszText1, pszText2 ) : DateCompare( pszText2, pszText1 );
else
// text.
return pListCtrl->m_bSortAscending ? lstrcmp( pszText1, pszText2 ) : lstrcmp( pszText2, pszText1 );



could anyone tell me how to include the winsock library, or give me some sample code to write the inet_address the person suggested?

thanks so much!

regards,
kaya
 
- Include the header file 'winsock2.h' into the .cpp file where you want to use winsock functions
- Add the library 'ws2_32.lib' to your project (Project -> Settings -> Link -> Object/library modules)

Standa K.
 
hi, i followed ur instruction, but still it cannot work. there are 62 errors and 11 warnings come out...
 
--------------------Configuration: EIFScan - Win32 Debug--------------------
Compiling...
SortListCtrl.cpp
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(99) : error C2011: 'fd_set' : 'struct' type redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(134) : warning C4005: 'FD_SET' : macro redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(83) : see previous definition of 'FD_SET'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(143) : error C2011: 'timeval' : 'struct' type redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(199) : error C2011: 'hostent' : 'struct' type redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(212) : error C2011: 'netent' : 'struct' type redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(219) : error C2011: 'servent' : 'struct' type redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(226) : error C2011: 'protoent' : 'struct' type redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(310) : error C2011: 'in_addr' : 'struct' type redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(368) : error C2011: 'sockaddr_in' : 'struct' type redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(378) : error C2011: 'WSAData' : 'struct' type redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(430) : warning C4005: 'SO_DONTLINGER' : macro redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(391) : see previous definition of 'SO_DONTLINGER'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(483) : warning C4005: 'AF_IPX' : macro redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(449) : see previous definition of 'AF_IPX'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(506) : warning C4005: 'AF_MAX' : macro redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(468) : see previous definition of 'AF_MAX'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(512) : error C2011: 'sockaddr' : 'struct' type redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(521) : error C2011: 'sockproto' : 'struct' type redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(560) : error C2011: 'linger' : 'struct' type redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(573) : warning C4005: 'SOMAXCONN' : macro redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(533) : see previous definition of 'SOMAXCONN'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(598) : warning C4005: 'FD_READ' : macro redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(551) : see previous definition of 'FD_READ'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(601) : warning C4005: 'FD_WRITE' : macro redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(552) : see previous definition of 'FD_WRITE'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(604) : warning C4005: 'FD_OOB' : macro redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(553) : see previous definition of 'FD_OOB'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(607) : warning C4005: 'FD_ACCEPT' : macro redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(554) : see previous definition of 'FD_ACCEPT'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(610) : warning C4005: 'FD_CONNECT' : macro redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(555) : see previous definition of 'FD_CONNECT'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(613) : warning C4005: 'FD_CLOSE' : macro redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(556) : see previous definition of 'FD_CLOSE'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(1427) : error C2375: 'accept' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(707) : see declaration of 'accept'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(1448) : error C2375: 'bind' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(710) : see declaration of 'bind'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(1467) : error C2375: 'closesocket' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(712) : see declaration of 'closesocket'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(1486) : error C2375: 'connect' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(714) : see declaration of 'connect'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(1507) : error C2375: 'ioctlsocket' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(716) : see declaration of 'ioctlsocket'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(1528) : error C2375: 'getpeername' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(718) : see declaration of 'getpeername'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(1549) : error C2375: 'getsockname' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(721) : see declaration of 'getsockname'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(1572) : error C2375: 'getsockopt' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(724) : see declaration of 'getsockopt'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(1593) : error C2375: 'htonl' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(727) : see declaration of 'htonl'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(1610) : error C2375: 'htons' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(729) : see declaration of 'htons'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(1627) : error C2375: 'inet_addr' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(731) : see declaration of 'inet_addr'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(1644) : error C2375: 'inet_ntoa' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(733) : see declaration of 'inet_ntoa'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(1662) : error C2375: 'listen' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(735) : see declaration of 'listen'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(1680) : error C2375: 'ntohl' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(737) : see declaration of 'ntohl'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(1697) : error C2375: 'ntohs' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(739) : see declaration of 'ntohs'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(1717) : error C2375: 'recv' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(741) : see declaration of 'recv'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(1742) : error C2375: 'recvfrom' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(743) : see declaration of 'recvfrom'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(1768) : error C2375: 'select' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(746) : see declaration of 'select'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(1792) : error C2375: 'send' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(749) : see declaration of 'send'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(1817) : error C2375: 'sendto' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(751) : see declaration of 'sendto'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(1843) : error C2375: 'setsockopt' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(754) : see declaration of 'setsockopt'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(1865) : error C2375: 'shutdown' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(757) : see declaration of 'shutdown'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(1885) : error C2375: 'socket' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(759) : see declaration of 'socket'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(1908) : error C2375: 'gethostbyaddr' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(763) : see declaration of 'gethostbyaddr'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(1927) : error C2375: 'gethostbyname' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(766) : see declaration of 'gethostbyname'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(1945) : error C2375: 'gethostname' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(768) : see declaration of 'gethostname'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(1964) : error C2375: 'getservbyport' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(770) : see declaration of 'getservbyport'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(1983) : error C2375: 'getservbyname' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(772) : see declaration of 'getservbyname'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(2001) : error C2375: 'getprotobynumber' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(775) : see declaration of 'getprotobynumber'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(2018) : error C2375: 'getprotobyname' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(777) : see declaration of 'getprotobyname'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(2038) : error C2375: 'WSAStartup' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(781) : see declaration of 'WSAStartup'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(2056) : error C2375: 'WSACleanup' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(783) : see declaration of 'WSACleanup'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(2073) : error C2375: 'WSASetLastError' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(785) : see declaration of 'WSASetLastError'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(2090) : error C2375: 'WSAGetLastError' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(787) : see declaration of 'WSAGetLastError'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(2107) : error C2375: 'WSAIsBlocking' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(789) : see declaration of 'WSAIsBlocking'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(2124) : error C2375: 'WSAUnhookBlockingHook' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(791) : see declaration of 'WSAUnhookBlockingHook'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(2141) : error C2375: 'WSASetBlockingHook' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(793) : see declaration of 'WSASetBlockingHook'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(2158) : error C2375: 'WSACancelBlockingCall' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(795) : see declaration of 'WSACancelBlockingCall'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(2180) : error C2375: 'WSAAsyncGetServByName' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(797) : see declaration of 'WSAAsyncGetServByName'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(2207) : error C2375: 'WSAAsyncGetServByPort' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(802) : see declaration of 'WSAAsyncGetServByPort'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(2233) : error C2375: 'WSAAsyncGetProtoByName' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(806) : see declaration of 'WSAAsyncGetProtoByName'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(2258) : error C2375: 'WSAAsyncGetProtoByNumber' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(810) : see declaration of 'WSAAsyncGetProtoByNumber'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(2283) : error C2375: 'WSAAsyncGetHostByName' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(814) : see declaration of 'WSAAsyncGetHostByName'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(2310) : error C2375: 'WSAAsyncGetHostByAddr' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(818) : see declaration of 'WSAAsyncGetHostByAddr'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(2333) : error C2375: 'WSACancelAsyncRequest' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(822) : see declaration of 'WSACancelAsyncRequest'
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(2353) : error C2375: 'WSAAsyncSelect' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(824) : see declaration of 'WSAAsyncSelect'
D:\EIFScanDB_final_17\SortListCtrl.cpp(488) : error C2446: '!=' : no conversion from 'const unsigned int' to 'unsigned long (__stdcall *)(const char *)'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
D:\EIFScanDB_final_17\SortListCtrl.cpp(488) : error C2040: '!=' : 'unsigned long (__stdcall *)(const char *)' differs in levels of indirection from 'const unsigned int'
D:\EIFScanDB_final_17\SortListCtrl.cpp(499) : error C2440: 'initializing' : cannot convert from 'unsigned long (__stdcall *)(const char *)' to 'long'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
D:\EIFScanDB_final_17\SortListCtrl.cpp(500) : error C2440: 'initializing' : cannot convert from 'unsigned long (__stdcall *)(const char *)' to 'long'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Error executing cl.exe.
Creating browse info file...

EIFScan.exe - 62 error(s), 11 warning(s)



//*********************************************************

what does that means?
 
You seem to be #including both winsock.h and winsock2.h. Get rid of winsock.h and that will get rid of most of your errors and warnings.
 
oh...i remember, when i first built the MFC exe workspace. i ticked the one Windows Sockets checkbox in the step4 of the MFC AppWizard....in the "what features would you like to include?" frame...


any way that i can remove it?
 
Yes, get rid of <winsock.h> (it will be probably in your StdAfx.h file). Then include <winsock2.h> in StdAfx.h and in cpp files where you want to use Windows Sockets functions include just StdAfx.h (and not winsock2.h).

That should help
 
hi, i checked the stdafx.h,
but there is no "winsock.h" inside.

only got
#include <afxsock.h>

that is not winsock.h right? but except this one, there is nothing related to sockets....

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top