2009年4月7日 星期二

Multi hread

.h
//////
HANDLE m_hLoadingThread;
DWORD m_dLoadingThreadID;
BOOL m_bLoadingThreadFlag;
static DWORD WINAPI LoadingThreadProc(LPVOID pThis);



//////////////////////////////////////////
.cpp
///////
///Start/////

m_hLoadingThread = ::CreateThread(NULL, 0, CUPnPAction::LoadingThreadProc, this, 0, &m_dLoadingThreadID);


///RUN/////
DWORD WINAPI CUPnPAction::LoadingThreadProc(LPVOID pThis)
{
char ErrMsg[MAX_PATH];
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);

OutputDebugString("LTP_Loading thread start\n");

CUPnPAction *pUPnPAction = (CUPnPAction*)pThis;


pUPnPAction->m_bLoadingThreadFlag = TRUE;

do
{

} while (pUPnPAction->m_bLoadingThreadFlag && ulMatches > ulStartIndex && SUCCEEDED(hr));

return S_OK;
}


///END/////

if (0 != m_hLoadingThread)
{
DWORD dwExitCode = 0;
GetExitCodeThread(m_hLoadingThread, &dwExitCode);
if (STILL_ACTIVE == dwExitCode)
{
m_bLoadingThreadFlag = FALSE;
WaitForSingleObject(m_hLoadingThread, INFINITE);
}
CloseHandle(m_hLoadingThread);
m_hLoadingThread = 0;
}

沒有留言: