Cocos2d-x网游开发之添加curl库到vs2010中
Cocos2D-X加入以下代码到HelloWorld.cpp中;
- bool HelloWorld::init()
- {
- /*
- *@author By Himi
- */
- //////////////////////////////
- // 1. super init first
- if ( !CCLayer::init() )
- {
- return false;
- }
- CCLabelTTF* pLabel = CCLabelTTF::labelWithString("Hello World", "Thonburi", 34);
- CCSize size = CCDirector::sharedDirector()->getWinSize();
- pLabel->setPosition( ccp(size.width / 2, size.height - 20) );
- this->addChild(pLabel, 1);
- CURL *curl;
- CURLcode res;
- char buffer[10];
- curl = curl_easy_init();
- if (curl)
- {
- // curl_easy_setopt(curl, CURLOPT_URL, "http://127.0.0.1:8080/himi");
- curl_easy_setopt(curl, CURLOPT_URL, "http://127.0.0.1:8080/himi?name=xiaoming&password=李华明");
- res = curl_easy_perform(curl);
- /* always cleanup */
- curl_easy_cleanup(curl);
- if (res == 0)
- {
- pLabel->setString("0 response");
- }
- else
- {
- sprintf(buffer,"code: %i",res);
- pLabel->setString(buffer);
- }
- }
- else
- {
- pLabel->setString("no curl");
- }
- return true;
- }
在下载的引擎文件中如E:\TDDOWNLOAD\cocos2d-x\cocos2dx\platform\third_party\win32\libraries
把头文件加到项目中。#include"curl.h"
现在在vs2010中添加curl的lib文件文件识别
打开vs2010->项目->win32.debug->如下图:
打开项目菜单:
打开附加依赖库菜单;
添加libcurl_imp.lib,如图上
本人表达能力有限,不明白可提问。
新浪微博: http://weibo.com/u/2129505763
谢谢!你的支持。