亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? free.cpp

?? COM技術內幕配書源碼
?? CPP
字號:
#include <windows.h>
#include <stdlib.h>
#include <objbase.h>
#include <assert.h>

#define __OUTPROC_SERVER_ // To get the proper definition of trace
#include "util.h"
#undef __OUTPROC_SERVER_ 

#include "Free.h"

static inline void trace(char* msg)
	{ Util::Trace("Free thread", msg, S_OK) ;} 
static inline void trace(char* msg, HRESULT hr)
	{ Util::Trace("Free thread", msg, hr) ;}

///////////////////////////////////////////////////////////
//
// Constructor
//
CSimpleFree::CSimpleFree() 
{
	m_ThreadId = 0 ;	
	m_hThread = NULL ;
	m_hCreateComponentEvent = NULL ;
	m_hComponentReadyEvent = NULL ;
	m_hStopThreadEvent = NULL ;
	m_pIStream = NULL ;
	m_hr = S_OK ;
	m_piid = NULL ;
	m_pclsid = NULL ;
	m_WaitTime = 500 ;
} 

///////////////////////////////////////////////////////////
//
// Destructor
//
CSimpleFree::~CSimpleFree()
{
	// The thread must be stopped before we are deleted
	// because the WorkerFunction is in the derived class.
	assert(m_hThread == NULL) ;
}

///////////////////////////////////////////////////////////
//
// StartThread
//   - Create and start the thread.
//
BOOL CSimpleFree::StartThread(DWORD WaitTime) 
{
	if (IsThreadStarted())
	{
		return FALSE ;
	}

	// Create the thread.
	m_hThread
		= ::CreateThread(NULL,             // Default security
		                 0,                // Default stack size
		                 RealThreadProc, 
		                 (void*)this,
		                 CREATE_SUSPENDED, // Create the thread suspended.
		                 &m_ThreadId) ;    // Get the Thread ID.
	if (m_hThread == NULL)
	{
		trace("StartThread failed to create thread.", GetLastError()) ; 
		return FALSE ;
	}
	trace("StartThread successfully created thread.") ;

	// Create an event to signal the thread to create the component. 
	m_hCreateComponentEvent = ::CreateEvent(NULL, FALSE, FALSE, NULL) ;
	if (m_hCreateComponentEvent == NULL)
	{
		return FALSE ;
	}

	// Create an event for the thread to signal when it is finished. 
	m_hComponentReadyEvent = ::CreateEvent(NULL, FALSE, FALSE, NULL) ;
	if (m_hComponentReadyEvent == NULL)
	{
		return FALSE ;
	}

	// Create an event to tell the free thread to stop.
	m_hStopThreadEvent = ::CreateEvent(NULL, FALSE, FALSE, NULL) ;
	if (m_hStopThreadEvent == NULL)
	{
		return FALSE ;
	}

	trace("StartThread successfully created the events.") ;

	// Initialize the wait time.
	m_WaitTime = WaitTime ;

	// Thread was created suspended; start the thread.
	DWORD r = ::ResumeThread(m_hThread) ;
	assert(r != 0xffffffff) ;

	// Wait for the thread to start up before we continue.
	WaitWithMessageLoop(m_hComponentReadyEvent) ;

	// Make sure that thread is still running and that
	// there isn't an error.
	DWORD dwReturn = 0 ;
	BOOL b = ::GetExitCodeThread(m_hThread, &dwReturn) ;
	assert(b) ;
	if (dwReturn != STILL_ACTIVE)
	{
		trace("There was an error. Thread is not running.") ;
		m_hThread = NULL ;
		return FALSE ;
	}

	return TRUE ;
}

///////////////////////////////////////////////////////////
//
// StopThread
//
void CSimpleFree::StopThread()
{
	if (m_hThread != NULL)
	{
		// Stop the thread.
		// PostThreadMessage(m_ThreadId, WM_QUIT, 0,0) ;
		SetEvent(m_hStopThreadEvent) ;

		// Wait for thread to stop.
		WaitWithMessageLoop(m_hComponentReadyEvent) ;

		m_hThread = NULL ;
	}
}
	
///////////////////////////////////////////////////////////
//
// Current thread status
//
BOOL CSimpleFree::IsThreadStarted()
{
	return (m_hThread != NULL) ;
}

///////////////////////////////////////////////////////////
//
// Thread procedure
//
DWORD WINAPI CSimpleFree::RealThreadProc(void* pv) 
{
	CSimpleFree* pFree = reinterpret_cast<CSimpleFree*>(pv) ;
	return pFree->ClassThreadProc() ;
}

///////////////////////////////////////////////////////////
//
// Thread procedure
//
BOOL CSimpleFree::ClassThreadProc()
{
	BOOL bReturn = FALSE ;

	// Check for the existence of CoInitializeEx.
	typedef HRESULT (__stdcall *FPCOMINITIALIZE)(void*, DWORD) ;
	FPCOMINITIALIZE pCoInitializeEx = 
		reinterpret_cast<FPCOMINITIALIZE>(
			::GetProcAddress(::GetModuleHandle("ole32"),
			                 "CoInitializeEx")) ;
	if (pCoInitializeEx == NULL)
	{
		trace("This program requires the free-thread support in DCOM.") ;
		SetEvent(m_hComponentReadyEvent) ;
		return FALSE ;
	}

	// Initialize the COM Library.
	HRESULT hr = pCoInitializeEx(0, COINIT_MULTITHREADED) ; //@
	if (SUCCEEDED(hr))
	{
		// Signal that we are starting.
		SetEvent(m_hComponentReadyEvent) ;

		// Set up array of events.
		HANDLE hEventArray[2] = { m_hCreateComponentEvent,
		                          m_hStopThreadEvent } ;

		// Wait for the signal to create a component.
		BOOL bContinue = TRUE ;
		while (bContinue)
		{
			//@
			switch(::WaitForMultipleObjects(2,
			                                hEventArray,
			                                FALSE,
			                                m_WaitTime)) 
			{
			// Create the component.
			case WAIT_OBJECT_0:			
				CreateComponentOnThread() ;	
				break ;

			// Stop the thread.
			case (WAIT_OBJECT_0 +1):
				bContinue = FALSE ;
				bReturn = TRUE ;
				break ;

			// Do background processing.
			case WAIT_TIMEOUT:
				WorkerFunction() ; 
				break ;

			default:
				trace("Wait failed.", GetLastError()) ; 
			}
		}
		// Uninitialize the COM Library.
		CoUninitialize() ;
	}

	// Signal that we have finished.
	SetEvent(m_hComponentReadyEvent) ;
	return bReturn ;
}


///////////////////////////////////////////////////////////
//
// CreateComponent helper function
//
HRESULT CSimpleFree::CreateComponent(const CLSID& clsid,
                                     const IID& iid,
                                     IUnknown** ppI)
{
	// Initialize the shared data.
	m_pIStream = NULL ;
	m_piid = &iid ;
	m_pclsid = &clsid ;

	// Signal the thread to create a component.
	SetEvent(m_hCreateComponentEvent) ;

	// Wait for the component to be created.
	trace("Wait for the component to be created.") ;
	if (WaitWithMessageLoop(m_hComponentReadyEvent))
	{
		trace("The wait succeeded.") ;

		if (FAILED(m_hr))        // Did GetClassFactory fail?
		{
			return m_hr ;
		}

		if (m_pIStream == NULL)  // Did the marshaling fail?
		{
			return E_FAIL ;
		}

		trace("Unmarshal the interface pointer.") ;
		// Unmarshal the interface.
		HRESULT hr = ::CoGetInterfaceAndReleaseStream(m_pIStream,
		                                              iid,
		                                              (void**)ppI) ;
		m_pIStream = NULL ;
		if (FAILED(hr))
		{
			trace("CoGetInterfaceAndReleaseStream failed.", hr) ; 
			return E_FAIL ;
		}
		return S_OK ;
	}
	trace("What happened here?") ;
	return E_FAIL ;
}

///////////////////////////////////////////////////////////
//
// CreateComponentOnThread helper function
//   - This function packages the parameters for the
//     CoCreateComponentOnThread function.
//
void CSimpleFree::CreateComponentOnThread()
{
	IUnknown* pI = NULL;
	// Call the derived class to actually create the component.
	m_hr = CreateComponentOnThread(*m_pclsid, *m_piid, &pI) ;
	if (SUCCEEDED(m_hr))
	{
      trace("Successfully created component.") ;
		// Marshal the interface pointer to the server.
		HRESULT hr = ::CoMarshalInterThreadInterfaceInStream(*m_piid,
		                                                     pI,
		                                                     &m_pIStream) ;
		assert(SUCCEEDED(hr)) ;

		// Release the pI Pointer.
		pI->Release() ;
	}
	else
	{
		trace("CreateComponentOnThread failed.", m_hr);
	}

	trace("Signal the main thread that the component is ready.") ;
	SetEvent(m_hComponentReadyEvent) ;

}
///////////////////////////////////////////////////////////
//
// BOOL WaitWithMessageLoop(HANDLE hEvent)
//
BOOL CSimpleFree::WaitWithMessageLoop(HANDLE hEvent)
{
	while (TRUE)
	{
		// Wait for the event and for messages.
		DWORD dwReturn = ::MsgWaitForMultipleObjects(1,
		                                             &hEvent,
		                                             FALSE,
		                                             INFINITE,
		                                             QS_ALLINPUT) ;
		if (dwReturn == WAIT_OBJECT_0)
		{
			// Our event happened.
			return TRUE ;
		}
		else if (dwReturn == WAIT_OBJECT_0 + 1)
		{
			// Handle message to keep client alive.
			MSG msg ;
			while(::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
			{
				::DispatchMessage(&msg) ;
			}
		}
		else
		{
			trace("WaitWithMessageLoop failed.", GetLastError()) ; 
			return FALSE ;
		}
	}
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲大片在线观看| 欧美成人三级电影在线| 欧美亚洲日本国产| 6080午夜不卡| 久久久九九九九| 一区二区三区在线不卡| 免费看日韩精品| 成人国产精品免费观看| 中文字幕亚洲一区二区va在线| 自拍偷拍亚洲欧美日韩| 青青草一区二区三区| 成人av手机在线观看| 欧美丰满一区二区免费视频| 国产三级精品视频| 日日骚欧美日韩| 成人动漫在线一区| 日韩一级片网址| 伊人色综合久久天天| 毛片av一区二区三区| 99re66热这里只有精品3直播 | 亚洲精品一区二区三区影院| 国产精品久久久99| 免费在线观看精品| 91香蕉视频在线| 久久人人97超碰com| 亚洲午夜在线视频| 成人动漫视频在线| 欧美不卡视频一区| 亚洲综合精品久久| 成人永久看片免费视频天堂| 8x福利精品第一导航| 国产精品美日韩| 奇米色一区二区三区四区| 91麻豆精品秘密| 国产欧美中文在线| 美女在线视频一区| 欧美日韩卡一卡二| 亚洲欧美日韩国产另类专区| 国产精品综合二区| 欧美一区二区观看视频| 一级特黄大欧美久久久| www.成人在线| 国产校园另类小说区| 蜜桃视频一区二区三区| 欧美性色综合网| 亚洲视频 欧洲视频| 国产成人免费xxxxxxxx| 日韩小视频在线观看专区| 亚洲自拍另类综合| 色综合色综合色综合| 国产精品久久久久久久久搜平片| 久久成人免费电影| 欧美一区二区三区免费在线看| 亚洲与欧洲av电影| 日本乱人伦一区| 亚洲天堂网中文字| 一本一道波多野结衣一区二区| 亚洲国产高清在线| 高清国产午夜精品久久久久久| 久久综合久久鬼色中文字| 久久精品国产澳门| 欧美变态口味重另类| 久久aⅴ国产欧美74aaa| 日韩网站在线看片你懂的| 男人操女人的视频在线观看欧美| 欧美性受极品xxxx喷水| 亚洲一区二区三区美女| 欧洲一区在线电影| 亚洲sss视频在线视频| 欧美三区免费完整视频在线观看| 夜夜嗨av一区二区三区| 欧美在线啊v一区| 亚洲国产欧美在线| 欧美日韩不卡一区二区| 日韩精品一二区| 日韩一级完整毛片| 激情文学综合丁香| 国产午夜精品美女毛片视频| 国产成人在线看| 中文字幕av资源一区| av高清久久久| 亚洲综合色成人| 欧美精品高清视频| 久久成人麻豆午夜电影| 国产婷婷色一区二区三区四区| 国产成人8x视频一区二区| 日韩一区在线看| 在线观看91精品国产入口| 日本成人超碰在线观看| 精品国产青草久久久久福利| 国产不卡视频在线观看| 亚洲欧美一区二区久久 | 首页欧美精品中文字幕| 日韩欧美综合在线| 国产精品一区在线观看乱码| 国产精品国产精品国产专区不片| 91麻豆swag| 日韩 欧美一区二区三区| 久久精品一区蜜桃臀影院| 91在线视频播放| 午夜私人影院久久久久| 精品粉嫩超白一线天av| 成人97人人超碰人人99| 亚洲一区二区中文在线| 日韩丝袜美女视频| av成人动漫在线观看| 午夜影院在线观看欧美| 久久亚洲欧美国产精品乐播| 91麻豆免费看| 乱一区二区av| 亚洲欧洲国产专区| 日韩亚洲欧美成人一区| 成人的网站免费观看| 五月天中文字幕一区二区| 国产亚洲短视频| 欧美美女网站色| 高清不卡一二三区| 首页国产欧美久久| 国产精品护士白丝一区av| 制服视频三区第一页精品| 国产成a人亚洲精| 日韩制服丝袜av| 国产精品三级视频| 欧美妇女性影城| 成人精品高清在线| 奇米777欧美一区二区| 国产精品国产成人国产三级| 日韩欧美一区在线| 在线视频你懂得一区| 国产一区二区三区免费在线观看| 亚洲一区二区三区爽爽爽爽爽| 久久伊人蜜桃av一区二区| 欧美在线|欧美| av在线播放不卡| 国产一区二区91| 日韩二区在线观看| 亚洲一区中文日韩| 中文字幕不卡一区| 久久亚洲精品国产精品紫薇| 欧美三级视频在线观看| 99久久久久久| 国产91高潮流白浆在线麻豆 | 日韩欧美久久久| 色先锋aa成人| 国产.欧美.日韩| 久久国产剧场电影| 一区二区三区高清不卡| 国产精品素人视频| 欧美mv和日韩mv的网站| 7777精品伊人久久久大香线蕉经典版下载 | 国产aⅴ综合色| 毛片一区二区三区| 日韩专区在线视频| 亚洲伊人色欲综合网| 综合久久一区二区三区| 国产人久久人人人人爽| 欧美精品一区二区三区很污很色的| 欧美三级电影在线观看| 色综合天天综合网国产成人综合天 | 在线观看亚洲精品| 不卡av在线网| 成人爽a毛片一区二区免费| 国产在线看一区| 久久国产精品免费| 免费观看一级特黄欧美大片| 亚洲图片欧美色图| 亚洲在线观看免费| 亚洲国产精品一区二区久久恐怖片| 中文字幕一区二区三区不卡 | 99久久精品国产网站| 国产成人a级片| 国产精品一品二品| 国产一区不卡在线| 国产在线视视频有精品| 国产原创一区二区| 国产在线一区二区| 国产精品白丝jk黑袜喷水| 黑人巨大精品欧美黑白配亚洲| 精品一区二区免费看| 九色综合狠狠综合久久| 老司机免费视频一区二区三区| 日本免费新一区视频| 老司机精品视频在线| 精品一二三四区| 国产美女精品一区二区三区| 国产一区二区三区免费在线观看| 国产精品亚洲人在线观看| 国产成人免费9x9x人网站视频| 国产精品主播直播| 成人国产电影网| 91久久线看在观草草青青| 欧洲另类一二三四区| 欧美精品久久一区| 日韩欧美亚洲一区二区| 欧美精品一区二区三| 国产日韩av一区二区| 国产精品电影一区二区三区| 亚洲欧美激情在线| 亚洲1区2区3区视频| 美女被吸乳得到大胸91|