int WINAPI ___tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/) { lpCmdLine = GetCommandLine(); //this line necessary for _ATL_MIN_CRT _Module.Init(hInstance, _T("CallMeSleep"), NULL); _Module.m_bService = TRUE; TCHAR szTokens[] = _T("-/"); LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens); while (lpszToken != NULL) { if (lstrcmpi(lpszToken, _T("delete"))==0) return _Module.UnregisterServer(); // Register as Local Server if (lstrcmpi(lpszToken, _T("install"))==0) return _Module.RegisterServer(TRUE, FALSE); if(lstrcmpi(lpszToken, _T("time"))==0) { } lpszToken = FindOneOf(lpszToken, szTokens); } _Module.Start(); // When we get here, the service has been stopped return _Module.m_status.dwWin32ExitCode; }
extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/) { lpCmdLine = GetCommandLine(); //this line necessary for _ATL_MIN_CRT HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED); _ASSERTE(SUCCEEDED(hRes)); _Module.Init(ObjectMap, hInstance, &LIBID_IVMCTRLLib); _Module.dwThreadID = GetCurrentThreadId(); TCHAR szTokens[] = _T("-/"); int nRet = 0; BOOL bRun = TRUE; LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens); while (lpszToken != NULL) { if (lstrcmpi(lpszToken, _T("UnregServer"))==0) { _Module.UpdateRegistryFromResource(IDR_IVMCtrl, FALSE); nRet = _Module.UnregisterServer(TRUE); bRun = FALSE; break; } if (lstrcmpi(lpszToken, _T("RegServer"))==0) { _Module.UpdateRegistryFromResource(IDR_IVMCtrl, TRUE); nRet = _Module.RegisterServer(TRUE); bRun = FALSE; break; } lpszToken = FindOneOf(lpszToken, szTokens); } if (bRun) { _Module.StartMonitor(); #if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED) hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED); _ASSERTE(SUCCEEDED(hRes)); hRes = CoResumeClassObjects(); #else hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE); #endif _ASSERTE(SUCCEEDED(hRes)); MSG msg; while (GetMessage(&msg, 0, 0, 0)) DispatchMessage(&msg); _Module.RevokeClassObjects(); Sleep(dwPause); //wait for any threads to finish } _Module.Term(); CoUninitialize(); return nRet; }
bool ParseCommandLine(LPCTSTR lpCmdLine, HRESULT* pnRetCode ) throw( ) { m_nRestarting = 1; TCHAR szTokens[] = _T("-/"); LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens); getRhoRootPath(); while (lpszToken != NULL) { if (WordCmpI(lpszToken, _T("Restarting"))==0) { m_nRestarting = 10; } #if defined(OS_WINDOWS) else if (wcsncmp(lpszToken, _T("approot"),7)==0) { char* token = wce_wctomb(lpszToken); //parseToken will allocate extra byte at the end of the returned token value char* path = parseToken( token, strlen(token) ); if (path) { int len = strlen(path); if (!(path[len]=='\\' || path[len]=='/')) { path[len] = '\\'; path[len+1] = 0; } m_strRootPath = path; free(path); } free(token); } #endif lpszToken = FindOneOf(lpszToken, szTokens); } return __super::ParseCommandLine(lpCmdLine, pnRetCode); }
extern "C" int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPWSTR lpCmdLine, int /*nShowCmd*/) { lpCmdLine = GetCommandLine(); //this line necessary for _ATL_MIN_CRT HRESULT hr = CoInitialize(NULL); _ASSERTE(SUCCEEDED(hr)); _Module.Init(ObjectMap, hInstance); _Module.dwThreadID = GetCurrentThreadId(); WCHAR wszTokens[] = L"-/"; int nRet = 0; bool bRun = true; LPCWSTR lpwszToken = FindOneOf(lpCmdLine, wszTokens); while (lpwszToken != NULL) { if (_wcsnicmp(lpwszToken, L"UnregServer", 11)==0) { _Module.UpdateRegistryFromResource(IDR_ComSpy, FALSE); nRet = _Module.UnregisterServer(); bRun = false; break; } if (_wcsnicmp(lpwszToken, L"RegServer", 9)==0) { _Module.UpdateRegistryFromResource(IDR_ComSpy, TRUE); nRet = _Module.RegisterServer(TRUE); bRun = false; break; } lpwszToken = FindOneOf(lpwszToken, wszTokens); } if (bRun) { hr = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE); _ASSERTE(SUCCEEDED(hr)); CComPtr<ISpyCon> spApp; hr = CoCreateInstance(CLSID_SpyCon, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&spApp)); _ASSERTE(SUCCEEDED(hr)); if (SUCCEEDED(spApp->Run())) { MSG msg; while (GetMessage(&msg, 0, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } } _Module.RevokeClassObjects(); } CoUninitialize(); return nRet; }
int WinMain(int nShowCmd) throw() { LPCTSTR lpCmdLine = GetCommandLine(); CoInitialize(0); int nRet = 0; HRESULT res; BOOL bRun = TRUE; TCHAR szTokens[] = _T("-/"); LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens); while (lpszToken != NULL) { if (WordCmpI(lpszToken, _T("UnregServer"))==0) { res = this->UnregisterServer(TRUE); if (SUCCEEDED(res)) res = this->UnregisterAppId(); return false; } // Register as Local Server if (WordCmpI(lpszToken, _T("RegServer"))==0) { res = this->RegisterAppId(); if (SUCCEEDED(res)) res = this->RegisterServer(TRUE); return false; } lpszToken = FindOneOf(lpszToken, szTokens); } if (bRun) { // create a modeless dialog to be displayed _ASSERT(CDuckDoer::m_pDlg == NULL); CDuckDoer::m_pDlg = new CDuckDoerDlg(); CDuckDoer::m_pDlg->Create(NULL); CDuckDoer::m_pDlg->ShowWindow(SW_SHOWNORMAL); _ASSERT(CDuckDoer::m_pDlg != NULL); res = this->RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE); _ASSERTE(SUCCEEDED(res)); MSG msg; while (GetMessage(&msg, 0, 0, 0)) DispatchMessage(&msg); this->RevokeClassObjects(); } CoUninitialize(); return nRet; }
extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/) { lpCmdLine = GetCommandLine(); HRESULT hRes = CoInitialize(NULL); // If you are running on NT 4.0 or higher you can use the following call // instead to make the EXE free threaded. // This means that calls come in on a random RPC thread // HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED); _ASSERTE(SUCCEEDED(hRes)); _Module.Init(ObjectMap, hInstance); _Module.dwThreadID = GetCurrentThreadId(); TCHAR szTokens[] = _T("-/"); int nRet = 0; BOOL bRun = TRUE; LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens); while (lpszToken != NULL) { if (lstrcmpi(lpszToken, _T("UnregServer"))==0) { _Module.UpdateRegistryFromResource(IDR_Stlcoll, FALSE); nRet = _Module.UnregisterServer(); bRun = FALSE; break; } if (lstrcmpi(lpszToken, _T("RegServer"))==0) { _Module.UpdateRegistryFromResource(IDR_Stlcoll, TRUE); nRet = _Module.RegisterServer(TRUE); bRun = FALSE; break; } lpszToken = FindOneOf(lpszToken, szTokens); } if (bRun) { hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE); _ASSERTE(SUCCEEDED(hRes)); MSG msg; while (GetMessage(&msg, 0, 0, 0)) DispatchMessage(&msg); _Module.RevokeClassObjects(); } CoUninitialize(); return nRet; }
extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/) { lpCmdLine = GetCommandLine(); //this line necessary for _ATL_MIN_CRT _Module.Init(ObjectMap, hInstance, IDS_SERVICENAME, &LIBID_SENDERSERVERLib); _Module.m_bService = TRUE; TCHAR szTokens[] = _T("-/"); LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens); while (lpszToken != NULL) { if (lstrcmpi(lpszToken, _T("UnregServer"))==0) return _Module.UnregisterServer(); // Register as Local Server if (lstrcmpi(lpszToken, _T("RegServer"))==0) return _Module.RegisterServer(TRUE, FALSE); // Register as Service if (lstrcmpi(lpszToken, _T("Service"))==0) return _Module.RegisterServer(TRUE, TRUE); lpszToken = FindOneOf(lpszToken, szTokens); } // Are we Service or Local Server CRegKey keyAppID; LONG lRes = keyAppID.Open(HKEY_CLASSES_ROOT, _T("AppID"), KEY_READ); if (lRes != ERROR_SUCCESS) return lRes; CRegKey key; lRes = key.Open(keyAppID, _T("{87AB90ED-EFD4-4A6B-9CC7-6C87D5704FED}"), KEY_READ); if (lRes != ERROR_SUCCESS) return lRes; TCHAR szValue[_MAX_PATH]; DWORD dwLen = _MAX_PATH; lRes = key.QueryValue(szValue, _T("LocalService"), &dwLen); _Module.m_bService = FALSE; if (lRes == ERROR_SUCCESS) _Module.m_bService = TRUE; _Module.Start(); // When we get here, the service has been stopped return _Module.m_status.dwWin32ExitCode; }
/*! install service -i uninstall service -u run as service -runas service run as session -runas session -parent n check and install -c run hook -runas hook -parent n */ bool ParseCommandLine(LPCTSTR lpCmdLine, HRESULT* pnRetCode) throw() { if (!CAtlServiceModuleT< CWinRobotHostModule, IDS_SERVICENAME >::ParseCommandLine(lpCmdLine, pnRetCode)) return false; TCHAR szTokens[] = _T("-/"); *pnRetCode = S_OK; LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens); while (lpszToken != NULL) { if (WordCmpI(lpszToken, _T("I"))==0) // install { *pnRetCode = RegisterAppId(true); if (SUCCEEDED(*pnRetCode)) *pnRetCode = RegisterServer(TRUE); return false; } else if (WordCmpI(lpszToken, _T("U"))==0)// uninstall { *pnRetCode = UnregisterServer(TRUE); if (SUCCEEDED(*pnRetCode)) *pnRetCode = UnregisterAppId(); return false; } else if (WordCmpI(lpszToken, _T("runas"))==0) { lpszToken = FindOneOf(lpszToken, _T(" ")); if (WordCmpI(lpszToken, _T("service")) == 0) // run as service { return true; } else if(WordCmpI(lpszToken, _T("session")) == 0) // run as session { lpszToken = FindOneOf(lpszToken, _T("-/")); if(WordCmpI(lpszToken, _T("parent")) == 0) { lpszToken = FindOneOf(lpszToken, _T(" ")); CSessionHost host(_tcstoul(lpszToken,0,10)); host.Run(); host.WaitThreadEnd(); } } else if(WordCmpI(lpszToken, _T("hook")) == 0) // run as session { lpszToken = FindOneOf(lpszToken, _T("-/")); if(WordCmpI(lpszToken, _T("parent")) == 0) { lpszToken = FindOneOf(lpszToken, _T(" ")); CHookHost host(_tcstoul(lpszToken,0,10)); host.Run(); } } return false; } lpszToken = FindOneOf(lpszToken, szTokens); } return true; }
int CUnicodeString::FindOneOf(LPCSTR lpszCharSet) const { ASSERT(IsValidString(lpszCharSet)); DWORD dwszLen = strlen(lpszCharSet); LPWSTR lpwsz = (LPWSTR)malloc((dwszLen + 1) * sizeof(WCHAR)); lpwsz[dwszLen] = L'\0'; MultiByteToWideChar(CP_ACP, 0, lpszCharSet, dwszLen, lpwsz, dwszLen); int iRet = FindOneOf(lpwsz); free(lpwsz); return iRet; }
// OnOK() calls wxWindow::Validate, then wxWindow::TransferDataFromWindow. // If this returns TRUE, the function either calls EndModal(wxID_OK) if the // dialog is modal, or sets the return value to wxID_OK and calls Show(FALSE) // if the dialog is modeless. void COutputFilenameDlg::OnOK(wxCommandEvent& event) { // ensure there are no illegal characters in the filename //TransferDataFromWindow(); // whm removed 21Nov11 m_strFilename = pEdit->GetValue(); // whm added 21Nov11 wxString fn = m_strFilename; wxString illegals = wxFileName::GetForbiddenChars(); //_T(":?*\"\\/|<>"); wxString scanned = SpanExcluding(fn, illegals); if (scanned == fn) { // BW added 22July08; check for a name clash bool bNamesClash = gpApp->GetDocument()->FilenameClash(fn); if (bNamesClash) { // IDS_TYPED_DOCNAME_CLASHES wxMessageBox(_("The name you typed clashes with an existing document name. Please type a different name.") ,_T(""), wxICON_EXCLAMATION | wxOK); return; // leave user in the dialog, to fix the name } } else { // there is at least one illegal character, replace each such // by a space, beep, and show the modified string to the user //int nFound = -1; // whm Note: Since different platforms have slightly differing illegal characters for file // names, etc., we will not hard code the search for characters as does the MFC version. // Instead, we'll scan the file name char by char and change any that are illegal to spaces. int ct; int foundPos; for (ct = 0; ct < (int)fn.Length(); ct++) { foundPos = FindOneOf(fn, illegals); if (foundPos != -1) fn[foundPos] = _T(' '); } m_strFilename = fn; //TransferDataFromWindow(); // whm removed 21Nov11 // whm note 21Nov11 the TransferDataFromWindow() call above would defeat the preceding code // that replaces any illegal char with a space, so I've removed it entirely. ::wxBell(); // if we decide to verbally tell the user what the beep means: //wxString message; //message = message.Format(_("Names cannot include these characters: %s (Note: An .xml extension will be automatically added.) Please try the New... command again."),illegals.c_str()); //wxMessageBox(message, _("Bad characters found in name"), wxICON_INFORMATION | wxOK); } } event.Skip(); //EndModal(wxID_OK); //AIModalDialog::OnOK(event); // not virtual in wxDialog }
//============================================================================================ // MAIN //============================================================================================ extern "C" int WINAPI WinMain( HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPSTR lpCmdLine, // command line int nCmdShow ){ // show state HANDLE hMutex; TCHAR szTokens[] = "-/"; LPCTSTR lpszToken; int iRes; HWND hDlgWnd; UINT uiTimerID; HRESULT hr; // Check for another instance hMutex = OpenMutex( SYNCHRONIZE, // requested access (lowest possible) FALSE, // allow inheritance (does not matter) x_szMutexName); // unique name if(hMutex){ MessageBox( NULL, "Cannot start the application because another instance is already running.\n", x_szTitle, MB_OK | MB_ICONERROR ); return 1; } hMutex = CreateMutex( NULL, // default security TRUE, // obtain ownership x_szMutexName); // unique name if(!hMutex){ MessageBox( NULL, "Cannot create application mutex.\n", x_szTitle, MB_OK | MB_ICONERROR ); return 1; } // Parse the command line for options lpszToken = FindOneOf(lpCmdLine, szTokens); while (lpszToken != NULL) { if (lstrcmpi(lpszToken, "UnregServer")==0) { iRes = g_UnregisterCOM(); if( iRes != 0 ) { MessageBox( NULL, "Error: Can't unregister server. g_UnregisterCOM() failed.", x_szTitle, MB_OK); } else { MessageBox( NULL, "Success: the server is unregistered.", x_szTitle, MB_OK); } return iRes; } if (lstrcmpi(lpszToken, "RegServer")==0) { iRes = g_RegisterCOM(); if( iRes != 0 ) { MessageBox( NULL, "Error: Can't register server. g_RegisterCOM() failed.", x_szTitle, MB_OK); } else { MessageBox( NULL, "Success: the server is registered.", x_szTitle, MB_OK); } return iRes; } lpszToken = FindOneOf(lpszToken, szTokens); } // while there are tokens //------- Windows staff starts here CP_printfCreate(x_szTitle); // create console window hDlgWnd=CreateDialog(hInstance, MAKEINTRESOURCE(IDD_MAIN_DIALOG), NULL, x_DialogProc); g_hWnd = hDlgWnd; SetWindowText(hDlgWnd, x_szTitle); SendMessage(hDlgWnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON_APPL))); SendMessage(hDlgWnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadImage(hInstance, MAKEINTRESOURCE(IDI_ICON_APPL), IMAGE_ICON, 16, 16, 0)); ShowWindow(hDlgWnd, SW_SHOW); CP_printf(g_szVersion); CP_printf("\n\n"); uiTimerID = SetTimer( hDlgWnd, TIMER_ID, TIMER_PERIOD_MS, NULL ); if ( uiTimerID == 0){ CP_printf("Error: could not create timer!"); // don't exit we are still functional } CP_printfHide(); // default is no log window // Init COM using single-thread apartment model hr = CoInitialize(NULL); if( hr != S_OK) { MessageBox( NULL, "Error in CoInitializeEx()", x_szTitle, MB_OK); return 1; } iRes = g_Init_LibertyTrack( ); if( iRes != 0 ) { MessageBox( NULL, "Error: g_Init_LibertyTrack() failed.", x_szTitle, MB_OK); return 1; } // Message loop MSG msg; while (GetMessage(&msg, 0, 0, 0)) { // IsDialogMessage() processes keyboard events for the dialog and // passes others to translate/dispatch if(!IsDialogMessage(hDlgWnd,&msg)){ TranslateMessage(&msg); DispatchMessage(&msg); } } // end of uMsg loop KillTimer( hDlgWnd, TIMER_ID); CoUninitialize(); ReleaseMutex(hMutex); return 0; }
//=========================================================================== extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nShowCmd ) { HANDLE hMutex; int iRet; HRESULT hRes; TCHAR szTokens[] = _T("-/"); // Check for another instance hMutex = OpenMutex( SYNCHRONIZE, // requested access (lowest possible) FALSE, // allow inheritance (does not matter) x_szMutexName); // unique name if(hMutex){ MessageBox( NULL, "Cannot start the application because another instance is already running.\n", g_szAppTitile, MB_OK | MB_ICONERROR ); return 1; } hMutex = CreateMutex( NULL, // default security TRUE, // obtain ownership x_szMutexName); // unique name if(!hMutex){ MessageBox( NULL, "Cannot create application mutex.\n", g_szAppTitile, MB_OK | MB_ICONERROR ); return 1; } hRes = CoInitialize(NULL); // single-threaded apartment _ASSERTE(SUCCEEDED(hRes)); _Module.Init(ObjectMap, hInstance, &LIBID_CP_DISPLAYLib); hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE); _ASSERTE(SUCCEEDED(hRes)); lpCmdLine = GetCommandLine(); //this line is necessary for _ATL_MIN_CRT // Parse the command line for options LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens); while (lpszToken != NULL) { if (lstrcmpi(lpszToken, "UnregServer")==0) { _Module.UpdateRegistryFromResource(IDR_CP_Display, FALSE); iRet = _Module.UnregisterServer(TRUE); // iRet = g_UnregisterCOM(); if( iRet != 0 ) { MessageBox( NULL, "Error: Can't unregister server. UnregisterServer() failed.", g_szAppTitile, MB_OK); } else { MessageBox( NULL, "Success: the server is unregistered.", g_szAppTitile, MB_OK); } _Module.Term(); CoUninitialize(); return iRet; } if (lstrcmpi(lpszToken, "RegServer")==0) { iRet = _Module.UpdateRegistryFromResource(IDR_CP_Display, TRUE); iRet = _Module.RegisterServer(TRUE); //iRet = g_RegisterCOM(); if( iRet != 0 ) { char str[200]; sprintf(str,"Error: Can't register server. g_RegisterCOM() failed (%lx).",(unsigned long)iRet); MessageBox( NULL, str, g_szAppTitile, MB_OK); //MessageBox( NULL, "Error: Can't register server. g_RegisterCOM() failed.", g_szAppTitile, MB_OK); } else { MessageBox( NULL, "Success: the server is registered.", g_szAppTitile, MB_OK); } _Module.Term(); CoUninitialize(); return iRet; } lpszToken = FindOneOf(lpszToken, szTokens); } // while there are tokens CP_printfCreate( g_szAppTitile ); // Creates log window (console) CP_printf("%s\n", g_szVersion ); CP_printf("----------------------------------------\n"); CP_printf("Build options:\n\n"); //~~~~~~~~~~~~~~~~~ #ifdef _DEBUG CP_printf("Debug version.\n"); #else CP_printf("Release version. \n\n"); #endif // #ifdef _DEBUG //~~~~~~~~~~~~~~~~~ CP_printf("SET_FULLSCREEN_MODE: %d\n", SET_FULLSCREEN_MODE); CP_printf("DEBUG_THRESHOLD: %d\n", DEBUG_THRESHOLD); CP_printf("----------------------------------------\n"); srand( (unsigned)123 ); try { if ( !g_StartGL_Engine( hInstance, nShowCmd ) ){ g_MainLoop(); } } catch( ... ) { MessageBox( NULL, "Exception!!! SOS!!! The program will shut down!", g_szAppTitile, MB_OK | MB_ICONERROR ); exit(1); } CP_printf("N objects before quitting: %d\n", _Module.GetLockCount() ); _Module.RevokeClassObjects(); Sleep(COM_THREAD_WAIT_MS); //wait for any threads to finish // WrapUp _Module.Term(); CoUninitialize(); // Left-over objects are deleted in CoUninitialize(). Since they call RequestUpdate // in the destuctor, we have to delete GL_Window after CoUninitialize() g_StopGL_Engine( ); InvalidateRect(NULL, NULL, TRUE); // redraw the desktop Sleep(5000); // show log window for 5 sec before quitting CP_printfDestroy( ); // Kills log window (console) ReleaseMutex(hMutex); return 0; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int /*nShowCmd*/) { LPCTSTR lpCmdLine = GetCommandLine(); /* this line necessary for _ATL_MIN_CRT */ /* * Need to parse the command line before initializing the VBox runtime. */ TCHAR szTokens[] = _T("-/"); LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens); while (lpszToken != NULL) { if (WordCmpI(lpszToken, _T("Embedding")) == 0) { /* %HOMEDRIVE%%HOMEPATH% */ wchar_t wszHome[RTPATH_MAX]; DWORD cEnv = GetEnvironmentVariable(L"HOMEDRIVE", &wszHome[0], RTPATH_MAX); if (cEnv && cEnv < RTPATH_MAX) { DWORD cwc = cEnv; /* doesn't include NUL */ cEnv = GetEnvironmentVariable(L"HOMEPATH", &wszHome[cEnv], RTPATH_MAX - cwc); if (cEnv && cEnv < RTPATH_MAX - cwc) { /* If this fails there is nothing we can do. Ignore. */ SetCurrentDirectory(wszHome); } } } lpszToken = FindOneOf(lpszToken, szTokens); } /* * Initialize the VBox runtime without loading * the support driver. */ int argc = __argc; char **argv = __argv; RTR3InitExe(argc, &argv, 0); /* Note that all options are given lowercase/camel case/uppercase to * approximate case insensitive matching, which RTGetOpt doesn't offer. */ static const RTGETOPTDEF s_aOptions[] = { { "--embedding", 'e', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE }, { "-embedding", 'e', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE }, { "/embedding", 'e', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE }, { "--unregserver", 'u', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE }, { "-unregserver", 'u', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE }, { "/unregserver", 'u', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE }, { "--regserver", 'r', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE }, { "-regserver", 'r', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE }, { "/regserver", 'r', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE }, { "--reregserver", 'f', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE }, { "-reregserver", 'f', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE }, { "/reregserver", 'f', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE }, { "--helper", 'H', RTGETOPT_REQ_STRING | RTGETOPT_FLAG_ICASE }, { "-helper", 'H', RTGETOPT_REQ_STRING | RTGETOPT_FLAG_ICASE }, { "/helper", 'H', RTGETOPT_REQ_STRING | RTGETOPT_FLAG_ICASE }, { "--logfile", 'F', RTGETOPT_REQ_STRING | RTGETOPT_FLAG_ICASE }, { "-logfile", 'F', RTGETOPT_REQ_STRING | RTGETOPT_FLAG_ICASE }, { "/logfile", 'F', RTGETOPT_REQ_STRING | RTGETOPT_FLAG_ICASE }, { "--logrotate", 'R', RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_ICASE }, { "-logrotate", 'R', RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_ICASE }, { "/logrotate", 'R', RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_ICASE }, { "--logsize", 'S', RTGETOPT_REQ_UINT64 | RTGETOPT_FLAG_ICASE }, { "-logsize", 'S', RTGETOPT_REQ_UINT64 | RTGETOPT_FLAG_ICASE }, { "/logsize", 'S', RTGETOPT_REQ_UINT64 | RTGETOPT_FLAG_ICASE }, { "--loginterval", 'I', RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_ICASE }, { "-loginterval", 'I', RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_ICASE }, { "/loginterval", 'I', RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_ICASE }, }; bool fRun = true; bool fRegister = false; bool fUnregister = false; const char *pszPipeName = NULL; const char *pszLogFile = NULL; uint32_t cHistory = 10; // enable log rotation, 10 files uint32_t uHistoryFileTime = RT_SEC_1DAY; // max 1 day per file uint64_t uHistoryFileSize = 100 * _1M; // max 100MB per file RTGETOPTSTATE GetOptState; int vrc = RTGetOptInit(&GetOptState, argc, argv, &s_aOptions[0], RT_ELEMENTS(s_aOptions), 1, 0 /*fFlags*/); AssertRC(vrc); RTGETOPTUNION ValueUnion; while ((vrc = RTGetOpt(&GetOptState, &ValueUnion))) { switch (vrc) { case 'e': /* already handled above */ break; case 'u': fUnregister = true; fRun = false; break; case 'r': fRegister = true; fRun = false; break; case 'f': fUnregister = true; fRegister = true; fRun = false; break; case 'H': pszPipeName = ValueUnion.psz; if (!pszPipeName) pszPipeName = ""; fRun = false; break; case 'F': pszLogFile = ValueUnion.psz; break; case 'R': cHistory = ValueUnion.u32; break; case 'S': uHistoryFileSize = ValueUnion.u64; break; case 'I': uHistoryFileTime = ValueUnion.u32; break; case 'h': { TCHAR txt[]= L"Options:\n\n" L"/RegServer:\tregister COM out-of-proc server\n" L"/UnregServer:\tunregister COM out-of-proc server\n" L"/ReregServer:\tunregister and register COM server\n" L"no options:\trun the server"; TCHAR title[]=_T("Usage"); fRun = false; MessageBox(NULL, txt, title, MB_OK); return 0; } case 'V': { char *psz = NULL; RTStrAPrintf(&psz, "%sr%s\n", RTBldCfgVersion(), RTBldCfgRevisionStr()); PRTUTF16 txt = NULL; RTStrToUtf16(psz, &txt); TCHAR title[]=_T("Version"); fRun = false; MessageBox(NULL, txt, title, MB_OK); RTStrFree(psz); RTUtf16Free(txt); return 0; } default: /** @todo this assumes that stderr is visible, which is not * true for standard Windows applications. */ /* continue on command line errors... */ RTGetOptPrintError(vrc, &ValueUnion); } } /* Only create the log file when running VBoxSVC normally, but not when * registering/unregistering or calling the helper functionality. */ if (fRun) { if (!pszLogFile) { char szLogFile[RTPATH_MAX]; vrc = com::GetVBoxUserHomeDirectory(szLogFile, sizeof(szLogFile)); if (RT_SUCCESS(vrc)) vrc = RTPathAppend(szLogFile, sizeof(szLogFile), "VBoxSVC.log"); if (RT_SUCCESS(vrc)) pszLogFile = RTStrDup(szLogFile); } char szError[RTPATH_MAX + 128]; vrc = com::VBoxLogRelCreate("COM Server", pszLogFile, RTLOGFLAGS_PREFIX_THREAD | RTLOGFLAGS_PREFIX_TIME_PROG, "all", "VBOXSVC_RELEASE_LOG", RTLOGDEST_FILE, UINT32_MAX /* cMaxEntriesPerGroup */, cHistory, uHistoryFileTime, uHistoryFileSize, szError, sizeof(szError)); if (RT_FAILURE(vrc)) return RTMsgErrorExit(RTEXITCODE_FAILURE, "failed to open release log (%s, %Rrc)", szError, vrc); } int nRet = 0; HRESULT hRes = com::Initialize(); _ASSERTE(SUCCEEDED(hRes)); _Module.Init(ObjectMap, hInstance, &LIBID_VirtualBox); _Module.dwThreadID = GetCurrentThreadId(); if (!fRun) { if (fUnregister) { _Module.UpdateRegistryFromResource(IDR_VIRTUALBOX, FALSE); nRet = _Module.UnregisterServer(TRUE); } if (fRegister) { _Module.UpdateRegistryFromResource(IDR_VIRTUALBOX, TRUE); nRet = _Module.RegisterServer(TRUE); } if (pszPipeName) { Log(("SVCMAIN: Processing Helper request (cmdline=\"%s\")...\n", pszPipeName)); if (!*pszPipeName) vrc = VERR_INVALID_PARAMETER; if (RT_SUCCESS(vrc)) { /* do the helper job */ SVCHlpServer server; vrc = server.open(pszPipeName); if (RT_SUCCESS(vrc)) vrc = server.run(); } if (RT_FAILURE(vrc)) { Log(("SVCMAIN: Failed to process Helper request (%Rrc).", vrc)); nRet = 1; } } } else { _Module.StartMonitor(); #if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED) hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED); _ASSERTE(SUCCEEDED(hRes)); hRes = CoResumeClassObjects(); #else hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE); #endif _ASSERTE(SUCCEEDED(hRes)); MSG msg; while (GetMessage(&msg, 0, 0, 0)) DispatchMessage(&msg); _Module.RevokeClassObjects(); Sleep(dwPause); //wait for any threads to finish } _Module.Term(); com::Shutdown(); Log(("SVCMAIN: Returning, COM server process ends.\n")); return nRet; }
extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/) { lpCmdLine = GetCommandLine(); //this line necessary for _ATL_MIN_CRT _Module.Init(ObjectMap, hInstance, IDS_SERVICENAME, IDS_SERVICEDISPLAYNAME, &LIBID_VIRTUOSOSINKLib); _Module.m_bService = TRUE; TCHAR szTokens[] = _T("-/"); LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens); while (lpszToken != NULL) { if (lstrcmpi(lpszToken, _T("UnregServer"))==0) return _Module.UnregisterServer(); // Register as Local Server if (lstrcmpi(lpszToken, _T("RegServer"))==0) return _Module.RegisterServer(TRUE, FALSE); // Register as Service if (lstrcmpi(lpszToken, _T("Service"))==0) return _Module.RegisterServer(TRUE, TRUE); // Register as Service if (lstrcmpi(lpszToken, _T("Help"))==0 || lstrcmpi(lpszToken, _T("?"))==0) { char szBuffer[4096]; wsprintf (szBuffer, "%s Help", _Module.m_szServiceDisplayName); ::MessageBox (NULL, "/RegServer\t - registers the COM server\n" "/Service\t\t - registers the COM server & the service instance\n" "/UnregServer\t - unregisters the service instance & the COM server\n", szBuffer, MB_OK | MB_ICONINFORMATION); return TRUE; } lpszToken = FindOneOf(lpszToken, szTokens); } // Are we Service or Local Server CRegKey keyAppID; LONG lRes = keyAppID.Open(HKEY_CLASSES_ROOT, _T("AppID"), KEY_READ); if (lRes != ERROR_SUCCESS) return lRes; CRegKey key; lRes = key.Open(keyAppID, _T("{C9C50643-AE52-11D4-8986-00E018001CA1}"), KEY_READ); if (lRes != ERROR_SUCCESS) return lRes; TCHAR szValue[_MAX_PATH]; DWORD dwLen = _MAX_PATH; lRes = key.QueryValue(szValue, _T("LocalService"), &dwLen); _Module.m_bService = FALSE; if (lRes == ERROR_SUCCESS) _Module.m_bService = TRUE; _Module.Start(); // When we get here, the service has been stopped return _Module.m_status.dwWin32ExitCode; }
extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/) { lpCmdLine = GetCommandLine(); //this line necessary for _ATL_MIN_CRT HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED); _ASSERTE(SUCCEEDED(hRes)); _Module.Init(ObjectMap, hInstance, &LIBID_HYPERFEEDPROVIDERSLib); _Module.dwThreadID = GetCurrentThreadId(); TCHAR szTokens[] = _T("-/"); int nRet = 0; BOOL bRun = TRUE; LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens); while (lpszToken != NULL) { if (lstrcmpi(lpszToken, _T("UnregServer"))==0) { _Module.UpdateRegistryFromResource(IDR_HyperFeedProviders, FALSE); nRet = _Module.UnregisterServer(TRUE); bRun = FALSE; break; } if (lstrcmpi(lpszToken, _T("RegServer"))==0) { _Module.UpdateRegistryFromResource(IDR_HyperFeedProviders, TRUE); nRet = _Module.RegisterServer(TRUE); bRun = FALSE; break; } lpszToken = FindOneOf(lpszToken, szTokens); } if (bRun) { // Starting with trace EgStd::g_pTrace = new CHyperFeedTrace(); EgStd::g_pTrace->Init(); #ifndef _DEBUG SetMiniDumpDefaultCrashHandler(); #endif ATLVERIFY(SUCCEEDED(_Module.LoadExchangeCodes())); ATLVERIFY(SUCCEEDED(_Module.LoadProviderSettings())); _Module.StartMonitor(); #if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED) hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED); _ASSERTE(SUCCEEDED(hRes)); hRes = CoResumeClassObjects(); #else hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE); #endif _ASSERTE(SUCCEEDED(hRes)); MSG msg; while (GetMessage(&msg, 0, 0, 0)) DispatchMessage(&msg); _Module.RevokeClassObjects(); Sleep(dwPause); //wait for any threads to finish // Exit the tracing EgStd::g_pTrace->Exit(); if (EgStd::g_pTrace != NULL) delete EgStd::g_pTrace; } _Module.Term(); CoUninitialize(); return nRet; }
BOOL CMyApp::InitInstance() { if (!DComOk()) { AfxMessageBox(_T("DCOM OLE Not supported"),MB_SYSTEMMODAL+MB_OK); return FALSE; } // Initialize OLE libraries if (!AfxOleInit2()) { AfxMessageBox(_T("OLE Initialization Failed!"),MB_SYSTEMMODAL+MB_OK); return FALSE; } // Initialize the ATL Module _Module.Init(ObjectMap,m_hInstance); _Module.dwThreadID = GetCurrentThreadId(); #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking // to MFC statically #endif //Reg UnregSever TCHAR szTokens[] = _T("-/"); int nRet = 0; BOOL bRun = TRUE; LPCTSTR lpszToken = FindOneOf(m_lpCmdLine, szTokens); while (lpszToken != NULL) { if (lstrcmpi(lpszToken, _T("UnregServer"))==0) { _Module.UpdateRegistryFromResource(IDR_ModbusServer, FALSE); nRet = _Module.UnregisterServer(); nRet = UnRegisterTypeLib( LIBID_MODBUSSERVERLib, 1, 0, LOCALE_NEUTRAL, SYS_WIN32); bRun = FALSE; break; } if (lstrcmpi(lpszToken, _T("RegServer"))==0) { _Module.UpdateRegistryFromResource(IDR_ModbusServer, TRUE); nRet = _Module.RegisterServer(TRUE); bRun = FALSE; // Update the System Registry COleObjectFactory::UpdateRegistryAll(); // MFC Classes if(!(SUCCEEDED(nRet))){ AfxMessageBox("Register server Failed",MB_SYSTEMMODAL+MB_OK); } bRun=FALSE; break; } lpszToken = FindOneOf(lpszToken, szTokens); } // ATL Classes // Create the dialog box or other stuff here // Register OLE Class Factories // MFC ones are for multiple as specified // by the IMPLEMENT_OLECREATE() macro //COleObjectFactory::RegisterAll(); // ATL ones specifically register with REGCLS_MULTIPLEUSE if (bRun) { if(!(SUCCEEDED(_Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE)))){ AfxMessageBox("RegisterClassObjects Failed",MB_SYSTEMMODAL+MB_OK); } } VERIFY(CTcpServer::StartWinsock()); // Parse the command line to see if launched as OLE server if (RunEmbedded() || RunAutomated()) { // Application was run with /Embedding or /Automation. // Don't show the main window in this case. //Test(); return TRUE; } return FALSE; // Nothing to do, so exit. }
//============================================================================================ // MAIN //============================================================================================ extern "C" int WINAPI WinMain( HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPSTR lpCmdLine, // command line int nCmdShow ){ // show state HANDLE hMutex; TCHAR szTokens[] = "-/"; LPCTSTR lpszToken; int iRes; HRESULT hRes; x_hInstance = hInstance; // Check for another instance hMutex = OpenMutex( SYNCHRONIZE, // requested access (lowest possible) FALSE, // allow inheritance (does not matter) x_szMutexName); // unique name if(hMutex){ MessageBox( NULL, "Cannot start the application because another instance is already running.\n", x_szTitle, MB_OK | MB_ICONERROR ); return 1; } hMutex = CreateMutex( NULL, // default security TRUE, // obtain ownership x_szMutexName); // unique name if(!hMutex){ MessageBox( NULL, "Cannot create application mutex.\n", x_szTitle, MB_OK | MB_ICONERROR ); return 1; } // Parse the command line for options lpszToken = FindOneOf(lpCmdLine, szTokens); while (lpszToken != NULL) { if (lstrcmpi(lpszToken, "UnregServer")==0) { iRes = g_UnregisterCOM(); if( iRes != 0 ) { MessageBox( NULL, "Error: Can't unregister server. g_UnregisterCOM() failed.", x_szTitle, MB_OK); } else { MessageBox( NULL, "Success: the server is unregistered.", x_szTitle, MB_OK); } return iRes; } if (lstrcmpi(lpszToken, "RegServer")==0) { iRes = g_RegisterCOM(); if( iRes != 0 ) { MessageBox( NULL, "Error: Can't register server. g_RegisterCOM() failed.", x_szTitle, MB_OK); } else { MessageBox( NULL, "Success: the server is registered.", x_szTitle, MB_OK); } return iRes; } lpszToken = FindOneOf(lpszToken, szTokens); } // while there are tokens //------- Regular run starts here // Init COM using single-threaded model hRes = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); if( hRes != S_OK) { MessageBox( NULL, "Error in CoInitializeEx()", x_szTitle, MB_OK); return 1; } CP_printfCreate(x_szTitle); // create console window CP_printf(g_szVersion); CP_printf("\n\n"); CP_printfHide(); // hide console window //------- Windows main loop is here DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN_DIALOG), NULL, x_DialogProc); CP_printfDestroy(); CoUninitialize(); return 0; }
extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/) { lpCmdLine = GetCommandLine(); // この行は _ATL_MIN_CRT のために必要です #if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED) HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED); #else HRESULT hRes = CoInitialize(NULL); #endif _ASSERTE(SUCCEEDED(hRes)); _Module.Init(ObjectMap, hInstance, &LIBID_ATLDEVICEMANAGERLib); _Module.dwThreadID = GetCurrentThreadId(); TCHAR szTokens[] = _T("-/"); int nRet = 0; BOOL bRun = TRUE; LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens); while (lpszToken != NULL) { if (lstrcmpi(lpszToken, _T("UnregServer"))==0) { _Module.UpdateRegistryFromResource(IDR_ATLDeviceManager, FALSE); nRet = _Module.UnregisterServer(TRUE); bRun = FALSE; break; } if (lstrcmpi(lpszToken, _T("RegServer"))==0) { _Module.UpdateRegistryFromResource(IDR_ATLDeviceManager, TRUE); nRet = _Module.RegisterServer(TRUE); bRun = FALSE; break; } lpszToken = FindOneOf(lpszToken, szTokens); } if (bRun) { HWND dummy_dialog_handle = NULL; //::AllocConsole(); ProcessInstance = hInstance; dummy_dialog_handle = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DUMMYDIALOG), NULL, DummyDialogProc); ShowWindow(dummy_dialog_handle, SW_HIDE); _Module.StartMonitor(); #if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED) hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED); _ASSERTE(SUCCEEDED(hRes)); hRes = CoResumeClassObjects(); #else hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE); #endif _ASSERTE(SUCCEEDED(hRes)); MSG msg; while (GetMessage(&msg, 0, 0, 0)) DispatchMessage(&msg); _Module.RevokeClassObjects(); Sleep(dwPause); //スレッドが終了するまで待ちます if(dummy_dialog_handle != NULL) ::DestroyWindow(dummy_dialog_handle); ::FreeConsole(); } _Module.Term(); CoUninitialize(); return nRet; }
extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/) { #if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED) HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); #else HRESULT hr = CoInitialize(NULL); #endif // SetMiniDumpDefaultCrashHandler(); _ASSERTE(SUCCEEDED(hr)); lpCmdLine = GetCommandLine(); //this line necessary for _ATL_MIN_CRT _Module.m_bService = FALSE; TCHAR szTokens[] = _T("-/"); LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens); while (lpszToken != NULL) { if (lstrcmpi(lpszToken, _T("Install"))==0) { _Module.Init(ObjectMap, hInstance, IDS_SERVICENAME, &LIBID_TRANSPORTLib); _Module.m_bService = TRUE; // CRouter::Install(); return _Module.Install(); } if (lstrcmpi(lpszToken, _T("Uninstall"))==0) { _Module.Init(ObjectMap, hInstance, IDS_SERVICENAME, &LIBID_TRANSPORTLib); _Module.m_bService = TRUE; // CRouter::Uninstall(); return _Module.Uninstall(); } if (lstrcmpi(lpszToken, _T("UnregServer"))==0) { _Module.Init(ObjectMap, hInstance, IDS_SERVICENAME, &LIBID_TRANSPORTLib); _Module.m_bService = TRUE; _Module.UpdateRegistryFromResource(IDR_Transport, FALSE); return _Module.UnregisterServer(); } if (lstrcmpi(lpszToken, _T("RegServer"))==0) { _Module.Init(ObjectMap, hInstance, IDS_SERVICENAME, &LIBID_TRANSPORTLib); _Module.m_bService = TRUE; _Module.UpdateRegistryFromResource(IDR_Transport, TRUE); return _Module.RegisterServer(TRUE,TRUE); } if (lstrcmpi(lpszToken, _T("Debug"))==0) { _Module.CComModule::Init(ObjectMap, hInstance, &LIBID_TRANSPORTLib); _Module.Start(); _Module.Term(); ::CoUninitialize(); return 0; } lpszToken = FindOneOf(lpszToken, szTokens); } _Module.Init(ObjectMap, hInstance, IDS_SERVICENAME, &LIBID_TRANSPORTLib); _Module.m_bService = TRUE; _Module.Start(); _Module.Term(); ::CoUninitialize(); // When we get here, the service has been stopped return _Module.m_status.dwWin32ExitCode; }
extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/) { lpCmdLine = GetCommandLine(); //this line necessary for _ATL_MIN_CRT _Module.Init(ObjectMap, hInstance, IDS_SERVICENAME, &LIBID_WIPPIENSERVICELib); _Module.m_bService = TRUE; TCHAR szTokens[] = _T("-/"); LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens); while (lpszToken != NULL) { if (_strnicmp(lpszToken, _T("UnregServer"), 11)==0) flagUnregServer = TRUE; // Register as Local Server if (_strnicmp(lpszToken, _T("RegServer"), 9)==0) flagRegServer = TRUE; // Register as Service if (_strnicmp(lpszToken, _T("Service"), 7)==0) flagService = TRUE; // Register as Service if (_strnicmp(lpszToken, _T("AutoStart"), 9)==0) flagAutoStart = SERVICE_AUTO_START; lpszToken = FindOneOf(lpszToken, szTokens); } if (flagUnregServer) return _Module.UnregisterServer(); if (flagRegServer) return _Module.RegisterServer(TRUE, FALSE); if (flagService) return _Module.RegisterServer(TRUE, TRUE); // Are we Service or Local Server CRegKey keyAppID; LONG lRes = keyAppID.Open(HKEY_CLASSES_ROOT, _T("AppID"), KEY_READ); if (lRes != ERROR_SUCCESS) return lRes; CRegKey key; lRes = key.Open(keyAppID, _T("{A3084FF8-63BF-40A1-8AE0-AD792B0078D9}"), KEY_READ); if (lRes != ERROR_SUCCESS) return lRes; TCHAR szValue[_MAX_PATH]; DWORD dwLen = _MAX_PATH; lRes = key.QueryValue(szValue, _T("LocalService"), &dwLen); _Module.m_bService = FALSE; if (lRes == ERROR_SUCCESS) _Module.m_bService = TRUE; WODXMPP::_XMPP_LibInit(_Module.GetModuleInstance()); WODVPN::_VPN_LibInit(_Module.GetModuleInstance()); if (LoadConfig()) { _Jabber = new CJabberLib(); _Ethernet = new CEthernet(); if (_Ethernet->InitAdapter()) { _Module.LogEvent("Connecting to the XMPP server." ); _Ethernet->GetMyIP(); _Module.Start(); } else _Module.LogEvent(_T("Wippien Service failed to open Network adapter.")); } else { char bf[8192]; sprintf(bf, "Could not read: %s.config", __argv[0]); _Module.LogEvent(bf); } WODVPN::_VPN_LibDeinit(); WODXMPP::_XMPP_LibDeInit(); // When we get here, the service has been stopped return _Module.m_status.dwWin32ExitCode; }
//============================================================================================ // MAIN //============================================================================================ extern "C" int WINAPI WinMain( HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPSTR lpCmdLine, // command line int nCmdShow ){ // show state TCHAR szTokens[] = "-/"; int iRes; HWND hDlgWnd; UINT uiTimerID; HRESULT hr; // Parse the command line for options LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens); while (lpszToken != NULL) { if (lstrcmpi(lpszToken, "UnregServer")==0) { iRes = g_UnregisterCOM(); if( iRes != 0 ) { MessageBox( NULL, "Error: Can't unregister server. g_UnregisterCOM() failed.", x_szTitle, MB_OK); } else { MessageBox( NULL, "Success: the server is unregistered.", x_szTitle, MB_OK); } return iRes; } if (lstrcmpi(lpszToken, "RegServer")==0) { iRes = g_RegisterCOM(); if( iRes != 0 ) { MessageBox( NULL, "Error: Can't register server. g_RegisterCOM() failed.", x_szTitle, MB_OK); } else { MessageBox( NULL, "Success: the server is registered.", x_szTitle, MB_OK); } return iRes; } lpszToken = FindOneOf(lpszToken, szTokens); } // while there are tokens //------- Windows staff starts here CP_printfCreate(x_szTitle); // create console window hDlgWnd=CreateDialog(hInstance, MAKEINTRESOURCE(IDD_MAIN_DIALOG), NULL, x_DialogProc); SetWindowText(hDlgWnd, x_szTitle); SendMessage(hDlgWnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON_APPL))); SendMessage(hDlgWnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadImage(hInstance, MAKEINTRESOURCE(IDI_ICON_APPL), IMAGE_ICON, 16, 16, 0)); // SetWindowText(GetDlgItem(hDlgWnd, IDC_LBL_VERSION ) , g_szVersion); ShowWindow(hDlgWnd, SW_SHOW); CP_printf(g_szVersion); CP_printf("\n\n"); uiTimerID = SetTimer( hDlgWnd, TIMER_ID, TIMER_PERIOD_MS, NULL ); if ( uiTimerID == 0){ CP_printf("Error: could not create timer!"); // don't exit we are still functional } // Init COM using multi-threaded model hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); //COINIT_APARTMENTTHREADED if( hr != S_OK) { MessageBox( NULL, "Error in CoInitializeEx()", x_szTitle, MB_OK); return 1; } iRes = g_Init_EyeTrack( ); if( iRes != 0 ) { MessageBox( NULL, "Error: g_Init_EyeTrack() failed.", x_szTitle, MB_OK); return 1; } // Message loop MSG msg; while (GetMessage(&msg, 0, 0, 0)) { // Process dialog messages in IsDialogMessage() pass others to translate/dispatch if(!IsDialogMessage(hDlgWnd,&msg)){ TranslateMessage(&msg); DispatchMessage(&msg); } } // end of message loop KillTimer( hDlgWnd, TIMER_ID); CoUninitialize(); return 0; }
extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/) { lpCmdLine = GetCommandLine(); //this line necessary for _ATL_MIN_CRT #if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED) HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED); #else HRESULT hRes = CoInitialize(NULL); #endif _ASSERTE(SUCCEEDED(hRes)); _Module.Init(ObjectMap, hInstance, &LIBID_VISSERVERLib); _Module.dwThreadID = GetCurrentThreadId(); TCHAR szTokens[] = _T("-/"); int nRet = 0; BOOL bRun = TRUE; LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens); while (lpszToken != NULL) { if (lstrcmpi(lpszToken, _T("UnregServer"))==0) { _Module.UpdateRegistryFromResource(IDR_VisServer, FALSE); nRet = _Module.UnregisterServer(TRUE); bRun = FALSE; break; } if (lstrcmpi(lpszToken, _T("RegServer"))==0) { _Module.UpdateRegistryFromResource(IDR_VisServer, TRUE); nRet = _Module.RegisterServer(TRUE); bRun = FALSE; break; } lpszToken = FindOneOf(lpszToken, szTokens); } if (bRun) { _Module.StartMonitor(); #if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED) hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED); _ASSERTE(SUCCEEDED(hRes)); hRes = CoResumeClassObjects(); #else hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE); #endif _ASSERTE(SUCCEEDED(hRes)); /////////////// /////////////// MAIN LOOP /////////////// // PNS:: The orginal message loop did nothing but handle messages: /* MSG msg; while (GetMessage(&msg, 0, 0, 0)) DispatchMessage(&msg); */ // Will Use WM_PAINT to coordinate painting MSG msg; while (GetMessage(&msg, 0, 0, 0)){ TranslateMessage( &msg ); DispatchMessage(&msg); } /* // We need to add the graphics loop here. // We will: // use PeekMessage (which does not block) as long as there is a message // then do a single window Update // then use GetMessage which blocks (idle) until the next message MSG msg; int done = 0; while(!done) // Loop That Runs While done=FALSE { GetMessage(&msg, 0, 0, 0); // Idle until first message if(msg.message==WM_QUIT) done=1; else { TranslateMessage( &msg ); DispatchMessage(&msg); } while(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // Handle rest of waiting messages { if(msg.message==WM_QUIT) done=1; else { TranslateMessage( &msg ); DispatchMessage(&msg); } } if(VisWindow!=NULL) VisWindow->update(); // Take this time to update window } */ /////////////// _Module.RevokeClassObjects(); Sleep(dwPause); //wait for any threads to finish // Just in Case Window Cleanup if(WindowFlag) KillGLWindow(); } // WrapUp _Module.Term(); CoUninitialize(); return nRet; }