Tutorial: How to run a cocos2d-x 3.0 beta app on Windows XP with Visual Studio 2012 Express

Hi!

cocos2d-x 3.0 beta docs says that the minimum Windows version available to run an app is Windows 7.
However, it’s possible to run a cocos2d-x 3.0 beta app on Windows XP with Visual Studio 2012 Express.

Steps:
1) Install Visual Studio 2012 Express

**2) Install the latest update of Visual Studio 2012 Express *
Since Update 1, Visual Studio 2012 Express is able to build apps compatible with Windows XP.
**3) Comment out Console::listenOnTCP(int port)*
It seems that inet_ntop is not compatible with Windows XP:

So we have to comment out Console::listenOnTCP(int port) on CCConsole.cpp:

bool Console::listenOnTCP(int /*port*/)
{
    /*int listenfd, n;
    const int on = 1;
    struct addrinfo hints, *res, *ressave;
    char serv[30];

    snprintf(serv, sizeof(serv)-1, "%d", port );
    serv[sizeof(serv)-1]=0;

    bzero(&hints, sizeof(struct addrinfo));
    hints.ai_flags = AI_PASSIVE;
    hints.ai_family = AF_INET; // AF_UNSPEC: Do we need IPv6 ?
    hints.ai_socktype = SOCK_STREAM;

#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
    WSADATA wsaData;
    n = WSAStartup(MAKEWORD(2, 2),&wsaData);
#endif

    if ( (n = getaddrinfo(NULL, serv, &hints, &res)) != 0) {
        fprintf(stderr,"net_listen error for %s: %s", serv, gai_strerror(n));
        return false;
    }

    ressave = res;

    do {
        listenfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
        if (listenfd < 0)
            continue;       

        setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, (const char*)&on, sizeof(on));
        if (bind(listenfd, res->ai_addr, res->ai_addrlen) == 0)
            break;          

        close(listenfd);   
    } while ( (res = res->ai_next) != NULL);

    if (res == NULL) {
        perror("net_listen:");
        freeaddrinfo(ressave);
        return false;
    }

    listen(listenfd, 50);

    if (res->ai_family == AF_INET) {
        char buf[INET_ADDRSTRLEN] = "";
        struct sockaddr_in *sin = (struct sockaddr_in*) res->ai_addr;
        if( inet_ntop(res->ai_family, &sin->sin_addr, buf, sizeof(buf)) != NULL )
            log("Console: listening on  %s : %d", buf, ntohs(sin->sin_port));
        else
            perror("inet_ntop");
    } else if (res->ai_family == AF_INET6) {
        char buf[INET6_ADDRSTRLEN] = "";
        struct sockaddr_in6 *sin = (struct sockaddr_in6*) res->ai_addr;
        if( inet_ntop(res->ai_family, &sin->sin6_addr, buf, sizeof(buf)) != NULL )
            log("Console: listening on  %s : %d", buf, ntohs(sin->sin6_port));
        else
            perror("inet_ntop");
    }

    freeaddrinfo(ressave);

    return listenOnFileDescriptor(listenfd);*/

    log("Console::listenOnTCP disabled!");
    return false;
}

4) Ensure that your project / solution is targeting Windows XP

5) Make a x86 release build of your cocos2d-x 3.0 beta app

6) Ensure that the app works on your current Windows OS by double clicking on the executable
If it hangs, it’s probably because it doesn’t find the resources. In that case, paste the content of the resources folder in the executable folder.

7) On Windows XP, install the Visual C++ x86 redistributables
http://www.microsoft.com/en-us/download/details.aspx?id=8328 and http://www.microsoft.com/en-us/download/details.aspx?id=30679

8) Run the thing!


screenshot.JPG (59.4 KB)