本文整理汇总了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;
}
}
示例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;
//.........这里部分代码省略.........