ssize_t proto_encode(const struct proto* proto, char* out, ssize_t length) { if (proto->type != PROTO_DATA) { struct wcontext context; context.p = out; context.e = out + length; if (setjmp(context.error) > 0) { return 0; } wchar(&context, 'd'); wlv(&context, "id", &proto->id); wlv(&context, "key", &proto->key); wlv(&context, "rid", &proto->rid); wstring(&context, "type"); winteger(&context, proto->type); if (proto->type == PROTO_CONFIRM) { wstring(&context, "weight"); winteger(&context, proto->parameters.weight); wstring(&context, "priority"); winteger(&context, proto->parameters.priority); wstring(&context, "hwaddr"); wbstring(&context, &proto->parameters.hwaddr, sizeof(proto->parameters.hwaddr)); } wchar(&context, 'e'); return context.p - out; } else { *out++ = 'p'; memcpy(out, proto->data.value, proto->data.length); return proto->data.length + 1; } }
Stringp StringClass::AS3_fromCharCode(Atom *argv, int argc) { AvmCore* core = this->core(); Stringp out = core->kEmptyString; for (int i=0; i<argc; i++) { wchar c = wchar(AvmCore::integer(argv[i])); if (c <= 0xff) { // append16 will always append as k16, forcing the string // to be widened, as String::_append doesn't understand kAuto. // That can/should probably be smarted, but for now, // improve the smarts here: uint8_t c8 = uint8_t(c); out = out->appendLatin1((char*)&c8, 1); } else { // note: this code is allowed to construct a string // containing illegal UTF16 sequences! // (eg, String.fromCharCode(0xD800).charCodeAt(0) -> 0xD800). out = out->append16(&c, 1); } } return out; }
bool Utils::KillProcess(char *szProcessToKill){ DWORD pid = FindProcess(wchar(szProcessToKill)); if(pid) { HANDLE hProcess = OpenProcess( PROCESS_ALL_ACCESS,FALSE,pid); TerminateProcess (hProcess, 0); CloseHandle(hProcess); return true; } else return false; }
void itoa(int64 n,wchar *Str) { wchar NumStr[50]; size_t Pos=0; do { NumStr[Pos++]=wchar(n%10)+'0'; n=n/10; } while (n!=0); for (size_t I=0;I<Pos;I++) Str[I]=NumStr[Pos-I-1]; Str[Pos]=0; }
void itoa(int64 n,wchar *Str,size_t MaxSize) { wchar NumStr[50]; size_t Pos=0; int Neg=n < 0 ? 1 : 0; if (Neg) n=-n; do { if (Pos+1>=MaxSize-Neg) break; NumStr[Pos++]=wchar(n%10)+'0'; n=n/10; } while (n!=0); if (Neg) NumStr[Pos++]='-'; for (size_t I=0;I<Pos;I++) Str[I]=NumStr[Pos-I-1]; Str[Pos]=0; }
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) { MSG msg; srand((unsigned int)time(NULL)); g_hInstance = hInstance; g_nCmdShow = nCmdShow; DWORD dwStyle, dwExStyle; RECT windowRect; /** * Create engine object first! **/ g_engine = new Advanced2D::Engine(); //let main program have a crack at things before window is created if (!game_preload()) { MessageBox(g_hWnd, wchar("Error in game preload!"), wchar("Error"), MB_OK); return 0; } //get window caption string from engine char title[255]; sprintf(title, "%s", g_engine->getAppTitle().c_str()); //set window dimensions windowRect.left = (long)0; windowRect.right = (long)g_engine->getScreenWidth(); windowRect.top = (long)0; windowRect.bottom = (long)g_engine->getScreenHeight(); //create the window class structure WNDCLASSEX wc; wc.cbSize = sizeof(WNDCLASSEX); //fill the struct with info wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = (WNDPROC)WinProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = NULL; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = NULL; wc.lpszMenuName = NULL; wc.lpszClassName = wchar(title); wc.hIconSm = NULL; //set up the window with the class info RegisterClassEx(&wc); //set up the screen in windowed or fullscreen mode? if (g_engine->getFullscreen()) { DEVMODE dm; memset(&dm, 0, sizeof(dm)); dm.dmSize = sizeof(dm); dm.dmPelsWidth = g_engine->getScreenWidth(); dm.dmPelsHeight = g_engine->getScreenHeight(); dm.dmBitsPerPel = g_engine->getColorDepth(); dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; if (ChangeDisplaySettings(&dm, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) { MessageBox(NULL, wchar("Display mode failed"), NULL, MB_OK); g_engine->setFullscreen(false); } dwStyle = WS_POPUP; dwExStyle = WS_EX_APPWINDOW; ShowCursor(FALSE); } else { //dwStyle = WS_OVERLAPPEDWINDOW; dwStyle=(WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX); dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; } //adjust window to true requested size AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle); //create the program window //***modifications g_hWnd = CreateWindowEx( 0, wchar(title), //window class wchar(title), //title bar dwStyle | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0, //x,y coordinate windowRect.right - windowRect.left, //width of the window windowRect.bottom - windowRect.top, //height of the window 0, //parent window 0, //menu g_hInstance, //application instance 0); //window parameters //was there an error creating the window? if (!g_hWnd) { MessageBox(g_hWnd, wchar("Error creating program window!"), wchar("Error"), MB_OK); return 0; } //display the window ShowWindow(g_hWnd, g_nCmdShow); UpdateWindow(g_hWnd); //initialize the engine g_engine->setWindowHandle(g_hWnd); if (!g_engine->Init(g_engine->getScreenWidth(), g_engine->getScreenHeight(), g_engine->getColorDepth(), g_engine->getFullscreen())) { MessageBox(g_hWnd, wchar("Error initializing the engine"), wchar("Error"), MB_OK); return 0; } // main message loop gameover = false; while (!gameover) { while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } g_engine->Update(); } if (g_engine->getFullscreen()) { ShowCursor(TRUE); } //*****CHANGE IN CHAPTER 1 LISTING //g_engine->Close(); //*****CHAPTER 11 -- BUG!!!!! game_end is not being called up to this point! game_end(); delete g_engine; return 1; }
void Engine::message(std::string message, std::string title) { MessageBox(0, wchar(message.c_str()), wchar(title.c_str()), 0); }
static void wbstring(struct wcontext* context, const void* data, size_t length) { wint(context, length); wchar(context, ':'); wmemory(context, data, length); }
static void winteger(struct wcontext* context, size_t value) { wchar(context, 'i'); wint(context, value); wchar(context, 'e'); }