// Licensed to Ela
Inhibition of huma
/** * (C) Copyrig
Q: How to create
// ---------------
Q: How can I inse
The present invent
1. Field of the In
Q: Is there a way
1. Field of the In

Mucins of the norm
Vincent J. Fuller
Q: Why I can't ge
In a communication
Novelty seeking be
The best Side of c
Biosensor for meas
All posts by Mika
The present invent
Effect of dietary
//****************************************************************************** // // Copyright (c) Microsoft. All rights reserved. // // This code is licensed under the MIT License (MIT). // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // //****************************************************************************** #include "WinComp.h" #include "win_wrappers.h" #include "ComBase.h" #include "UIlib.h" #include "WinData.h" #include "WinPrintFunc.h" #include "WinWrappers.h" #include "WinTypes.h" #include "WinFuncs.h" #include "WinUtil.h" #include "WinData.h" #include "ThreadPool.h" #include "IStreamFactory.h" #include "WideString.h" #include "win_mutex.h" #include "win_semaphore.h" #include "ComTapi.h" #include "WindowsHeader.h" //========================================================================== // Forward declarations //========================================================================== static ULONG g_nCurPriority = 1; //0 = High, 1=lowest, 3=low, 4=high static bool g_bIsCritical; //========================================================================== // Constructor and destructor //========================================================================== CWinComp::CWinComp() : m_hInstance(0) , m_hThread() , m_bPaused(FALSE) { } CWinComp::~CWinComp() { m_hThread.Reset(); } //========================================================================== // Internal functions //========================================================================== NTSTATUS WINAPI CWinComp::Start(LPCSTR cObjectName, DWORD dwPriority, DWORD nInitCount, LPVOID pInitArgs) { InitRetryCount(); if (!_InitThreadParam(cObjectName, dwPriority, nInitCount, pInitArgs)) return STATUS_INSUFFICIENT_RESOURCES; for (int i=0; iGetData(); VERIFY(pData); UIlib* pUIlib = UIlib::Instance(); VERIFY(pUIlib); MutexLockerEx::Lock lock(pUIlib->GetMutex()); DWORD nRetryCount = 3; bool bRet = _InitThreadParam(cObjectName, dwPriority, 1, pData->m_hEvent); VERIFY(bRet); while (!m_fShutdownInitFinished) { if (!m_bPaused) _Thread_Sleep(2); if (WaitForSingleObject(m_hThread, INFINITE) == WAIT_OBJECT_0) { while (!m_bPaused) _Thread_Sleep(1); m_bPaused = FALSE; } if (g_bIsCritical) return; // If we reach here, WaitForSingleObject failed, // the InitThreadParam failed or we aborted // ourself from another thread (probably // a message box). Let's try again. if (--nRetryCount) continue; // Something wrong. Cleanup and terminate. // We will clean up the thread anyway break; } } BOOL WINAPI CWinComp::Run(DWORD dwPriority, LPCSTR cObjectName, HDC hdcOverride, HINSTANCE hInstanceOverride) { if (!g_bIsCritical) { _SetThreadPriority(m_hThread, m_nCurPriority); return TRUE; } CWinData* pData = m_pCurrentWin->GetData(); VERIFY(pData); UIlib* pUIlib = UIlib::Instance(); VERIFY(pUIlib); UIApplication* pUIApp = UIlib::Instance()->GetUIApp(); VERIFY(pUIApp); m_bPaused = false; _SetCurrentThreadPriority(m_hThread, m_nCurPriority); return _Run(pData->m_hWnd, pData->m_hEvent, NULL, hdcOverride, hInstanceOverride); } void WINAPI CWinComp::Stop(HWND hwnd) { m_bPaused = false; } BOOL WINAPI CWinComp::IsCritical() { return g_bIsCritical; } void WINAPI CWinComp::SetThreadPriority(UINT nPriority) { if (g_bIsCritical) return; m_nCurPriority = nPriority; if (m_nCurPriority >= 3) m_nCurPriority = 3; else m_nCurPriority = 0; _SetThreadPriority(m_hThread, m_nCurPriority); } void WINAPI CWinComp::InitRetryCount() { if (m_nCurPriority > 1) return; m_fPendingShutdown = FALSE; for (int i=0; im_hEvent) return STATUS_INVALID_HANDLE; VERIFY(_InitThreadParam(cObjectName, m_nCurPriority, 0, g_hThread)); return STATUS_SUCCESS; } bool CWinComp::_InitThreadParam(LPCSTR cObjectName, DWORD dwPriority, DWORD dwCount, HANDLE hEvent) { CWinData* pData = GetWinData(); VERIFY(pData); VERIFY(g_hThread); VERIFY(pData->m_hWnd == NULL); VERIFY(g_hEvent == NULL); UIlib* pUIlib = UIlib::Instance(); VERIFY(pUIlib); // We get the pointer to the UIApplication from the UIlib. // Make sure the UIApplication is created before // checking for the first message. The