Exemple #1
0
void tLuaCOM::releaseConnections() {
	if(conn_point==NULL)
		return;
	
	conn_point->Release();
	IConnectionPointContainer *pcpc;

    HRESULT hr = pdisp->QueryInterface(IID_IConnectionPointContainer, (void **) &pcpc);

    if(FAILED(hr))
    {
	    return;
    }

	IEnumConnectionPoints *pecp;

	hr = pcpc->EnumConnectionPoints(&pecp);
	pcpc->Release();

    if(FAILED(hr))
    {
	    return;
    }

	pecp->Reset();

	IConnectionPoint *pcp;
	ULONG fetched = 0;

	hr = pecp->Next(1, &pcp, &fetched);
	while(SUCCEEDED(hr) && fetched) {
		IEnumConnections *pec;
		hr = pcp->EnumConnections(&pec);
		if(SUCCEEDED(hr)) {
			pec->Reset();
			CONNECTDATA conn;
			ULONG conn_fetched = 0;
			hr = pec->Next(1, &conn, &conn_fetched);
			while(SUCCEEDED(hr) && conn_fetched) {
				pcp->Unadvise(conn.dwCookie);
				hr = pec->Next(1, &conn, &conn_fetched);
			}
			pec->Release();
		}
        pcp->Release();
  	    pecp->Next(1, &pcp, &fetched);
	}
	
	pecp->Release();
}
void CIncrementSystemBFDlg::ConnectButton1(IHTMLElement *pButtonElem)
{
	HRESULT hr = 0; 
	IConnectionPointContainer* pCPC = NULL; 
	IConnectionPoint* pCP = NULL; 
	IUnknown* pUnk = NULL; 
	DWORD dwCookie; 
	// Check that this is a connectable object. 
	hr = pButtonElem->QueryInterface(IID_IConnectionPointContainer, (void**)&pCPC); 
	if (hr == S_OK) 
	{ 
		//AfxMessageBox("ConnectionPointContainer"); 
		// Find the connection point. 
		IEnumConnectionPoints *ppEnum=NULL;
		hr=pCPC->EnumConnectionPoints(&ppEnum);

	//	ppEnum->Next()
	//	if( hr == S_OK)
		{
			//ppEnum->Next()
		}
		hr = pCPC->FindConnectionPoint(DIID_HTMLinputTextElementEvents2/*DIID_HTMLButtonElementEvents2*/, &pCP); 
	//	hr = pCPC->FindConnectionPoint(__uuidof(IID_HTMLElementEvents2)/*DIID_HTMLButtonElementEvents2*/, &pCP); 
		if   ( SUCCEEDED(hr)) 
		{                         
			//AfxMessageBox( "Find   connection   point   "); 
			//   Advise   the   connection   point. 
			//   pUnk   is   the   IUnknown   interface   pointer   for   your   event   sink 
			
			//CDHTMLEventSink*   pSink   =   new CDHTMLEventSink;// CMyEventSink;// ;   
			//pSink->SetParent(this); 
			//IUnknown*   pUnk   = pSink->GetInterface(&IID_IUnknown);
			
			CMyEventSink* pSink = new CMyEventSink;
			hr   =   pCP->Advise(pSink,   &dwCookie); 
			pCP->Release(); 
		} 
		pCPC->Release(); 
	} 

	
}
void EnumConnectionPoint(IDispatch *pDisp, LPCSTR comment)
{
	if (!pDisp) return;
	HRESULT hr = S_OK;

	USES_CONVERSION;
	IConnectionPointContainer *spCPC = NULL;
	IConnectionPoint *spCP = NULL;
	IEnumConnectionPoints *ppEnum = NULL;
	IID id;
	LPOLESTR strGUID = 0;
	CComBSTR bstrId = NULL;

	if(comment) cout << comment << _T(" ");
	cout << _T("ConnectionPoint: [");
	hr = pDisp->QueryInterface(IID_IConnectionPointContainer, reinterpret_cast<void**>(&spCPC));
	if (SUCCEEDED(hr) && spCPC)
	{
		hr = spCPC->EnumConnectionPoints(&ppEnum);
		while(SUCCEEDED(ppEnum->Next(1, &spCP, NULL)) && spCP) 
		{
			spCP->GetConnectionInterface(&id);
			// 注意此处StringFromIID的正确用法, 否则会在Debug状态下出错: user breakpoint called from code 0x7c901230
			StringFromIID(id, &strGUID);
			bstrId = strGUID;
			CoTaskMemFree(strGUID);
			cout << (bstrId ? OLE2CT(bstrId) : _T("")) << _T(", ");
		}
	}
	cout << "]" << endl;
	if(spCP) spCP->Release();
	if(ppEnum) ppEnum->Release();
	if(spCPC) spCPC->Release();
/*
	{9bfbbc02-eff1-101a-84ed-00aa00341d07}	IPropertyNotifySink
	{3050f3c4-98b5-11cf-bb82-00aa00bdce0b}	HTMLObjectElementEvents
	{3050f620-98b5-11cf-bb82-00aa00bdce0b}	HTMLObjectElementEvents2
	{00020400-0000-0000-c000-000000000046}	IDispatch
	{1dc9ca50-06ef-11d2-8415-006008c3fbfc}	ITridentEventSink
	{d27cdb6d-ae6d-11cf-96b8-444553540000}	ShockwaveFlashObjects::_IShockwaveFlashEvents
*/
}