/************************************************************************* * main.cpp - program entry for win32 and wince platforms * * author: Konstantin Maslyuk "Kalemas" mailto:kalemas@mail.ru * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation version 2. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. ************************************************************************/ #include "sbCore.h" #include #include #ifdef _WIN32_WCE #include #include #include #include #endif #include // Globals HWND Window = NULL; // Functions void sbMessage ( const char * format , ... ) { char buffer [1024]; va_list args; va_start(args, format); int l = _vsnprintf(buffer, 1024, format, args); if (l == -1) l = 1024; va_end(args); #ifdef _WIN32_WCE printf(buffer); #else OutputDebugStringA(buffer); #endif //static FileDesc * file = NULL; //file = FileMgr::getSystemFileMgr()->open(".\\log.txt", file == NULL ? FileMgr::WRONLY|FileMgr::CREAT|FileMgr::TRUNC : FileMgr::WRONLY|FileMgr::APPEND ); static sword::FileDesc * file = sword::FileMgr::getSystemFileMgr()->open(".\\log.txt", sword::FileMgr::WRONLY|sword::FileMgr::CREAT|sword::FileMgr::TRUNC ); if (file->getFd() > 0) { file->write(buffer,l); //FileMgr::getSystemFileMgr()->close(file); } } void sbFillRect ( sbSurface rc, const sbRect * rect, sbColor color ) { HBRUSH brush = CreateSolidBrush(RGB(color.red,color.green,color.blue)); RECT rect2 = {rect->left,rect->top,rect->right,rect->bottom}; FillRect ((HDC)rc, &rect2, brush); DeleteObject (brush); } sbFont sbMakeFont ( int size, const TCHAR * face, bool bold, bool italic ) { LOGFONT lf; memset(&lf, 0, sizeof(LOGFONT)); lf.lfHeight = size; lf.lfWidth = 0; lf.lfEscapement = 0; lf.lfOrientation = 0; //if (bold) lf.lfWeight = FW_BOLD; else lf.lfWeight = FW_NORMAL; lf.lfWeight = bold ? FW_SEMIBOLD : FW_NORMAL; lf.lfItalic = italic; lf.lfUnderline = FALSE; lf.lfStrikeOut = FALSE; lf.lfCharSet = DEFAULT_CHARSET; lf.lfOutPrecision = OUT_RASTER_PRECIS; lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; lf.lfQuality = CLEARTYPE_QUALITY; lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; _tcsncpy (lf.lfFaceName, face, LF_FACESIZE); /* Wingdings, Tahoma, Courier New */ return (sbFont) CreateFontIndirect(&lf); } sbPoint sbGetTextExtent ( sbFont font, const TCHAR * text, int count ) { SIZE sz; sbPoint ts; HDC hdc = CreateCompatibleDC (NULL); SelectObject (hdc,(HFONT)font); for ( ; count > 0; count--) { GetTextExtentPoint32 (hdc,text,1,&sz); ts.x += sz.cx; ts.y = max (ts.y,sz.cy); text++; } DeleteDC (hdc); return ts; } void sbDrawGradient ( sbSurface rc, const sbRect * rect, sbColor startColor, sbColor endColor, bool vertical ) { TRIVERTEX vert[2]; GRADIENT_RECT gRect; vert [0] .x = rect->left; vert [0] .y = rect->top; vert [0] .Red = startColor.red << 8; vert [0] .Green = startColor.green << 8; vert [0] .Blue = startColor.blue << 8; vert [0] .Alpha = 0x0000; vert [1] .x = rect->right; vert [1] .y = rect->bottom; vert [1] .Red = endColor.red << 8; vert [1] .Green = endColor.green << 8; vert [1] .Blue = endColor.blue << 8; vert [1] .Alpha = 0x0000; gRect.UpperLeft = 0; gRect.LowerRight = 1; GradientFill((HDC)rc, vert, 2, &gRect, 1, vertical ? GRADIENT_FILL_RECT_V : GRADIENT_FILL_RECT_H); } void sbDrawBitmap ( sbSurface rc, const sbRect * rect, sbBitmap bitmap, bool stretch ) { HDC thdc = CreateCompatibleDC(NULL); HBITMAP obm = (HBITMAP)SelectObject(thdc, (HBITMAP)bitmap); BITMAP bm; GetObject(bitmap, sizeof(bm), &bm); if ( stretch ) { StretchBlt((HDC)rc, rect->left, rect->top, rect->width(), rect->height(), thdc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY); } else { BitBlt((HDC)rc, rect->left, rect->top, min(rect->width(),bm.bmWidth), min(rect->height(),bm.bmHeight), thdc, 0, 0, SRCCOPY); } SelectObject(thdc, obm); DeleteDC(thdc); } const char * sbGetLocale () { const char * locale = "en_US"; TCHAR userLocale [6]; GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, userLocale, 6); if (_tcscmp(userLocale, L"RUS")==0) locale = "ru_RU-cp1251"; else if (_tcscmp(userLocale, L"AFK")==0) locale = "af"; else if (_tcscmp(userLocale, L"BGR")==0) locale = "bg_BG-cp1251"; else if (_tcscmp(userLocale, L"CSY")==0) locale = "cs"; else if (_tcscmp(userLocale, L"DAN")==0) locale = "da"; else if (_tcscmp(userLocale, L"ETI")==0) locale = "et"; else if (_tcscmp(userLocale, L"FIN")==0) locale = "fi"; else if (_tcscmp(userLocale, L"IND")==0) locale = "id"; else if (_tcscmp(userLocale, L"KOR")==0) locale = "ko"; else if (_tcscmp(userLocale, L"PLK")==0) locale = "pl"; else if (_tcscmp(userLocale, L"ROM")==0) locale = "ro"; else if (_tcscmp(userLocale, L"SKY")==0) locale = "sk"; else if (_tcscmp(userLocale, L"SLV")==0) locale = "sl"; else if (_tcscmp(userLocale, L"UKR")==0) locale = "uk_UA-cp1251"; else if (_tcsnccmp(userLocale, L"AR", 2)==0) locale = "ar_EG-cp1256"; else if (_tcsnccmp(userLocale, L"EN", 2)==0) locale = "en_GB"; else if (_tcsnccmp(userLocale, L"DE", 2)==0) locale = "de"; else if (_tcsnccmp(userLocale, L"ES", 2)==0) locale = "es"; else if (_tcsnccmp(userLocale, L"FR", 2)==0) locale = "fr"; else if (_tcsnccmp(userLocale, L"IT", 2)==0) locale = "it"; else if (_tcsnccmp(userLocale, L"NL", 2)==0) locale = "nl"; else if (_tcsnccmp(userLocale, L"NO", 2)==0) locale = "no"; else if (_tcsnccmp(userLocale, L"PT", 2)==0) locale = "pt"; else if (_tcscmp(userLocale, L"USA")!=0) sbMessage("Unsupported user locale: %s\n", userLocale); return locale; } void sbUpdateScreen () { sbAssert(Window==NULL); RECT rect; GetClientRect(Window,&rect); InvalidateRect(Window, &rect, FALSE); UpdateWindow(Window); } void sbSetSip ( bool on ) { #ifdef _WIN32_WCE SIPINFO si; if (SipStatus() == SIP_STATUS_UNAVAILABLE) { sbMessage("Sip is unavailable.\n"); return; } memset(&si, 0, sizeof(SIPINFO)); si.cbSize = sizeof(SIPINFO); SHSipInfo(SPI_GETSIPINFO,0,&si,0); if (on) { if (si.fdwFlags & SIPF_ON) return; //printf("%i %i %i %i %i\n",si.fdwFlags, si.fdwFlags | SIPF_ON, si.fdwFlags & SIPF_ON, si.fdwFlags & ~SIPF_ON, si.fdwFlags ^ SIPF_ON); si.fdwFlags |= SIPF_ON; HWND sipWnd = FindWindow(L"SipWndClass",L""); si.rcSipRect.top += si.rcVisibleDesktop.bottom-si.rcSipRect.bottom; si.rcSipRect.bottom += si.rcVisibleDesktop.bottom-si.rcSipRect.bottom; SHSipInfo(SPI_SETSIPINFO,0,&si,0); MoveWindow(sipWnd,si.rcSipRect.left,si.rcSipRect.top,si.rcSipRect.right-si.rcSipRect.left,si.rcSipRect.bottom-si.rcSipRect.top,false); } else { if (!(si.fdwFlags & SIPF_ON)) return; si.fdwFlags ^= SIPF_ON; SHSipInfo (SPI_SETSIPINFO,0,&si,0); } #endif } class sbThreadData { public: sbThreadData () : running (false) , abort (false) { ; } bool running; bool abort; HANDLE handle; DWORD id; void (*executor) (bool*); }; DWORD WINAPI sbThreadMain ( LPVOID pData ) { sbAssert (pData==NULL); sbThreadData * data = reinterpret_cast(pData); sbAssert (data->executor==NULL); data->executor(&data->abort); data->running = false; return 1; } sbThread sbThreadCreate (void (*executor) (bool*)) { sbThreadData * threadData = new sbThreadData (); threadData->executor = executor; threadData->handle = CreateThread(NULL, 0, sbThreadMain, (LPVOID)threadData, 0, &threadData->id); if(threadData->handle) { threadData->running = true; SetThreadPriority(threadData->handle, THREAD_PRIORITY_BELOW_NORMAL); } sbAssert (threadData->running==false); return (sbThread)threadData; } void sbThreadDestroy ( sbThread theThread ) { sbThreadData * threadData = (sbThreadData*)theThread; const int timeout = 2000; int time = timeout; if (!threadData->running) return; threadData->abort = true; SetThreadPriority(threadData->handle, THREAD_PRIORITY_ABOVE_NORMAL); while (threadData->running && timeout > 0) { Sleep(1); time--; } if (timeout <= 0) { sbMessage ("Thread termination forced.\n"); TerminateThread(threadData->handle, -1); threadData->running = false; } else if (timeout-time > 16) { sbMessage ("Thread stoped in %i msec.\n", timeout-time); } CloseHandle(threadData->handle); threadData->abort = false; delete threadData; } sbBitmap sbLoadBitmap ( const TCHAR * filename ) { #ifdef _WIN32_WCE return SHLoadImageFile(filename); #else return LoadBitmap(NULL,filename); #endif } sbSurface sbSurfaceCreate ( int width, int height ) { sbAssert ( Window == NULL ); HDC wc = GetDC ( Window ); HDC dc = CreateCompatibleDC ( wc ); HBITMAP bitmap = CreateCompatibleBitmap ( wc, width, height ); SelectObject ( dc, bitmap ); SetBkMode ( dc, TRANSPARENT ); ReleaseDC ( Window, wc ); return (sbSurface)dc; } void sbSurfaceDestroy ( sbSurface surface ) { DeleteObject ( (HBITMAP)GetCurrentObject( (HDC)surface, OBJ_BITMAP ) ); DeleteDC ( (HDC)surface ); } void sbDrawLine ( sbSurface rc, sbPoint from, sbPoint to, sbColor color, int thickness ) { HPEN pen = CreatePen(PS_SOLID, thickness, RGB(color.red,color.green,color.blue) ); SelectObject((HDC)rc,pen); MoveToEx((HDC)rc, from.x, from.y, (LPPOINT)NULL); LineTo((HDC)rc, to.x, to.y); } void sbSelectColor ( sbSurface rc, sbColor color ) { //static sbColor * prevColor = NULL; //if (prevColor == &color) return *prevColor; SetTextColor((HDC)rc,RGB(color.red,color.green,color.blue)); //prevColor = &color; } bool sbQueryBox ( const TCHAR * question ) { return MessageBox(Window,question,L"Question :",MB_YESNO) == IDYES; } int sbWcsToMbs ( const TCHAR * wcs , char * mbs , int length ) { if (!length) return WideCharToMultiByte(CP_UTF8,0,wcs,-1,NULL,0,NULL,NULL); return WideCharToMultiByte(CP_UTF8,0,wcs,-1,mbs,length,NULL,NULL); } void sbGetScreenRect ( sbRect & rect ) { sbAssert (Window==NULL); RECT wr; GetClientRect(Window,&wr); rect.left = wr.left; rect.top = wr.top; rect.right = wr.right; rect.bottom = wr.bottom; } void sbDeleteFont ( sbFont font ) { DeleteObject ((HFONT)font); } void sbDeleteBitmap ( sbBitmap bitmap ) { DeleteObject ((HBITMAP)bitmap); } sbFont sbSelectFont ( sbSurface rc, sbFont font ) { return (sbFont)SelectObject((HDC)rc,(HFONT)font); } void sbDrawText ( sbSurface rc, int x, int y, const TCHAR * text, int count ) { ExtTextOut((HDC)rc, x, y, ETO_OPAQUE, NULL, text, count, 0); } void sbSleep ( int milliseconds ) { Sleep (milliseconds); } void sbSetTimer ( const int timer, int refreshRate ) { sbAssert(Window==NULL); SetTimer(Window, timer, refreshRate, (TIMERPROC) NULL); } void sbKillTimer ( const int timer ) { sbAssert(Window==NULL); KillTimer(Window, timer); } void sbBitBlt ( sbSurface toRc, sbRect toRect , sbSurface fromRc, sbPoint fromXy ) { BitBlt((HDC)toRc, toRect.left, toRect.top, toRect.width(), toRect.height(), (HDC)fromRc, fromXy.x, fromXy.y, SRCCOPY); } void sbStretchBlt ( sbSurface toRc, sbRect toRect , sbSurface fromRc, sbRect fromRect ) { StretchBlt((HDC)toRc, toRect.left, toRect.top, toRect.width(), toRect.height(), (HDC)fromRc, fromRect.left, fromRect.top, fromRect.width(), fromRect.height(), SRCCOPY); } long sbGetTickCount () { return GetTickCount(); } void sbExit ( int code ) { PostQuitMessage(code); } void sbWaitMode ( bool wait ) { if (wait) SetCursor ( LoadCursor ( NULL, IDC_WAIT ) ); else SetCursor ( LoadCursor ( NULL, IDC_ARROW ) ); } LRESULT CALLBACK wndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch ( message ) { case WM_ERASEBKGND: return 1; case WM_KILLFOCUS: // loose focus sbSetSip ( false ); Core->switchList ( sbList::TYPE_NONE ); return 1; case WM_SETFOCUS: // receive focus if ( Core != NULL ) Core->switchList ( sbList::TYPE_CURRENT ); return 1; case WM_ACTIVATE: #ifdef _WIN32_WCE SHFullScreen ( hwnd, SHFS_HIDESIPBUTTON | SHFS_HIDETASKBAR | SHFS_HIDESTARTICON ); #endif return 1; case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); Core->onPaint((sbSurface)hdc); /*HDC rc = CreateCompatibleDC(NULL); HDC rc2 = GetDC(Window); HBITMAP bmp = CreateCompatibleBitmap (rc2, 100, 100); SelectObject(rc,bmp); SetBkMode(rc, TRANSPARENT); //sbFillRect(rc,&sbRect(0,0,32,100),sbColor(250,0,0)); //sbFillRect(rc,&sbRect(64,0,100,100),sbColor(50,128,100)); //sbBitBlt(hdc,32,0,100,100,rc,0,0); RECT r1 = {0,0,32,100}; RECT r2 = {64,0,100,100}; HBRUSH b1 = CreateSolidBrush(RGB(250,0,0)); HBRUSH b2 = CreateSolidBrush(RGB(50,120,100)); FillRect(rc,&r1,b1); FillRect(rc,&r2,b2); BitBlt(hdc,0,0,100,100,rc,0,0,SRCCOPY); BitBlt(hdc,0,100,100,100,rc,0,0,SRCCOPY); DeleteObject(b1); DeleteObject(b2); DeleteObject(bmp); DeleteDC(rc); ReleaseDC(Window,rc2);*/ EndPaint(hwnd, &ps); DeleteDC(hdc); } return 1; case WM_LBUTTONUP: Core->onMouse ( LOWORD(lParam), HIWORD(lParam), MSG_MOUSE_L_UP ); return 1; case WM_MOUSEMOVE: Core->onMouse ( LOWORD(lParam), HIWORD(lParam), MSG_MOUSE_MOVE ); return 1; case WM_LBUTTONDOWN: Core->onMouse ( LOWORD(lParam), HIWORD(lParam), MSG_MOUSE_L_DOWN ); return 1; case WM_KEYDOWN: Core->onKey ( wParam, true ); return 1; case WM_KEYUP: Core->onKey ( wParam, false ); return 1; case WM_CHAR: Core->onChar ( (TCHAR) wParam ); return 1; case WM_TIMER: Core->onTimer ( wParam ); return 1; } return DefWindowProc(hwnd, message, wParam, lParam); } #if 0//#ifdef _WIN32_WCE #include #include #include #include #include struct in_addr BIN_IPV4_ADDR_LOOPBACK = {127, 0, 0, 1}; struct in6_addr BIN_IPV6_ADDR_LOOPBACK = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1 }; #define MAX_LOCAL_NAME_LEN 64 //Function Prototypes BOOL IsNetPresent(); int netTest(const char * adress) { WSADATA WSAData; WSAStartup(MAKEWORD(2,2), &WSAData); sbMessage("Network Connection %s present", IsNetPresent() ? "IS" : "is NOT"); WSACleanup(); return 0; } // // Determine if you have a IPv4 or IPv6 network address. // BOOL IsNetPresent() { BOOL bFoundLocalAddr = FALSE; char szAddrASCII[MAX_LOCAL_NAME_LEN]; ADDRINFO AddrHints, *pAI, *pAddrInfo; // // Get the local host's name in ASCII text. // if(gethostname(szAddrASCII, MAX_LOCAL_NAME_LEN - 1)) { sbMessage("Error getting local host name, error = %d\r\n", WSAGetLastError()); return FALSE; } // // To obtain a list of all the local // addresses, resolve the local name with getaddrinfo for all // protocol families. // memset(&AddrHints, 0, sizeof(AddrHints)); AddrHints.ai_family = PF_UNSPEC; AddrHints.ai_flags = AI_PASSIVE; if(getaddrinfo(szAddrASCII, "10", &AddrHints, &pAddrInfo)) { sbMessage("getaddrinfo(%hs) error %d", szAddrASCII, WSAGetLastError()); return FALSE; } // // Search the addresses returned. // If any of them match the loopback address, then // are not connected to an outside network. // // Note: This will not tell you how many networks you // are connected to. If one or more networks are present, // then the loopback addresses will not be included in the // list returned from getaddrinfo. // bFoundLocalAddr = TRUE; for(pAI = pAddrInfo; pAI != NULL && bFoundLocalAddr; pAI = pAI->ai_next) { if(pAI->ai_family == PF_INET) { if(memcmp(&(((SOCKADDR_IN *)(pAI->ai_addr))->sin_addr), &BIN_IPV4_ADDR_LOOPBACK, sizeof(BIN_IPV4_ADDR_LOOPBACK)) == 0) bFoundLocalAddr = FALSE; } else if(pAI->ai_family == PF_INET6) { if(memcmp(&(((SOCKADDR_IN6 *)(pAI->ai_addr))->sin6_addr), &BIN_IPV6_ADDR_LOOPBACK, sizeof(BIN_IPV6_ADDR_LOOPBACK)) == 0) bFoundLocalAddr = FALSE; } } freeaddrinfo(pAddrInfo); return bFoundLocalAddr; } #endif #if 0//#ifdef _WIN32_WCE #include #include #include char pBuf[] = "WinCE Echo Test Packet"; #define DEFAULT_FAMILY AF_UNSPEC #define DEFAULT_SOCKTYPE SOCK_STREAM #define BUFFER_SIZE 23 // length of "WinCE Echo Test Packet" int netTest (const char * szRemoteName) { SOCKET sock = INVALID_SOCKET; int nFamily = DEFAULT_FAMILY; int nSockType = DEFAULT_SOCKTYPE; SOCKADDR_STORAGE ssRemoteAddr; int cbXfer, cbTotalRecvd, cbRemoteAddrSize; WSADATA wsaData; ADDRINFO Hints, *AddrInfo = NULL, *AI; char szRemoteAddrString[128]; fd_set fdReadSet; TIMEVAL timeout = {2, 0}; char pRecvBuf[BUFFER_SIZE]; if(WSAStartup(MAKEWORD(2,2), &wsaData)) { // WSAStartup failed return -1; } sbMessage("Communicating with server - %hs\r\n",szRemoteName); // // Resolve the server name/address // memset(&Hints, 0, sizeof(Hints)); Hints.ai_family = nFamily; Hints.ai_socktype = nSockType; if(getaddrinfo(szRemoteName, "1234", &Hints, &AddrInfo)) { sbMessage("ERROR: Couldn't get resolve the server name/address!\r\n"); if(sock != INVALID_SOCKET) { shutdown(sock, SD_BOTH); closesocket(sock); } if(AddrInfo) freeaddrinfo(AddrInfo); WSACleanup(); return 0; } // // Attempt to connect to each address until we find one that succeeds // for(AI = AddrInfo; AI != NULL; AI = AI->ai_next) { if((AI->ai_family == PF_INET) || (AI->ai_family == PF_INET6)) // only want PF_INET or PF_INET6 { sock = socket(AI->ai_family, AI->ai_socktype, AI->ai_protocol); if (sock != INVALID_SOCKET) { if (AI->ai_socktype == SOCK_STREAM) { if(connect(sock, AI->ai_addr, AI->ai_addrlen) == SOCKET_ERROR) { // Connect failed, let's close this socket and try again on the next address in the list closesocket(sock); continue; } } sbMessage ("connect() succeeded or we're a UDP socket\r\n"); break; } } } if (AI == NULL) { sbMessage("ERROR: Unable to connect to any of the server's addresses!\r\n"); if(sock != INVALID_SOCKET) { shutdown(sock, SD_BOTH); closesocket(sock); } if(AddrInfo) freeaddrinfo(AddrInfo); WSACleanup(); return 0; } // // Send data to the server // cbXfer = 0; cbXfer = sendto(sock, pBuf, sizeof(pBuf), 0, AI->ai_addr, AI->ai_addrlen); if(cbXfer != sizeof(pBuf)) { sbMessage("ERROR: Couldn't send the data! error = %d\r\n"), WSAGetLastError(); if(sock != INVALID_SOCKET) { shutdown(sock, SD_BOTH); closesocket(sock); } if(AddrInfo) freeaddrinfo(AddrInfo); WSACleanup(); return 0; } if (getnameinfo(AI->ai_addr, AI->ai_addrlen, szRemoteAddrString, sizeof(szRemoteAddrString), NULL, 0, NI_NUMERICHOST) != 0) strcpy(szRemoteAddrString, ""); sbMessage("SUCCESS - Sent %d bytes to address %hs\r\n", cbXfer, szRemoteAddrString); // // Receive the echo'd data back from the server // FD_ZERO(&fdReadSet); FD_SET(sock, &fdReadSet); if(select(0, &fdReadSet, NULL, NULL, &timeout) != 1) { sbMessage("ERROR: Server hasn't responded in %d milliseconds\r\n"), ((timeout.tv_sec * 1000) + (timeout.tv_sec / 1000)); if(sock != INVALID_SOCKET) { shutdown(sock, SD_BOTH); closesocket(sock); } if(AddrInfo) freeaddrinfo(AddrInfo); WSACleanup(); return 0; } cbTotalRecvd = 0; do { cbRemoteAddrSize = sizeof(ssRemoteAddr); cbXfer = recvfrom(sock, pRecvBuf + cbTotalRecvd, sizeof(pRecvBuf) - cbTotalRecvd, 0, (SOCKADDR *)&ssRemoteAddr, &cbRemoteAddrSize); cbTotalRecvd += cbXfer; } while(cbXfer > 0 && cbTotalRecvd < sizeof(pRecvBuf)); if(cbXfer == SOCKET_ERROR) { sbMessage("ERROR: Couldn't receive the data! Error = %d\r\n", WSAGetLastError()); if(sock != INVALID_SOCKET) { shutdown(sock, SD_BOTH); closesocket(sock); } if(AddrInfo) freeaddrinfo(AddrInfo); WSACleanup(); return 0; } else if(cbTotalRecvd != sizeof(pRecvBuf)) { sbMessage("ERROR: Server didn't send back all the expected data!\r\n"); if(sock != INVALID_SOCKET) { shutdown(sock, SD_BOTH); closesocket(sock); } if(AddrInfo) freeaddrinfo(AddrInfo); WSACleanup(); return 0; } if(nSockType == SOCK_STREAM) { memset(&ssRemoteAddr, 0, sizeof(ssRemoteAddr)); cbRemoteAddrSize = sizeof(ssRemoteAddr); getpeername(sock, (SOCKADDR *)&ssRemoteAddr, &cbRemoteAddrSize); } if (getnameinfo((SOCKADDR *)&ssRemoteAddr, cbRemoteAddrSize, szRemoteAddrString, sizeof(szRemoteAddrString), NULL, 0, NI_NUMERICHOST) != 0) strcpy(szRemoteAddrString, ""); sbMessage("SUCCESS - Received %d bytes back from address %hs\r\n", cbTotalRecvd, szRemoteAddrString); if(sock != INVALID_SOCKET) { shutdown(sock, SD_BOTH); closesocket(sock); } if(AddrInfo) freeaddrinfo(AddrInfo); WSACleanup(); return 1; } #endif //#include //#include int WINAPI _tWinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow ) { const TCHAR * appClass = L"SlideBible Application"; const TCHAR * appTitle = L"SlideBible"; int exitCode = 0; //netTest("google.com"); /*{ sword::SWConfig conf (".\\options.conf"); conf.Load(); const char * host = conf["Test"].getWithDefault("address","speedguide.net"); const int port = atoi (conf["Test"].getWithDefault("port","7")); const char * req = (conf["Test"].getWithDefault("request","SlideBible test echo.")); Socket::initWinsocks(); Socket::networkUp(); long ip = Socket::resolveUrl(host); sbMessage("Connecting to %s at %u.%u.%u.%u\n",host,(ip>>0)&0xFF,(ip>>8)&0xFF,(ip>>16)&0xFF,(ip>>24)&0xFF); Socket * ts = new Socket (ip,port); int b = ts->write(req,strlen(req)); sbMessage ("Writen : %i\n",b); Sleep(2000); char rb [256]; memset (&rb,0,256); b = ts->read(rb,256); Sleep(2000); sbMessage ("Received : %i %s\n",b,rb); sbMessage ("Statistics : %s\n",ts->getStatistics()); delete ts; }*/ //mkdir("./20081216195754/modules/texts/ztext/ury_WBTI_2005"); //FileMgr::getSystemFileMgr()->createParent("./20081216195754/modules/texts/ztext/ury_WBTI_2005"); HWND hwnd = FindWindow ( appClass, appTitle ); if (hwnd) { SetForegroundWindow(hwnd); exitCode = -1; } else { HCURSOR oldCursor = SetCursor ( LoadCursor ( NULL, IDC_WAIT ) ); HACCEL accelTable = LoadAccelerators ( hInstance, NULL ); WNDCLASS wc; wc.style = 0; wc.lpfnWndProc = wndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = 0; wc.hIcon = 0; wc.hCursor = 0; wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wc.lpszMenuName = 0; wc.lpszClassName = appClass; SetCursor ( oldCursor ); if ( RegisterClass ( & wc ) ) { #ifdef _WIN32_WCE Window = CreateWindow( appClass, appTitle, WS_VISIBLE, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), NULL, NULL, hInstance, NULL ); // fix: if dirs does not exists module installation can't succeed if (!sword::FileMgr::getSystemFileMgr()->existsDir(".\\mods.d\\")) sword::FileMgr::getSystemFileMgr()->createParent(".\\mods.d\\"); if (!sword::FileMgr::getSystemFileMgr()->existsDir(".\\modules\\")) sword::FileMgr::getSystemFileMgr()->createParent(".\\modules\\"); #else Window = CreateWindow( appClass, appTitle, WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 480, 640, NULL, NULL, hInstance, NULL ); #endif if ( Window == NULL ) { sbMessage ( "Can not create window because of %i error.\n", GetLastError() ); PostQuitMessage ( 1 ); } else { sbCore core; ShowWindow(Window, nCmdShow); UpdateWindow(Window); MSG message; while ( GetMessage ( & message, NULL, 0, 0 ) ) { if ( ! accelTable || ! TranslateAccelerator ( message.hwnd, accelTable, & message ) ) { TranslateMessage ( & message ); DispatchMessage ( & message ); } } DestroyWindow(Window); exitCode = message.wParam; } } } return exitCode; }