A project used ADO method making connection to mysql may not work so well and may not so effictive , thus , use Mysql C-Api is a rather good scheme , but the C-Api is rather tougn for beginner , fortunately , An project called Mysql++ lib avaliable for C++ programmer. It's better than C-Api , but there is a problem while using with winsock2 on the platform Ms-windows .
Any question , contact me as follows:
The problem may appear like this :
c:\program files\devstudio\vc98\include\winsock2.h(99) : error C2011: 'fd_set' : 'struct' type redefinition
c:\program files\devstudio\vc98\include\winsock2.h(134) : warning C4005: 'FD_SET' : macro redefinition
c:\program files\devstudio\vc98\include\winsock.h(83) : see previous definition of 'FD_SET'
c:\program files\devstudio\vc98\include\winsock2.h(143) : error C2011: 'timeval' : 'struct' type redefinition
c:\program files\devstudio\vc98\include\winsock2.h(199) : error C2011: 'hostent' : 'struct' type redefinition
c:\program files\devstudio\vc98\include\winsock2.h(212) : error C2011: 'netent' : 'struct' type redefinition
c:\program files\devstudio\vc98\include\winsock2.h(219) : error C2011: 'servent' : 'struct' type redefinition
The problem tells its own table , the winsock.h was included somewhere . As we know , using the winsock and winsock2 must notice these :
Winsock2.h must be inclued before winsock.h
if you use windows.h , you must use like this :
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
but , this time , the winsock.h inclued in the diretory /Mysql++ 2.2.3 /lib/Common.h ,What could I do to enable Winsock2 in my project and make no impress on other projects?
this is a unified way to make the things easier and clear -
Condition Compiler , you can code like this :
#ifdef _CXL_WINSOCK2
#include <winsock2.h>
#pragma message("###The compiler's behavior Changed by Chang xinglong to Enable winsock2 in Mysql++...###")
#else
#include <winsock.h>
#endif
after done , you define _CXL_WINSOCK2 in your project to enable winsock2 or leave it to use winsock.