Bool CSampleApp::InitInstance() { // Initialize OLE libraries if (!AfxOleInit()) { AfxMessageBox(IDP_OLE_INIT_FAILED); return FALSE; } // CT: нрйкчвемхе дхюкнцю х яннаыемхъ на хявепоюмхх нфхдюмхъ нрберю яепбепю COleMessageFilter* pFilter = AfxOleGetMessageFilter(); ASSERT_VALID(pFilter); pFilter->SetMessagePendingDelay( -1 ); pFilter->EnableNotRespondingDialog(FALSE); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif // Parse the command line to see if launched as OLE server if (RunEmbedded() || RunAutomated()) { // Register all OLE server (factories) as running. This enables the // OLE libraries to create objects from other applications. COleTemplateServer::RegisterAll(); } else { // When a server application is launched stand-alone, it is a good idea // to update the system registry in case it has been damaged. COleObjectFactory::UpdateRegistryAll(); } CSampleDlg dlg; m_pMainWnd = &dlg; int nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE; }
BOOL CMfcCliApp::InitInstance() { // Initialize OLE libraries if (!AfxOleInit()) { AfxMessageBox(IDP_OLE_INIT_FAILED); return FALSE; } AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif // Parse the command line to see if launched as OLE server if (RunEmbedded() || RunAutomated()) { // Register all OLE server (factories) as running. This enables the // OLE libraries to create objects from other applications. COleTemplateServer::RegisterAll(); // Application was run with /Embedding or /Automation. Don't show the // main window in this case. return TRUE; } // When a server application is launched stand-alone, it is a good idea // to update the system registry in case it has been damaged. COleObjectFactory::UpdateRegistryAll(); CMfcCliDlg dlg; m_pMainWnd = &dlg; int nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE; }
BOOL CCalcApp::InitInstance() { // Initialize OLE 2.0 libraries if (!AfxOleInit()) { AfxMessageBox(IDP_OLE_INIT_FAILED); return FALSE; } // Parse the command line to see if launched as OLE server if (RunEmbedded() || RunAutomated()) { // Register all OLE server (factories) as running. This enables the // OLE 2.0 libraries to create objects from other applications. COleTemplateServer::RegisterAll(); // Do not continue with rest of initialization. Wait for // client to create a CCalcDlg object instead. return TRUE; } // When a server application is launched stand-alone, it is a good idea // to update the system registry in case it has been damaged. COleObjectFactory::UpdateRegistryAll(); // create a modeless dialog as the main window of the application //This disables the warning that the dialog could leak - //it will not leak since the Set Visible registers the dialog as //the main frame and any windows message that closes that dialog //causes the parent class to call the destructor #pragma warning( push ) #pragma warning(disable:6014) CCalcDlg* pDlg = new CCalcDlg; #pragma warning( pop ) pDlg->SetVisible(TRUE); if (!pDlg->GetVisible()) { // if GetVisible fails after SetVisibile, we never registered // the pDlg with the parent class, and it will not be deleted AfxMessageBox(IDP_UNABLE_TO_SHOW_CALC); delete pDlg; return FALSE; } pDlg->RegisterActive(); // We are using a modeless dialog so we can translate accelerator keys // against the dialog. In order to run the main message pump, // InitInstance must return TRUE even though this application is // a dialog-based application. return TRUE; }
BOOL CEx24aApp::InitInstance() { AfxOleInit(); if (RunEmbedded() || RunAutomated()) { // component started by COM COleTemplateServer::RegisterAll(); return TRUE; } // Component is being run directly by the user COleObjectFactory::UpdateRegistryAll(); AfxMessageBox("Bank component is registered"); // add this line return FALSE; }
BOOL CMDriveApp::InitInstance() { _Module.Init(NULL, NULL); // Initialize OLE libraries if (!AfxOleInit()) { AfxMessageBox(IDP_OLE_INIT_FAILED); return FALSE; } // Parse the command line to see if launched as OLE server if (RunEmbedded() || RunAutomated()) { // Register all OLE server (factories) as running. This enables the // OLE libraries to create objects from other applications. COleTemplateServer::RegisterAll(); // Application was run with /Embedding or /Automation. Don't show the // main window in this case. return TRUE; } // When a server application is launched stand-alone, it is a good idea // to update the system registry in case it has been damaged. COleObjectFactory::UpdateRegistryAll(); CMDriveDlg dlg; m_pMainWnd = &dlg; INT_PTR nResponse = dlg.DoModal(); if (nResponse == IDOK) { // dlg.OnStopAll(); } else if (nResponse == IDCANCEL) { // dlg.OnStopAll(); } // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE; }
BOOL CInProcApp::InitInstance() { #ifndef _USRDLL if (!RunEmbedded() && !RunAutomated()) { COleObjectFactory::UpdateRegistryAll(); AfxMessageBox(IDP_CANT_RUN_STANDALONE); return FALSE; } // Initialize OLE libraries if (!AfxOleInit()) { AfxMessageBox(IDP_OLE_INIT_FAILED); return FALSE; } #endif // Register all OLE server (factories) as running. This enables the // OLE libraries to create objects from other applications. COleObjectFactory::RegisterAll(); return TRUE; }
BOOL COleClientApp::InitInstance() { #if defined(_DEBUG) && !defined(_AFX_NO_DEBUG_CRT) // turn on extra memory tracking afxMemDF |= checkAlwaysMemDF; #endif // Initialize OLE 2.0 libraries if (!AfxOleInit()) { AfxMessageBox(IDP_AFXOLEINIT_FAILED); return FALSE; } // Standard initialization LoadStdProfileSettings(); // Load standard INI file options (including MRU) // Register document templates CMultiDocTemplate* pDocTemplate = new CMultiDocTemplate(IDR_OCLIENTTYPE, RUNTIME_CLASS(CMainDoc), RUNTIME_CLASS(CSplitFrame), RUNTIME_CLASS(CMainView)); pDocTemplate->SetContainerInfo(IDR_OCLIENTTYPE_CNTR_IP); AddDocTemplate(pDocTemplate); // create main MDI Frame window CMainFrame* pMainFrame = new CMainFrame; if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) { delete pMainFrame; return FALSE; } m_pMainWnd = pMainFrame; // enable file manager drag/drop and DDE Execute open m_pMainWnd->DragAcceptFiles(); EnableShellOpen(); RegisterShellFileTypes(TRUE); // connect the COleTemplate server to the document template m_server.ConnectTemplate(clsid, pDocTemplate, FALSE); COleTemplateServer::RegisterAll(); // Note: MDI applications register all class objects regardless of // the /Embedding on the command line. // Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); if (RunEmbedded()) { // application was run with /Embedding flag. Instead of showing // the window, the application waits to receive OLE requests. return TRUE; } // always update system registry when run non-embedded m_server.UpdateRegistry(OAT_CONTAINER); // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE; pMainFrame->ShowWindow(m_nCmdShow); pMainFrame->UpdateWindow(); return TRUE; }
extern "C" HRESULT EngineRun( __in HINSTANCE hInstance, __in_z_opt LPCWSTR wzCommandLine, __in int nCmdShow, __out DWORD* pdwExitCode ) { HRESULT hr = S_OK; BOOL fComInitialized = FALSE; BOOL fLogInitialized = FALSE; BOOL fRegInitialized = FALSE; BOOL fWiuInitialized = FALSE; BOOL fXmlInitialized = FALSE; OSVERSIONINFOEXW ovix = { }; LPWSTR sczExePath = NULL; BOOL fRunNormal = FALSE; BOOL fRestart = FALSE; BURN_ENGINE_STATE engineState = { }; hr = InitializeEngineState(&engineState); ExitOnFailure(hr, "Failed to initialize engine state."); engineState.command.nCmdShow = nCmdShow; // Ensure that log contains approriate level of information #ifdef _DEBUG LogSetLevel(REPORT_DEBUG, FALSE); #else LogSetLevel(REPORT_VERBOSE, FALSE); // FALSE means don't write an additional text line to the log saying the level changed #endif // initialize platform layer PlatformInitialize(); // initialize COM hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED); ExitOnFailure(hr, "Failed to initialize COM."); fComInitialized = TRUE; // Initialize dutil. LogInitialize(::GetModuleHandleW(NULL)); fLogInitialized = TRUE; hr = RegInitialize(); ExitOnFailure(hr, "Failed to initialize Regutil."); fRegInitialized = TRUE; hr = WiuInitialize(); ExitOnFailure(hr, "Failed to initialize Wiutil."); fWiuInitialized = TRUE; hr = XmlInitialize(); ExitOnFailure(hr, "Failed to initialize XML util."); fXmlInitialized = TRUE; ovix.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW); if (!::GetVersionExW((LPOSVERSIONINFOW)&ovix)) { ExitWithLastError(hr, "Failed to get OS info."); } PathForCurrentProcess(&sczExePath, NULL); // Ignore failure. LogId(REPORT_STANDARD, MSG_BURN_INFO, szVerMajorMinorBuild, ovix.dwMajorVersion, ovix.dwMinorVersion, ovix.dwBuildNumber, ovix.wServicePackMajor, sczExePath, wzCommandLine ? wzCommandLine : L""); ReleaseNullStr(sczExePath); // initialize core hr = CoreInitialize(wzCommandLine, &engineState); ExitOnFailure(hr, "Failed to initialize core."); // select run mode switch (engineState.mode) { case BURN_MODE_NORMAL: fRunNormal = TRUE; hr = RunNormal(hInstance, &engineState); ExitOnFailure(hr, "Failed to run per-user mode."); break; case BURN_MODE_ELEVATED: hr = RunElevated(hInstance, wzCommandLine, &engineState); ExitOnFailure(hr, "Failed to run per-machine mode."); break; case BURN_MODE_EMBEDDED: fRunNormal = TRUE; hr = RunEmbedded(hInstance, &engineState); ExitOnFailure(hr, "Failed to run embedded mode."); break; case BURN_MODE_RUNONCE: hr = RunRunOnce(wzCommandLine, nCmdShow); ExitOnFailure(hr, "Failed to run RunOnce mode."); break; default: hr = E_UNEXPECTED; ExitOnFailure(hr, "Invalid run mode."); } // set exit code and remember if we are supposed to restart. *pdwExitCode = engineState.userExperience.dwExitCode; fRestart = engineState.fRestart; LExit: ReleaseStr(sczExePath); // If anything went wrong but the log was never open, try to open a "failure" log // and that will dump anything captured in the log memory buffer to the log. if (FAILED(hr) && BURN_LOGGING_STATE_CLOSED == engineState.log.state) { LogOpen(NULL, L"Setup", L"_Failed", L"txt", FALSE, FALSE, NULL); } UserExperienceRemove(&engineState.userExperience); CacheRemoveWorkingFolder(engineState.registration.sczId); // If this is a related bundle (but not an update) suppress restart and return the standard restart error code. if (fRestart && BOOTSTRAPPER_RELATION_NONE != engineState.command.relationType && BOOTSTRAPPER_RELATION_UPDATE != engineState.command.relationType) { LogId(REPORT_STANDARD, MSG_RESTART_ABORTED, LoggingRelationTypeToString(engineState.command.relationType)); fRestart = FALSE; hr = HRESULT_FROM_WIN32(ERROR_SUCCESS_REBOOT_REQUIRED); } UninitializeEngineState(&engineState); if (fXmlInitialized) { XmlUninitialize(); } if (fWiuInitialized) { WiuUninitialize(); } if (fRegInitialized) { RegUninitialize(); } if (fComInitialized) { ::CoUninitialize(); } if (fRunNormal) { LogId(REPORT_STANDARD, MSG_EXITING, FAILED(hr) ? (int)hr : *pdwExitCode, LoggingBoolToString(fRestart)); if (fRestart) { LogId(REPORT_STANDARD, MSG_RESTARTING); } } if (fLogInitialized) { LogClose(FALSE); } if (fRestart) { Restart(); } if (fLogInitialized) { LogUninitialize(FALSE); } return hr; }
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. }
BOOL CCalcApp::InitInstance() { // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. #if _MFC_VER < 0x0700 Enable3dControls(); #endif // Initialize OLE 2.0 libraries if (!AfxOleInit()) { AfxMessageBox(IDP_OLE_INIT_FAILED); return FALSE; } // Parse command line for automation or reg/unreg switches. CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); if (RunEmbedded() || RunAutomated()) { // Register all OLE server (factories) as running. This enables the // OLE 2.0 libraries to create objects from other applications. COleTemplateServer::RegisterAll(); // Do not continue with rest of initialization. Wait for // client to create a CCalcDlg object instead. return TRUE; } // App was launched with /Unregserver or /Unregister switch. Remove // entries from the registry. else if (cmdInfo.m_nShellCommand == CCommandLineInfo::AppUnregister) { COleObjectFactory::UpdateRegistryAll(FALSE); AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor); return FALSE; } // App was launched standalone or with other switches (e.g. /Register // or /Regserver). Update registry entries, including typelibrary. else { COleObjectFactory::UpdateRegistryAll(); AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid); if (cmdInfo.m_nShellCommand == CCommandLineInfo::AppRegister) return FALSE; } // create a modeless dialog as the main window of the application //suppress warning because an object of CDialog is self-destructing #pragma warning (suppress: 6014) CCalcDlg* pDlg = new CCalcDlg; pDlg->SetVisible(TRUE); if (!pDlg->GetVisible()) { AfxMessageBox(IDP_UNABLE_TO_SHOW_CALC); return FALSE; } pDlg->RegisterActive(); // We are using a modeless dialog so we can translate accelerator keys // against the dialog. In order to run the main message pump, // InitInstance must return TRUE even though this application is // a dialog-based application. return TRUE; }