当前位置: 首页>>代码示例>>C++>>正文


C++ SharedMemory::Create方法代码示例

本文整理汇总了C++中SharedMemory::Create方法的典型用法代码示例。如果您正苦于以下问题:C++ SharedMemory::Create方法的具体用法?C++ SharedMemory::Create怎么用?C++ SharedMemory::Create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SharedMemory的用法示例。


在下文中一共展示了SharedMemory::Create方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Run


//.........这里部分代码省略.........
					{
						strInitialCmd = startupCmds[0];
					}

					DWORD dwBasePriority = ULONG_MAX;

					if (basePriorities.size() > 0)
					{
						dwBasePriority = basePriorities[0];
					}

					if (dwBasePriority == ULONG_MAX)
						dwBasePriority = tabData->get()->dwBasePriority;

					try
					{
						ConsoleHandler ConsoleHandler;
						ConsoleHandler.StartShellProcessAsAdministrator
						(
							strSyncName,
							strShell,
							strInitialDir,
							strInitialCmd,
							dwBasePriority,
							tabData->get()->environmentVariables
						);
					}
					catch (const ConsoleException& ex)
					{
						MessageBox(NULL, ex.GetMessage().c_str(), Helpers::LoadString(IDS_CAPTION_ERROR).c_str(), MB_ICONERROR|MB_OK);
						return 1;
					}

					break;
				}
			}

      return 0;
    }

    if (bReuse && HandleReuse(lpstrCmdLine))
      return 0;

    // create main window
    NoTaskbarParent noTaskbarParent;
    MainFrame wndMain(lpstrCmdLine);

    if (!g_settingsHandler->GetAppearanceSettings().stylesSettings.bTaskbarButton)
    {
      noTaskbarParent.Create(NULL);
    }

    if(wndMain.CreateEx(noTaskbarParent.m_hWnd) == NULL)
    {
      ATLTRACE(_T("Main window creation failed!\n"));
      return 1;
    }

#ifdef _USE_AERO
    // restore the drop files message in elevated console
    ::ChangeWindowMessageFilter(WM_DROPFILES, MSGFLT_ADD);
    ::ChangeWindowMessageFilter(WM_COPYDATA, MSGFLT_ADD);
    ::ChangeWindowMessageFilter(0x0049, MSGFLT_ADD);
#endif

    wndMain.ShowWindow(nCmdShow);

    SharedMemory<HWND> sharedInstance;
    if (bReuse)
    {
      sharedInstance.Create(L"ConsoleZ", 1, syncObjNone, _T(""));
      sharedInstance = wndMain.m_hWnd;
    }

    WallPaperThread wallPaperThread(wndMain);

    if (Helpers::CheckOSVersion(6, 1))
    {
      // Win7 or more, we use the wallpaper slideshow monitoring
      wallPaperThread.Start();
    }

		TranslateMessageEx = (_t_TranslateMessageEx)::GetProcAddress(::GetModuleHandle(L"user32.dll"), "TranslateMessageEx");
		if( !TranslateMessageEx )
			Win32Exception::ThrowFromLastError("TranslateMessageEx");

    int nRet = theLoop.Run();

    if (noTaskbarParent.m_hWnd != NULL) noTaskbarParent.DestroyWindow();

    _Module.RemoveMessageLoop();

    return nRet;
  }
  catch(std::exception& e)
  {
    ::MessageBoxA(0, e.what(), "exception", MB_OK);
    return 1;
  }
}
开发者ID:gaeeronimo,项目名称:console,代码行数:101,代码来源:Console.cpp

示例2: ConsoleException

void ConsoleHandler::StartShellProcess
(
	const wstring& strTitle,
	const wstring& strShell,
	const wstring& strInitialDir,
	const UserCredentials& userCredentials,
	const wstring& strInitialCmd,
	const wstring& strConsoleTitle,
	DWORD dwStartupRows,
	DWORD dwStartupColumns
)
{
	PROCESS_INFORMATION pi = {0, 0, 0, 0};

	bool runAsAdministrator = userCredentials.runAsAdministrator;

	if (runAsAdministrator)
	{
		try
		{
			if (Helpers::CheckOSVersion(6, 0))
			{
				if( Helpers::IsElevated() )
				{
					// process already running in elevated mode or UAC disabled
					runAsAdministrator = false;
				}
			}
			else
			{
				// UAC doesn't exist in current OS
				runAsAdministrator = false;
			}
		}
		catch(std::exception& err)
		{
			throw ConsoleException(boost::str(boost::wformat(Helpers::LoadString(IDS_ERR_CANT_GET_ELEVATION_TYPE)) % err.what()));
		}
	}

	SharedMemory<DWORD> pid;

	if (runAsAdministrator)
	{
		std::wstring strSyncName = (SharedMemNames::formatAdmin % ::GetCurrentProcessId()).str();

		pid.Create(strSyncName, 1, syncObjBoth, L"");

		RunAsAdministrator(
			strSyncName,
			strTitle,
			strInitialDir,
			strInitialCmd,
			pi
		);

		// wait for PID of shell launched in admin ConsoleZ
		if (::WaitForSingleObject(pid.GetReqEvent(), 10000) == WAIT_TIMEOUT)
			throw ConsoleException(boost::str(boost::wformat(Helpers::LoadString(IDS_ERR_DLL_INJECTION_FAILED)) % L"timeout"));

		pi.dwProcessId = *pid.Get();
		pi.hProcess = ::OpenProcess(SYNCHRONIZE, FALSE, pi.dwProcessId);
		if( pi.hProcess == NULL )
		{
			Win32Exception err(::GetLastError());
			throw ConsoleException(boost::str(boost::wformat(Helpers::LoadString(IDS_ERR_DLL_INJECTION_FAILED)) % err.what()));
		}
	}
	else
	{
		CreateShellProcess(
			strShell,
			strInitialDir,
			userCredentials,
			strInitialCmd,
			strConsoleTitle,
			pi
		);
	}

	// create shared memory objects
	try
	{
		CreateSharedObjects(pi.dwProcessId, userCredentials.netOnly? L"" : userCredentials.strAccountName);
		CreateWatchdog();
	}
	catch(Win32Exception& err)
	{
		throw ConsoleException(boost::str(boost::wformat(Helpers::LoadString(IDS_ERR_CREATE_SHARED_OBJECTS_FAILED)) % err.what()));
	}

	// write startup params
	m_consoleParams->dwParentProcessId     = ::GetCurrentProcessId();
	m_consoleParams->dwNotificationTimeout = g_settingsHandler->GetConsoleSettings().dwChangeRefreshInterval;
	m_consoleParams->dwRefreshInterval     = g_settingsHandler->GetConsoleSettings().dwRefreshInterval;
	m_consoleParams->dwRows                = dwStartupRows;
	m_consoleParams->dwColumns             = dwStartupColumns;
	m_consoleParams->dwBufferRows          = g_settingsHandler->GetConsoleSettings().dwBufferRows;
	m_consoleParams->dwBufferColumns       = g_settingsHandler->GetConsoleSettings().dwBufferColumns;

//.........这里部分代码省略.........
开发者ID:danieldc,项目名称:console,代码行数:101,代码来源:ConsoleHandler.cpp


注:本文中的SharedMemory::Create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。