#include "main.h" #include "AppDelegate.h" #include "cocos2d.h" #include #include "Utils/Utility.h" #include "Global/GlobalJosn.h" using namespace std; USING_NS_CC; char* convertTCharToUtf8(const TCHAR* src); int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); // load project config from command line args string strCmdLine = convertTCharToUtf8(lpCmdLine); vector args = utility::split(strCmdLine, " "); auto it = args.begin(); while (it != args.end()) { std::string arg = *it; if (arg.compare("-nickname") == 0) { ++it; if (it == args.end()) break; GlobalJosn::getInstance()->m_strNickName = *it; } else if (arg.compare("-host") == 0) { ++it; if (it == args.end()) break; GlobalJosn::getInstance()->m_strLogonIp = *it; } else if (arg.compare("-port") == 0) { ++it; if (it == args.end()) break; GlobalJosn::getInstance()->m_iPort = atoi((*it).c_str()); } else if (arg.compare("-resdir") == 0) { ++it; if (it == args.end()) break; FileUtils::getInstance()->addSearchPath(*it, true); } ++it; } // create the application instance AppDelegate app; return Application::getInstance()->run(); } //convert Unicode/LocalCode TCHAR to Utf8 char char* convertTCharToUtf8(const TCHAR* src) { #ifdef UNICODE WCHAR* tmp = (WCHAR*)src; size_t size = wcslen(src) * 3 + 1; char* dest = new char[size]; memset(dest, 0, size); WideCharToMultiByte(CP_UTF8, 0, tmp, -1, dest, size, NULL, NULL); return dest; #else char* tmp = (char*)src; unsigned int size = strlen(tmp) + 1; WCHAR* dest = new WCHAR[size]; memset(dest, 0, sizeof(WCHAR)*size); MultiByteToWideChar(CP_ACP, 0, src, -1, dest, (int)size); // convert local code to unicode. size = wcslen(dest) * 3 + 1; char* dest2 = new char[size]; memset(dest2, 0, size); WideCharToMultiByte(CP_UTF8, 0, dest, -1, dest2, size, NULL, NULL); // convert unicode to utf8. delete[] dest; return dest2; #endif }