VOID WindCppAPIImp::release() { if (m_pDWindData != NULL) { cancelAllRequest(); HRESULT hr = E_FAIL; IConnectionPointContainer *pCPC; hr = m_pDWindData.QueryInterface(IID_IConnectionPointContainer, (void **)&pCPC); if(SUCCEEDED(hr)) { IConnectionPoint *pCP; hr = pCPC->FindConnectionPoint(__uuidof(WindDataCOMLib::_DWindDataCOMEvents), &pCP); if (SUCCEEDED(hr)) { hr = pCP->Unadvise(m_dwAdvise); pCP->Release(); } pCPC->Release(); } m_pDWindData.Release(); m_pDWindData = NULL; if (m_pSink != NULL) { delete m_pSink; m_pSink = NULL; } m_dwAdvise = 0; } }
void mHpWebClient::AddSink() { TraceFunc("mHpWebClient::AddSink"); IConnectionPointContainer* cpc; IConnectionPoint* cp; if (!browserObject_) { ::MessageBox(0, "browserObject_ is null in AddSink", 0, 0); return; } if (browserObject_->QueryInterface(IID_IConnectionPointContainer, reinterpret_cast<void**>(&cpc)) == S_OK) { if (cpc->FindConnectionPoint(DIID_DWebBrowserEvents2, &cp) == S_OK) { // TODO: Member Var unsigned long cookie = 1; if (! (SUCCEEDED(cp->Advise(static_cast<IDispatch*>(this), &cookie)) ) ) { ::MessageBox(0, "Advise failed", 0, 0); } } else { ::MessageBox(0, "FindConnectionPoint", 0, 0); } } else { ::MessageBox(0, "QueryInterface for IID_IConnectionPointContainer", 0, 0); } }
// unadvise the world without decrementing the reference count of the client. //reduces refcount of pworld by 1. void DeleteWorld(IWorld* pWorld, DWORD dwCookie) { IConnectionPoint* pconnpt = NULL; IConnectionPointContainer* pconnptctr = NULL; if (pWorld == NULL) return; HRESULT hr = pWorld->QueryInterface(IID_IConnectionPointContainer, (LPVOID*)&pconnptctr); if (SUCCEEDED(hr)) { hr = pconnptctr->FindConnectionPoint(IID_IVWObjectSite, &pconnpt); if (SUCCEEDED(hr)) { // HACK: artificially addref ptr IUnknown* p = (IUnknown *)dwCookie; p->AddRef(); pconnpt->Unadvise(dwCookie); pconnpt->Release(); } pconnptctr->Release(); } pWorld->Terminate(); // REVIEW: let caller SAFERELEASE ptr rather than do it in here // SAFERELEASE(pWorld); }
STDMETHODIMP CEnumConnectionPoints::Next(ULONG cConnections, IConnectionPoint** rgpCP, ULONG* pcFetched) { LOGCALL(("CEnumConnectionPoints::Next(%ld)\n", cConnections)); if (rgpCP == NULL) return E_POINTER; if (cConnections > 1 && pcFetched == NULL) return E_POINTER; CriticalSection critical_section(this); ULONG iConnections = 0; while (iConnections < cConnections) { IConnectionPoint* pCP = m_rgpCP[m_iCurrent]; if (pCP == NULL) break; m_iCurrent++; rgpCP[iConnections++] = pCP; pCP->AddRef(); } if (pcFetched) *pcFetched = iConnections; return iConnections < cConnections ? S_FALSE : S_OK; }
//コネクションポイントへの接続 bool Advise(IUnknown * container, REFIID iid, IUnknown * sink, DWORD * cookie, IConnectionPoint ** pcp = NULL) { IConnectionPointContainer * cpc; IConnectionPoint * cp; HRESULT result; if(pcp == NULL) pcp = &cp; container->QueryInterface(IID_IConnectionPointContainer, (void **)&cpc); if(cpc == 0) return false; cpc->FindConnectionPoint(iid, pcp); cpc->Release(); if(*pcp == 0) return false; if(FAILED(result = (*pcp)->Advise(sink, cookie))) return false; if(pcp == &cp) cp->Release(); return true; }
// @pymethod int|PyIConnectionPoint|Advise|Establishes a connection between the connection point object and the client's sink. PyObject *PyIConnectionPoint::Advise(PyObject *self, PyObject *args) { PyObject *obUnk; // @pyparm <o PyIUnknown>|unk||The client's advise sink if ( !PyArg_ParseTuple(args, "O:Advise", &obUnk) ) return NULL; IUnknown *pUnk; if (!PyCom_InterfaceFromPyInstanceOrObject(obUnk, IID_IUnknown, (void **)&pUnk, FALSE)) return NULL; IConnectionPoint *pICP = GetI(self); if ( pICP == NULL ) return NULL; DWORD cookie; PY_INTERFACE_PRECALL; HRESULT hr = pICP->Advise( pUnk, &cookie ); pUnk->Release(); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return SetPythonCOMError(self,hr); // @rdesc The result is the connection point identifier used by <om PyIConnectionPoint::Unadvise> return PyInt_FromLong(cookie); }
/********************************************************** * COperator::RegisterTapiEventInterface * *---------------------------------------* * Description: * Get a unique identifier (m_ulAdvice) for * this connection point. * Return: * S_OK * Failed HRESULTs from QI(), * IConnectionPointContainer::FindConnectionPoint(), * or IConnectionPoint::Advise() ***********************************************************/ HRESULT COperator::RegisterTapiEventInterface() { HRESULT hr = S_OK; IConnectionPointContainer * pCPC; IConnectionPoint * pCP; hr = m_pTapi->QueryInterface( IID_IConnectionPointContainer, (void **)&pCPC ); if ( SUCCEEDED( hr ) ) { hr = pCPC->FindConnectionPoint( IID_ITTAPIEventNotification, &pCP ); pCPC->Release(); } if ( SUCCEEDED( hr ) ) { hr = pCP->Advise( m_pTAPIEventNotification, &m_ulAdvise ); pCP->Release(); } return hr; } /* COperator::RegisterTapiEventInterface */
BOOL ZDrOleClient::InterfaceDisconnect( IUnknown *pObj, REFIID riid, LPDWORD pdwConn ) { HRESULT hr; IConnectionPointContainer *pCPointContainer = 0; IConnectionPoint *pCPoint = 0; if ( pObj == 0 || pdwConn == 0 ) return( FALSE ); if ( *pdwConn == 0 ) return( FALSE ); hr = pObj->QueryInterface( IID_IConnectionPointContainer, (LPVOID *) &pCPointContainer ); if ( FAILED( hr ) ) return( FALSE ); hr = pCPointContainer->FindConnectionPoint( riid, &pCPoint ); if ( SUCCEEDED( hr ) ) { // This is the Point to kill m_pEditorEventSink. We are doing this // through Unadvise hr = pCPoint->Unadvise(*pdwConn); if ( SUCCEEDED( hr ) ) *pdwConn = 0L; pCPoint->Release( ); } pCPointContainer->Release( ); return( SUCCEEDED( hr ) ); } // InterfaceDisconnect
BOOL CXTPReportDataManager::DataBind() { HRESULT hr = E_FAIL; try { if (m_pDataSource == NULL) return FALSE; m_pConnection = NULL; // get connection _variant_t vtConnection; if (SUCCEEDED(hr = m_pDataSource->get_ActiveConnection(&vtConnection)) && vtConnection.pdispVal) { m_pConnection = vtConnection; } // clear report control ClearReportControl(); // create columns if (FAILED(hr = CreateColumns())) return FALSE; // create records if (FAILED(hr = AddReportRecords(m_pDataSource, FALSE))) return FALSE; m_pReportControl->Populate(); // advise events m_pRstEvent = new CRstEvent(this); if (!m_pRstEvent) return FALSE; IUnknown *pUnk = NULL; hr = m_pRstEvent->QueryInterface(__uuidof(IUnknown), (void **) &pUnk); if (FAILED(hr)) return FALSE; IConnectionPointContainer *pCPC = NULL; IConnectionPoint *pCP = NULL; hr = m_pDataSource->QueryInterface(__uuidof(IConnectionPointContainer), (void**)&pCPC); if (FAILED(hr)) return FALSE; hr = pCPC->FindConnectionPoint(__uuidof(XTPREPORTADODB::RecordsetEvents), &pCP); pCPC->Release(); if (FAILED(hr)) return FALSE; hr = pCP->Advise(pUnk, &m_dwRstEvent); pCP->Release(); } catch(_com_error &e) { TRACE_ProviderError(m_pConnection); TRACE_ComError(e); hr = FAILED(hr) ? hr : E_FAIL; } catch(...) { TRACE(_T("Unknown error in DataBind()\n")); hr = FAILED(hr) ? hr : E_FAIL; } return FAILED(hr) ? FALSE : TRUE; }
BOOL ZDrOleClient::InterfaceConnect( IUnknown *pObj, REFIID riid, IUnknown *pIUnknownSink, LPDWORD pdwConn ) { TraceLineS( "ZDrOleClient::InterfaceConnect", "" ); HRESULT hr; IConnectionPointContainer *pCPointContainer = 0; IConnectionPoint *pCPoint = 0; if ( pObj == 0 || pIUnknownSink == 0 || pdwConn == 0 ) return( FALSE ); hr = pObj->QueryInterface( IID_IConnectionPointContainer, (LPVOID *) &pCPointContainer ); if ( FAILED( hr ) ) return( FALSE ); hr = pCPointContainer->FindConnectionPoint( riid, &pCPoint ); if ( SUCCEEDED( hr ) ) { hr = pCPoint->Advise( pIUnknownSink, pdwConn ); if ( hr == E_POINTER ) AfxMessageBox( "Invalid Pointer!" ); else if ( hr == CONNECT_E_ADVISELIMIT ) AfxMessageBox( "No more Connections available!" ); else if ( hr == CONNECT_E_CANNOTCONNECT ) AfxMessageBox( "No Connection!" ); pCPoint->Release( ); } else { if ( hr == E_OUTOFMEMORY ) TraceLineS( "FindConnectionPoint failed: ", "E_OUTOFMEMORY" ); else if ( hr == E_UNEXPECTED ) TraceLineS( "FindConnectionPoint failed: ", "E_UNEXPECTED" ); else if ( hr == E_POINTER ) TraceLineS( "FindConnectionPoint failed: ", "E_POINTER" ); else if ( hr == CONNECT_E_NOCONNECTION ) TraceLineS( "FindConnectionPoint failed: ", "CONNECT_E_NOCONNECTION" ); else if ( hr == S_OK ) TraceLineS( "FindConnectionPoint failed: ", "S_OK" ); else TraceLineX( "FindConnectionPoint failed: ", (zLONG) hr ); } pCPointContainer->Release( ); return( SUCCEEDED( hr ) ); } // InterfaceConnect
static void initEventHandler() { IConnectionPointContainer* icpc; iTunes->QueryInterface(IID_IConnectionPointContainer, (void **)&icpc); IConnectionPoint* icp; icpc->FindConnectionPoint(DIID__IiTunesEvents, &icp); icpc->Release(); DWORD dwAdvise; iTunesEventHandler = new CiTunesEventHandler(); icp->Advise(iTunesEventHandler, &dwAdvise); icp->Release(); }
void WmdmLister::ReallyShutdown() { // Unregister for notifications IConnectionPointContainer* cp_container; thread_->manager()->QueryInterface(IID_IConnectionPointContainer, (void**)&cp_container); IConnectionPoint* cp; cp_container->FindConnectionPoint(IID_IWMDMNotification, &cp); cp->Release(); cp_container->Release(); thread_.reset(); }
BOOL WindCppAPIImp::initialize() { if (m_pDWindData != NULL) { return TRUE; } HRESULT hr = E_FAIL; hr = m_pDWindData.CreateInstance(__uuidof(WindDataCOMLib::WindDataCOM), NULL, CLSCTX_ALL); if(!SUCCEEDED(hr)) { return FALSE; } m_pDWindData->enableAsyn(1); IConnectionPointContainer *pCPC; hr = m_pDWindData.QueryInterface(IID_IConnectionPointContainer, (void **)&pCPC); if(!SUCCEEDED(hr)) { return FALSE; } IConnectionPoint *pCP; hr = pCPC->FindConnectionPoint(__uuidof(WindDataCOMLib::_DWindDataCOMEvents), &pCP); if (!SUCCEEDED(hr)) { return FALSE; } pCPC->Release(); IUnknown *m_pSinkUnk; m_pSink = new WindDataComSink(); hr = m_pSink->QueryInterface(IID_IUnknown, (void **)&m_pSinkUnk); if(!SUCCEEDED(hr)) { pCP->Release(); return FALSE; } hr = pCP->Advise(m_pSinkUnk, &m_dwAdvise); if(!SUCCEEDED(hr)) { return FALSE; } pCP->Release(); return TRUE; }
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(); }
HRESULT CJSExtender::SinkObject(CString strPrefix, IDispatch *pUnk, LCID lcid) { if (!pUnk || strPrefix==_T("")) return E_INVALIDARG; HRESULT hr = S_FALSE; GUID iid = GUID_NULL; if (theApp.m_pEventProxy) theApp.m_pEventProxy->GetConnectionInterface(&iid); else { CComQIPtr<IConnectionPointContainer> pContainer(pUnk); if (pContainer == nullptr) return 0; GUID libid; WORD wMajorVer = 1; WORD wMinorVer = 0; hr = AtlGetObjectSourceInterface(pUnk, &libid, &iid, &wMajorVer, &wMinorVer); if (iid == GUID_NULL) { IConnectionPoint* pConnectionPoint = nullptr; IEnumConnectionPoints* pEnum = nullptr; HRESULT hr = pContainer->EnumConnectionPoints(&pEnum); if (pEnum) { ULONG uFetched; while (S_OK == (pEnum->Next(1, &pConnectionPoint, &uFetched)) && uFetched >= 1) { hr = pConnectionPoint->GetConnectionInterface(&iid); if (hr == S_OK) { pConnectionPoint->Release(); pConnectionPoint = nullptr; break; } pConnectionPoint->Release(); pConnectionPoint = nullptr; } pEnum->Release(); } } } if (iid != GUID_NULL) new CJSProxyObj(this, pUnk, iid, strPrefix); return S_OK; }
Win32HtmlViewRep( Win32HtmlView *view, HWND hw,int style ):hwnd(hw){ owner=view; site.rep=this; eventsink.rep=this; frame.rep=this; viewstyle=style; emitNavEvent=!!(viewstyle & BBHtmlView::NONAVIGATE); currenturl=new BBString(""); eventurl=new BBString(""); OleCreate( CLSID_WebBrowser,IID_IOleObject,OLERENDER_DRAW,0,&site,&storage,(void**)&oleObject ); OleSetContainedObject( oleObject,TRUE); oleObject->SetHostNames(L"Web Host",L"Web View"); oleObject->QueryInterface(IID_IWebBrowser2,(void**)&iBrowser); oleObject->QueryInterface(IID_IOleInPlaceObject,(void**)&inPlaceObject ); oleObject->QueryInterface(IID_IConnectionPointContainer,(void**)&iConnection); iConnection->FindConnectionPoint(DIID_DWebBrowserEvents, &iConnectionPoint); iConnectionPoint->Advise((LPUNKNOWN)&eventsink, &dwCookie); RECT rect; ::GetClientRect( hwnd,&rect ); oleObject->DoVerb(OLEIVERB_SHOW,NULL,&site,-1,hwnd,&rect); go( "about:blank" ); }
int main(int argc, char * argv[]) { IKernelLog * pKernelLog; IKernelLogEvents * psKernelLogEvents; IConnectionPoint * cp; DWORD cookie; MSG msg; IKernelLogEvents a; ::CoInitialize(NULL); destination = 0; tmain_threadid = ::GetCurrentThreadId(); if(!FAILED(::CoCreateInstance(CLSID_KernelLog, NULL, CLSCTX_ALL, __uuidof(IKernelLog), (void **)&pKernelLog))) { cp = NULL; psKernelLogEvents = new IKernelLogEvents; if(Advise(pKernelLog, __uuidof(_IKernelLogEvents), psKernelLogEvents, &cookie, &cp)) { ::SetConsoleCtrlHandler(HandlerRoutine, TRUE); while(::GetMessage(&msg, NULL, 0, 0) != 0) { ::DispatchMessage(&msg); } ::SetConsoleCtrlHandler(HandlerRoutine, FALSE); cp->Unadvise(cookie); } delete psKernelLogEvents; if(pKernelLog != NULL) pKernelLog->Release(); } if(destination != NULL) { Printf("\n\nSuspended by Ctrl-C event occursion.\n"); fclose(destination); } ::CoUninitialize(); return 0; }
// @pymethod <o PyIID>|PyIConnectionPoint|GetConnectionInterface|Retrieves the IID of the interface represented by the connection point. PyObject *PyIConnectionPoint::GetConnectionInterface(PyObject *self, PyObject *args) { if ( !PyArg_ParseTuple(args, ":GetConnectionInterface") ) return NULL; IConnectionPoint *pICP = GetI(self); if ( pICP == NULL ) return NULL; IID iid; PY_INTERFACE_PRECALL; HRESULT hr = pICP->GetConnectionInterface(&iid); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return SetPythonCOMError(self,hr); return PyWinObject_FromIID(iid); }
// @pymethod <o PyIEnumConnections>|PyIConnectionPoint|EnumConnections|Creates an enumerator to iterate through the connections for the connection point PyObject *PyIConnectionPoint::EnumConnections(PyObject *self, PyObject *args) { if ( !PyArg_ParseTuple(args, ":EnumConnections") ) return NULL; IConnectionPoint *pICP = GetI(self); if ( pICP == NULL ) return NULL; IEnumConnections *p; PY_INTERFACE_PRECALL; HRESULT hr = pICP->EnumConnections(&p); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return SetPythonCOMError(self,hr); return PyCom_PyObjectFromIUnknown(p, IID_IEnumConnections, FALSE); }
// @pymethod <o PyIConnectionPointContainer>|PyIConnectionPoint|GetConnectionPointContainer|Gets the connection point container for the object. PyObject *PyIConnectionPoint::GetConnectionPointContainer(PyObject *self, PyObject *args) { if ( !PyArg_ParseTuple(args, ":GetConnectionPointContainer") ) return NULL; IConnectionPoint *pICP = GetI(self); if ( pICP == NULL ) return NULL; IConnectionPointContainer *pCont; PY_INTERFACE_PRECALL; HRESULT hr = pICP->GetConnectionPointContainer(&pCont); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return SetPythonCOMError(self,hr); return PyCom_PyObjectFromIUnknown( pCont, IID_IConnectionPointContainer ); }
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 */ }
void Win32WebControl::removeWebView() { if (_connectionPoint != NULL) { _connectionPoint->Unadvise(_cookie); _connectionPoint->Release(); _connectionPoint = NULL; } if (_htmlDoc != NULL) { _htmlDoc->Release(); _htmlDoc = NULL; } if (_webBrowser2 != NULL) { _webBrowser2->Release(); _webBrowser2 = NULL; } _winContainer.DestroyWindow(); }
// @pymethod |PyIConnectionPoint|Unadvise|Terminates an advisory connection previously established through IConnectionPoint::Advise. The dwCookie parameter identifies the connection to terminate. PyObject *PyIConnectionPoint::Unadvise(PyObject *self, PyObject *args) { DWORD cookie; // @pyparm int|cookie||The connection token if ( !PyArg_ParseTuple(args, "i:Unadvise", &cookie) ) return NULL; IConnectionPoint *pICP = GetI(self); if ( pICP == NULL ) return NULL; PY_INTERFACE_PRECALL; HRESULT hr = pICP->Unadvise(cookie); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return SetPythonCOMError(self,hr); Py_INCREF(Py_None); return Py_None; }
void CXTPReportDataManager::RemoveDataSource() { try { // unadvise events if (m_pRstEvent) { IConnectionPointContainer *pCPC = NULL; IConnectionPoint *pCP = NULL; HRESULT hr = m_pDataSource->QueryInterface(__uuidof(IConnectionPointContainer), (void**)&pCPC); if (SUCCEEDED(hr)) { hr = pCPC->FindConnectionPoint(__uuidof(XTPREPORTADODB::RecordsetEvents), &pCP); pCPC->Release(); if (SUCCEEDED(hr)) { hr = pCP->Unadvise(m_dwRstEvent); pCP->Release(); } } //delete m_pRstEvent; m_pRstEvent->Release(); m_pRstEvent = NULL; } // set data source pointer to NULL m_pDataSource = NULL; } catch(_com_error &e) { TRACE_ProviderError(m_pConnection); TRACE_ComError(e); } catch(...) { TRACE(_T("Unknown error in RemoveDataSource()\n")); } }
bool Win32WebControl::createWebView( const std::function<bool (const std::string &)> &shouldStartLoading, const std::function<void (const std::string &)> &didFinishLoading, const std::function<void (const std::string &)> &didFailLoading, const std::function<void (const std::string &)> &onJsCallback) { bool ret = false; IConnectionPointContainer *container = NULL; do { HWND hwnd = cocos2d::Director::getInstance()->getOpenGLView()->getWin32Window(); _winContainer.Create(hwnd, NULL, NULL, WS_CHILD | WS_VISIBLE); HRESULT hr; hr = _winContainer.CreateControl(L"shell.Explorer.2"); CC_BREAK_IF(FAILED(hr)); hr = _winContainer.QueryControl(__uuidof(IWebBrowser2), (void **)&_webBrowser2); CC_BREAK_IF(FAILED(hr) || _webBrowser2 == NULL); _webBrowser2->put_Silent(VARIANT_TRUE); VARIANT var; VariantInit(&var); var.vt = VT_BSTR; var.bstrVal = SysAllocString(L"about:blank"); hr = _webBrowser2->Navigate2(&var, NULL, NULL, NULL, NULL); SysFreeString(var.bstrVal); VariantClear(&var); CC_BREAK_IF(FAILED(hr)); hr = _webBrowser2->QueryInterface(IID_IConnectionPointContainer, (void **)&container); CC_BREAK_IF(FAILED(hr)); hr = container->FindConnectionPoint(DIID_DWebBrowserEvents2, &_connectionPoint); CC_BREAK_IF(FAILED(hr)); hr = _connectionPoint->Advise(this, &_cookie); CC_BREAK_IF(FAILED(hr)); hr = _webBrowser2->get_Document(&_htmlDoc); CC_BREAK_IF(FAILED(hr)); ret = true; } while (0); if (!ret) { removeWebView(); } if (container != NULL) { container->Release(); container = NULL; } _shouldStartLoading = shouldStartLoading; _didFinishLoading = didFinishLoading; _didFailLoading = didFailLoading; _onJsCallback = onJsCallback; return ret; }
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); IDot11AdHocManager * AdHocManager = NULL; IEnumDot11AdHocNetworks * networks = NULL; HRESULT ans; ULONG cnt; IDot11AdHocNetwork * network [10]; IConnectionPointContainer * pConnectionPointContainer; IConnectionPoint * pConnectionPoint; LPWSTR ssid; cout << "Initialising COM Lib... "; ans = CoInitialize(NULL); cout << ((SUCCEEDED(ans)) ? "OK" : "KO") << endl; cout << "Creating AdHocManager... "; ans = CoCreateInstance(CLSID_Dot11AdHocManager,NULL,CLSCTX_INPROC_SERVER,IID_IDot11AdHocManager,(void**) &AdHocManager); cout << ((SUCCEEDED(ans)) ? "OK" : "KO") << endl; cout << "Casting AdHocManager in ConnectionPointContainer... "; ans = AdHocManager->QueryInterface(IID_IConnectionPointContainer,(void**) &pConnectionPointContainer); cout << ((SUCCEEDED(ans)) ? "OK" : "KO") << endl; cout << "Retrieving connection point for AdHocManagerNotifications... "; ans = pConnectionPointContainer->FindConnectionPoint(IID_IDot11AdHocManagerNotificationSink,&pConnectionPoint); cout << ((SUCCEEDED(ans)) ? "OK" : "KO") << endl; cManagerSink mSink; DWORD sinkCookie; cout << "Registering for notifications... "; ans = pConnectionPoint->Advise((IUnknown*) &mSink, &sinkCookie); cout << ((SUCCEEDED(ans)) ? "OK" : "KO") << endl; cout << "Getting Network list... "; ans = AdHocManager->GetIEnumDot11AdHocNetworks(NULL, &networks); cout << "OK" << endl << "Extracting Networks... "; ans = networks->Next(10,network,&cnt); printf("Got %d networks\n",cnt); bool found = false; IDot11AdHocNetwork * myNet; for (ULONG i = 0; i < cnt; i++) { network[i]->GetSSID(&ssid); wstring str(ssid); wcout << "\tssid = " << str << endl; if (str == ADHOC_SSID) { found=true; myNet = network[i]; } } if (found) { cout << "Casting NetWork in ConnectionPointContainer... "; ans = myNet->QueryInterface(IID_IConnectionPointContainer,(void**) &pConnectionPointContainer); cout << ((SUCCEEDED(ans)) ? "OK" : "KO") << endl; cout << "Retrieving connection point for NetworkNotifications... "; ans = pConnectionPointContainer->FindConnectionPoint(IID_IDot11AdHocNetworkNotificationSink,&pConnectionPoint); cout << ((SUCCEEDED(ans)) ? "OK" : "KO") << endl; cout << "Registering for notifications... "; ans = pConnectionPoint->Advise((IUnknown*) &sink,&sinkCookie); cout << ((SUCCEEDED(ans)) ? "OK" : "KO") << endl; printf("Connecting... "); ans = myNet->Connect(ADHOC_PWD, 0x54, false, false); switch (ans) { case S_OK: printf("OK"); break; case REGDB_E_CLASSNOTREG: printf("REGDB"); break; case CLASS_E_NOAGGREGATION: printf("CLASS"); break; case E_NOINTERFACE: printf("NOINTERFACE"); break; case E_POINTER: printf("POINTER"); break; default : printf("%d",ans); } printf("\n"); } if (!found) { printf("Creating the network... "); ans = AdHocManager->CreateNetwork(ADHOC_SSID, ADHOC_PWD, 0x54, NULL, &securitySettings, NULL, &myNet); switch (ans) { case S_OK: printf("OK"); break; case REGDB_E_CLASSNOTREG: printf("REGDB"); break; case CLASS_E_NOAGGREGATION: printf("CLASS"); break; case E_NOINTERFACE: printf("NOINTERFACE"); break; case E_POINTER: printf("POINTER"); break; default : printf("%d",ans); } printf("\n"); cout << "Casting NetWork in ConnectionPointContainer... "; ans = myNet->QueryInterface(IID_IConnectionPointContainer,(void**) &pConnectionPointContainer); cout << ((SUCCEEDED(ans)) ? "OK" : "KO") << endl; cout << "Retrieving connection point for NetworkNotifications... "; ans = pConnectionPointContainer->FindConnectionPoint(IID_IDot11AdHocNetworkNotificationSink,&pConnectionPoint); cout << ((SUCCEEDED(ans)) ? "OK" : "KO") << endl; cout << "Registering for notifications... "; ans = pConnectionPoint->Advise((IUnknown*) &sink,&sinkCookie); cout << ((SUCCEEDED(ans)) ? "OK" : "KO") << endl; cout << "Committing the network... "; ans = AdHocManager->CommitCreatedNetwork(myNet,false,false); switch (ans) { case S_OK: printf("OK"); break; case REGDB_E_CLASSNOTREG: printf("REGDB"); break; case CLASS_E_NOAGGREGATION: printf("CLASS"); break; case E_NOINTERFACE: printf("NOINTERFACE"); break; case E_POINTER: printf("POINTER"); break; default : printf("%d",ans); } printf("\n"); } return a.exec(); }
STDMETHODIMP COPCGroupImpl::put_IsSubscribed(VARIANT_BOOL IsSubscribed) { if( !m_pOPCGroup ) return E_FAIL; HRESULT hr=S_OK; if( IsSubscribed == m_subscribed ) return hr; if( IsSubscribed ) { if( m_usingCP ) { IConnectionPointContainer *pCPC = 0; hr = m_pOPCGroup->QueryInterface(IID_IConnectionPointContainer, (LPVOID*)&pCPC); if( SUCCEEDED(hr) ) { IConnectionPoint *pCallbackCP = 0; hr = pCPC->FindConnectionPoint(IID_IOPCDataCallback, &pCallbackCP); pCPC->Release(); if( FAILED(hr) ) { return E_FAIL; } IUnknown* pUnk = NULL; ((COPCGroup*)this)->QueryInterface( IID_IUnknown, (LPVOID*)&pUnk); hr = pCallbackCP->Advise(pUnk, &m_DataConnection); pCallbackCP->Release(); pUnk->Release(); if( FAILED(hr) ) { return E_FAIL; } } } else { if( !m_pIDataObject ) { m_pIDataObject = m_pOPCGroup; // get IDataObject Interface if( !m_pIDataObject ) return E_FAIL; } IAdviseSink *pAdviseSink = NULL; hr = ((COPCGroup*)this)->QueryInterface(IID_IAdviseSink, (LPVOID *)&pAdviseSink); if (FAILED(hr)) { return E_FAIL; } FORMATETC formatEtc ; formatEtc.cfFormat = OPCSTMFORMATDATATIME; formatEtc.tymed = TYMED_HGLOBAL; formatEtc.ptd = NULL; formatEtc.dwAspect = DVASPECT_CONTENT; formatEtc.lindex = -1; hr = m_pIDataObject->DAdvise(&formatEtc, (DWORD)ADVF_PRIMEFIRST, pAdviseSink, &m_DataConnection); if( SUCCEEDED(hr) ) // also advise write complete { formatEtc.cfFormat = OPCSTMFORMATWRITECOMPLETE; hr = m_pIDataObject->DAdvise(&formatEtc, (DWORD)ADVF_PRIMEFIRST, pAdviseSink, &m_WriteConnection); } // DAdvise will hold its own reference pAdviseSink->Release(); } m_subscribed = VARIANT_TRUE; } else // Unsubscribing { if( m_usingCP ) { // OPC 2.0 ConnectionPoints IConnectionPointContainer *pCPC = 0; hr = m_pOPCGroup->QueryInterface(IID_IConnectionPointContainer, (LPVOID*)&pCPC); if( SUCCEEDED(hr) ) { IConnectionPoint *pCallbackCP = 0; hr = pCPC->FindConnectionPoint(IID_IOPCDataCallback, &pCallbackCP); if( SUCCEEDED(hr) ) { hr = pCallbackCP->Unadvise(m_DataConnection); pCallbackCP->Release(); } pCPC->Release(); } } else { if( m_pIDataObject.p ) // if a valid interface pointer { hr = m_pIDataObject->DUnadvise(m_DataConnection); if( SUCCEEDED(hr) ) // also unadvise write complete hr = m_pIDataObject->DUnadvise(m_WriteConnection); m_pIDataObject.Release(); } } m_subscribed = VARIANT_FALSE; } return hr; }
HRESULT RegisterCallback() { LogMessage("RegisterCallback: started"); HRESULT hr = S_OK; // // get connection point container on the tapi object // IConnectionPointContainer *pCPContainer = NULL; hr = g_pTapi->QueryInterface( IID_IConnectionPointContainer, (void **)&pCPContainer ); if (FAILED(hr)) { LogError("RegisterCallback: " "Failed to get IConnectionPointContainer on TAPI"); return hr; } // // find connection point for our interface // IConnectionPoint *pCP = NULL; hr = pCPContainer->FindConnectionPoint(IID_ITTAPIEventNotification, &pCP); pCPContainer->Release(); pCPContainer = NULL; if (FAILED(hr)) { LogError("RegisterCallback: " "Failed to get a connecion point for ITTAPIEventNotification"); return hr; } // // create the callback object and register it with TAPI. // for simplicity, the callback in this sample is not a // full-fledged COM object. So create is with new. // ITTAPIEventNotification *pTAPIEventNotification = new CTAPIEventNotification; if (NULL == pTAPIEventNotification) { LogError("RegisterCallback: Failed to create a tapi event notification object."); pCP->Release(); pCP = NULL; return E_OUTOFMEMORY; } // // will use the cookie later to register for events from addresses // and to unregister the callback when we no longer needs the events // hr = pCP->Advise(pTAPIEventNotification, &g_nTAPINotificationCookie); pCP->Release(); pCP = NULL; // // whether Advise failed or succeeded, we no longer need a reference to // the callback // pTAPIEventNotification->Release(); pTAPIEventNotification = NULL; if (FAILED(hr)) { g_nTAPINotificationCookie = 0; LogError("RegisterCallback: Failed to Advise"); } LogMessage("RegisterCallback: completed"); return hr; }
HRESULT UnRegisterCallBack() { LogMessage("UnRegisterCallBack: started"); HRESULT hr = S_OK; // // get connection point container on the tapi object // IConnectionPointContainer *pCPContainer = NULL; hr = g_pTapi->QueryInterface(IID_IConnectionPointContainer, (void **)&pCPContainer); if (FAILED(hr)) { LogError("UnRegisterCallBack: " "Failed to get IConnectionPointContainer on TAPI"); return hr; } // // find connection point for our interface // IConnectionPoint *pConnectionPoint = NULL; hr = pCPContainer->FindConnectionPoint(IID_ITTAPIEventNotification, &pConnectionPoint); pCPContainer->Release(); pCPContainer = NULL; if (FAILED(hr)) { LogError("RegisterCallback: Failed to get a connection point for " "ITTAPIEventNotification"); return hr; } // // unregister the callback // hr = pConnectionPoint->Unadvise(g_nTAPINotificationCookie); pConnectionPoint->Release(); pConnectionPoint = NULL; g_nTAPINotificationCookie = 0; if (FAILED(hr)) { LogError("UnRegisterCallBack: Unadvise failed"); } else { LogMessage("UnRegisterCallBack: succeeded"); } return hr; }