How to resolved 'timeval' : struct type redefinition when import winsock2.h

How to resolved 'timeval' : struct type redefinition when import winsock2.h
0

#1

I’m coding network for cocos2d-x game on WP8 and have to use ‘htonl, htons’ in winsock2 header to handle Read/Write buffer. But it caused error ‘timeval’ : struct type redefinition in CCStdC.h when i included winsock2 . I found many topics on Google but not really work. Please help!

Thanks


#2

try this, modified in CCStdC.h:

#include window.h
#if CC_TARGET_PLATFORM == CC_PLATFORM_WP8
// wp8 support winsock2, winrt not support
#include winsock2.h
#else
#undef timeval
struct timeval
{
        long tv_sec;                // seconds
        long tv_usec; // microSeconds
};
#endif

#3

That works! Thanks Jingchen chen :slight_smile:


#4

It works, thanks chenjc.