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

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

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

That works! Thanks Jingchen chen :slight_smile:

1 Like

It works, thanks chenjc.