void IEView::scrollToBottom() { /* IHTMLDocument2 *document = getDocument(); if (document != NULL) { wchar_t *p = NULL; if (SUCCEEDED(document->get_readyState(&p))) { int licznik = 0; do { if (FAILED(document->get_readyState(&p))) { break; } licznik++; if (licznik == 1) break; Sleep(10); } while (!wcscmp(p, L"loading")); } IHTMLWindow2* pWindow = NULL; if (SUCCEEDED(document->get_parentWindow( &pWindow )) && pWindow != NULL) { pWindow->scrollBy( 0, 0x01FFFFFF ); } document->Release(); }*/ IHTMLDocument2 *document = getDocument(); if (document != NULL) { IHTMLElementCollection *collection; IHTMLElement *element; IDispatch *dispatch; if (SUCCEEDED(document->get_all(&collection)) && (collection != NULL)) { long len; if (SUCCEEDED(collection->get_length(&len))) { VARIANT variant; variant.vt = VT_I4; variant.lVal = len-1; if (SUCCEEDED(collection->item(variant, variant, &dispatch)) && (dispatch != NULL)) { if (SUCCEEDED(dispatch->QueryInterface(IID_IHTMLElement,(void**)&element)) && (element != NULL)) { variant.vt = VT_BOOL; variant.boolVal = VARIANT_FALSE; if (SUCCEEDED(element->scrollIntoView(variant))) { } element->Release(); } dispatch->Release(); } } collection->Release(); } IHTMLWindow2* pWindow = NULL; if (SUCCEEDED(document->get_parentWindow( &pWindow )) && (pWindow != NULL)) { pWindow->scrollBy( -0x01FFFFFF, 0x01FFFFFF ); pWindow->Release(); } document->Release(); } }
HRESULT GetShellDispatchFromView(IShellView *psv, REFIID riid, void **ppv) { *ppv = NULL; IDispatch *pdispBackground; HRESULT hr = psv->GetItemObject(SVGIO_BACKGROUND, IID_PPV_ARGS(&pdispBackground)); if (SUCCEEDED(hr)) { IShellFolderViewDual *psfvd; hr = pdispBackground->QueryInterface(IID_PPV_ARGS(&psfvd)); if (SUCCEEDED(hr)) { IDispatch *pdisp; hr = psfvd->get_Application(&pdisp); if (SUCCEEDED(hr)) { hr = pdisp->QueryInterface(riid, ppv); pdisp->Release(); } psfvd->Release(); } pdispBackground->Release(); } return hr; }
//----------------------------------------------------------------------------- // Name: AddHtmlContentToElement // Object: // Parameters : // in : // out : // return : //----------------------------------------------------------------------------- BOOL CHtmlViewer::AddHtmlContentToElement(TCHAR* Id,TCHAR* Content) { if (this->pIWebBrowser==NULL) return FALSE; if (!this->IsPageCompleted()) return FALSE; HRESULT hr; BOOL bRet; IDispatch* pHtmlDocDispatch = NULL; IHTMLDocument3* pHtmlDoc = NULL; IHTMLElement* pElem = NULL; BSTR bstrElementId; #if ((!defined(UNICODE))&& (!defined(_UNICODE))) WCHAR* psz; #endif // get IDispatch document interface hr = pIWebBrowser->get_Document(&pHtmlDocDispatch); if (FAILED (hr) || (pHtmlDocDispatch == NULL)) return FALSE; // get IHTMLDocument3 document interface hr = pHtmlDocDispatch->QueryInterface(IID_IHTMLDocument3,(void**)&pHtmlDoc); if (FAILED (hr) || (pHtmlDoc == NULL)) { pHtmlDocDispatch->Release(); return FALSE; } // get pointer to element from it's Id #if (defined(UNICODE)||defined(_UNICODE)) bstrElementId=SysAllocString(Id); #else CAnsiUnicodeConvert::AnsiToUnicode(Id,&psz); bstrElementId=SysAllocString(psz); free(psz); #endif hr = pHtmlDoc->getElementById(bstrElementId,&pElem); SysFreeString(bstrElementId); if (FAILED (hr) || (pElem == NULL)) { pHtmlDoc->Release(); pHtmlDocDispatch->Release(); return FALSE; } bRet=this->AddHtmlContentToElement(pElem,Content); pElem->Release(); pHtmlDoc->Release(); pHtmlDocDispatch->Release(); return bRet; }
//Create an empty workshet BOOL CXLAutomation::CreateWorkSheet() { if(NULL == m_pdispExcelApp) return FALSE; BOOL fResult; VARIANTARG varg1, varg2; IDispatch *pdispRange = NULL; IDispatch *pdispActiveSheet = NULL; IDispatch *pdispActiveCell = NULL; IDispatch *pdispCrt = NULL; // Set wb = [application].Workbooks.Add(template := xlWorksheet) ClearAllArgs(); if (!ExlInvoke(m_pdispExcelApp, L"Workbooks", &varg1, DISPATCH_PROPERTYGET, 0)) return FALSE; ClearAllArgs(); AddArgumentInt2(L"Template", 0, xlWorksheet); fResult = ExlInvoke(varg1.pdispVal, L"Add", &varg2, DISPATCH_METHOD, 0); ReleaseVariant(&varg1); if (!fResult) return FALSE; m_pdispWorkbook = varg2.pdispVal; // Set ws = wb.Worksheets(1) ClearAllArgs(); AddArgumentInt2(NULL, 0, 1); if (!ExlInvoke(m_pdispWorkbook, L"Worksheets", &varg2, DISPATCH_PROPERTYGET, 0)) goto CreateWsBail; m_pdispWorksheet = varg2.pdispVal; fResult = TRUE; CreateWsExit: if (pdispRange != NULL) pdispRange->Release(); if (pdispCrt != NULL) pdispCrt->Release(); return fResult; CreateWsBail: fResult = FALSE; goto CreateWsExit; }
void EnumEmbeds(IHTMLDocument2 *pIHTMLDocument2) { if(!pIHTMLDocument2) return; HRESULT hr; USES_CONVERSION; CComPtr< IHTMLElementCollection > spEmbedCollection; hr = pIHTMLDocument2->get_embeds(&spEmbedCollection); //取得Embed的集合 if (FAILED(hr)) { cout << _T("错误: 获取Embed集合IHTMLElementCollection!") << endl; return; } long nEmbedCount = 0; //取得Embed个数 hr = spEmbedCollection->get_length(&nEmbedCount); if (FAILED(hr)) { cout << _T("错误: 获取Embed集合IHTMLElementCollection的长度!") << endl; } cout << "Embed对象共: " << nEmbedCount << endl; CComBSTR bstrPluginsPage, bstrSrc; IDispatch *pDisp = NULL; CComQIPtr< IHTMLEmbedElement > spEmbedElement; for(long i = 0; i < nEmbedCount; i++) { hr = spEmbedCollection->item(CComVariant(i), CComVariant(), &pDisp); if (FAILED(hr) || !pDisp) continue; spEmbedElement = pDisp; pDisp->Release(); spEmbedElement->get_pluginspage(&bstrPluginsPage); spEmbedElement->get_src(&bstrSrc); cout << i + 1 << ": pluginspage = " << (bstrPluginsPage ? OLE2CT(bstrPluginsPage) : _T("")) << ", src = " << (bstrSrc ? OLE2CT(bstrSrc) : _T("")) << endl; } if (pDisp) { pDisp->Release(); pDisp = NULL; } }
BOOL CScriptMeterImpl::AddDefaultScriptItem() { HRESULT hr; hr = scriptPtr->AddTypeLib(LIBID_COMMETERSLib, 1, 0, 0); if (!SUCCEEDED(hr)) return false; BOOL ret = AddScriptItem(ACTIVESCRIPT_HOST_NAME, (IMeter*)this); #ifdef CONNECTABLE IDispatch *pDispatch; scriptPtr->GetScriptDispatch(NULL, &pDispatch); pDispatch->Release(); pUtils->put_Script(pDispatch); pUtils->put_ScriptHost(this); AddScriptItem(UTILS_NAME, pUtils, SCRIPTITEM_ISVISIBLE); #endif IClientModel *_model = 0; get_Model(&_model); if (_model) { ret = AddScriptItem(MODEL_NAME, _model, SCRIPTITEM_ISVISIBLE | MY_SCRIPTITEM_WEAK); model->Release(); } else AtlTrace("Model is not set in ScriptMeterImpl\n"); return ret; }
STDMETHODIMP CompositeOverlayImpl<B>::put_Overlays(LPSAFEARRAY newVal) { ClearAndDestroy(); long lb = 0; long ub = 0; if( !(newVal->fFeatures & FADF_DISPATCH) ) return E_INVALIDARG; HRESULT hr = ::SafeArrayGetUBound(newVal, 1, &ub); hr = ::SafeArrayGetLBound(newVal, 1, &lb); IDispatch *pDisp; IOverlay *pOverlay; long indices[1]; for (int i=lb; i<=ub; i++) { indices[0] = i; pDisp = 0; ::SafeArrayGetElement(newVal, indices, &pDisp); if (pDisp) { if (SUCCEEDED(pDisp->QueryInterface(__uuidof(IOverlay), (void**)&pOverlay))) { AtlTrace("Added overlay to composite\n"); Add(pOverlay); pOverlay->Release(); } pDisp->Release(); } } return S_OK; }
//May be new points have been added to the plot data source. Update plot range BOOL CXLAutomation::UpdatePlotRange(int nYColumn) { if((NULL == m_pdispWorksheet) || (NULL == m_pdispWorkbook) || (NULL == m_pdispActiveChart)) return FALSE; VARIANTARG varg1; IDispatch *pdispRange = NULL; IDispatch *pdispActiveChart = NULL; BOOL bResult = TRUE; ClearAllArgs(); AddArgumentDouble(NULL, 0, nYColumn); if (!ExlInvoke(m_pdispWorksheet, L"Columns", &varg1, DISPATCH_PROPERTYGET, DISP_FREEARGS)) return FALSE; pdispRange = varg1.pdispVal; //ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A:A, B:B"), PlotBy:= _ // xlColumns ClearAllArgs(); AddArgumentInt2(L"PlotBy", 0, xlColumns); AddArgumentDispatch(L"Source", 0, pdispRange); // will auto-free pdispRange = NULL; if (!ExlInvoke(m_pdispActiveChart, L"SetSourceData", NULL, DISPATCH_METHOD, DISP_FREEARGS)) bResult = FALSE; ClearAllArgs(); if(NULL != pdispRange) { pdispRange->Release(); pdispRange = NULL; } return bResult; }
void CIncrementSystemBFDlg::ProcessElementCollection(IHTMLElementCollection* pElemColl, CString id) { IDispatch* pElemDisp = NULL; IHTMLElement* pElem = NULL; VARIANT vID; VARIANT vIdx; VariantInit(&vID); vID.vt=VT_BSTR; vID.bstrVal=_bstr_t(id); VariantInit(&vIdx); vIdx.vt=VT_I4; vIdx.lVal=0; HRESULT hr = pElemColl->item( vID, vIdx, &pElemDisp ); if ( SUCCEEDED(hr) && pElemDisp != 0x0) { hr = pElemDisp->QueryInterface( IID_IHTMLElement, (void**)&pElem ); if ( SUCCEEDED(hr) ) { // Obtained element with ID of "myID". BSTR bsHtml; pElem->get_outerHTML(&bsHtml); CLogFile::WriteLog(bsHtml); ConnectButton1( pElem ); pElem->Release(); } pElemDisp->Release(); } pElemColl->Release(); }
void CHtmlViewNotice::HideScrollBar() { IDispatch *pDisp = GetHtmlDocument(); if( pDisp != NULL ) { IHTMLDocument2* pHTMLDocument2; HRESULT hr; hr = pDisp->QueryInterface(IID_IHTMLDocument2, (void**)&pHTMLDocument2); if( hr == S_OK ) { IHTMLElement *pIElement; hr = pHTMLDocument2->get_body(&pIElement); if( pIElement ) { IHTMLBodyElement *pIBodyElement; hr = pIElement->QueryInterface(IID_IHTMLBodyElement,(void**)&pIBodyElement); pIBodyElement->put_scroll(L"no"); pIBodyElement->Release(); } } pHTMLDocument2->Release(); pDisp->Release(); } }
~GvComEventOutObserverConnection() { #ifdef DOREF if (observer) observer->Release(); if (userData) userData->Release(); #endif };
static wxAutoOleInterface<IHTMLSelectionObject> GetSelObject(IOleObject *oleObject) { // Query for IWebBrowser interface wxAutoOleInterface<IWebBrowser2> wb(IID_IWebBrowser2, oleObject); if (! wb.Ok()) return wxAutoOleInterface<IHTMLSelectionObject>(); IDispatch *iDisp = NULL; HRESULT hr = wb->get_Document(&iDisp); if (hr != S_OK) return wxAutoOleInterface<IHTMLSelectionObject>(); // Query for Document Interface wxAutoOleInterface<IHTMLDocument2> hd(IID_IHTMLDocument2, iDisp); iDisp->Release(); if (! hd.Ok()) return wxAutoOleInterface<IHTMLSelectionObject>(); IHTMLSelectionObject *_so = NULL; hr = hd->get_selection(&_so); // take ownership of selection object wxAutoOleInterface<IHTMLSelectionObject> so(_so); return so; };
// @pymethod |PyIDocHostUIHandler|ShowContextMenu|Description of ShowContextMenu. PyObject *PyIDocHostUIHandler::ShowContextMenu(PyObject *self, PyObject *args) { IDocHostUIHandler *pIDHUIH = GetI(self); if ( pIDHUIH == NULL ) return NULL; // @pyparm int|dwID||Description for dwID POINT pt; // @pyparm (int, int)|pt||Description for ppt // @pyparm <o PyIUnknown>|pcmdtReserved||Description for pcmdtReserved // @pyparm <o PyIDispatch>|pdispReserved||Description for pdispReserved PyObject *obpcmdtReserved; PyObject *obpdispReserved; DWORD dwID; IUnknown * pcmdtReserved; IDispatch * pdispReserved; if ( !PyArg_ParseTuple(args, "l(ii)OO:ShowContextMenu", &dwID, &pt.x, &pt.y, &obpcmdtReserved, &obpdispReserved) ) return NULL; BOOL bPythonIsHappy = TRUE; if (!PyCom_InterfaceFromPyInstanceOrObject(obpcmdtReserved, IID_IUnknown, (void **)&pcmdtReserved, TRUE /* bNoneOK */)) return NULL; if (!PyCom_InterfaceFromPyInstanceOrObject(obpdispReserved, IID_IDispatch, (void **)&pdispReserved, TRUE /* bNoneOK */)) { if (pcmdtReserved) pcmdtReserved->Release(); return NULL; } HRESULT hr; PY_INTERFACE_PRECALL; hr = pIDHUIH->ShowContextMenu( dwID, &pt, pcmdtReserved, pdispReserved ); if (pcmdtReserved) pcmdtReserved->Release(); if (pdispReserved) pdispReserved->Release(); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIDHUIH, IID_IDocHostUIHandler ); return PyInt_FromLong(hr); }
int main(void) { // Initialize COM for this thread... CoInitialize(NULL); // Get CLSID for our server... CLSID clsid; HRESULT hr = CLSIDFromProgID(L"bibleworks.automation", &clsid); if(FAILED(hr)) { ::MessageBox(NULL, "CLSIDFromProgID() failed", "Error", 0x10010); return -1; } // Start server and get IDispatch... IDispatch *pBwApp; hr = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER, IID_IDispatch, (void **)&pBwApp); if(FAILED(hr)) { ::MessageBox(NULL, "Bibleworks not registered properly", "Error", 0x10010); return -2; } // Tell Bibleworks not to quit. By the way, if you tell it TO quit, it behaves // very strangely. // { // VARIANT x; // x.vt = VT_I4; // x.lVal = 0; // set AutoQuit to false = 0 // AutoWrap(DISPATCH_METHOD, NULL, pBwApp, (wchar_t*)L"AutoQuit", 1, x); // } // Go to verse { VARIANT parm; parm.vt = VT_BSTR; // Following is the correct way to do this with a string literal, but we won't be // able to use this method in Bibledit //parm.bstrVal = ::SysAllocString(L"Luke 14:1"); ustring searchstring("Isa 15 1"); // This code doesn't result in a memory error or leak. std::wstring wide_string( searchstring.begin(), searchstring.end() ); parm.bstrVal = ::SysAllocString(wide_string.c_str()); // this allocates memory, which is freed below VARIANT result; VariantInit(&result); AutoWrap(DISPATCH_METHOD, &result, pBwApp, (wchar_t*)L"GoToVerse", 1, parm); VariantClear(&parm); // this will free the memory associated with parm.bstrVal string } // Wait for user... ::MessageBox(NULL, "All done.", "Notice", 0x10000); // Release references... pBwApp->Release(); // Uninitialize COM for this thread... CoUninitialize(); }
void ActiveXBrowserHost::DoDeferredRelease() const { assertMainThread(); IDispatch* deferred; while (m_deferredObjects.try_pop(deferred)) { deferred->Release(); } }
/* * Unload a plugin. */ void CComPlugin::unload() { if (m_plugin) { m_plugin->Release(); m_plugin = NULL; } }
void GetExplorerWindows(std::vector<PairHwndPath>& windows, BOOL needPaths) { IShellWindows *psw; if(SUCCEEDED(CoCreateInstance(CLSID_ShellWindows, NULL, CLSCTX_ALL, IID_IShellWindows, (void**)&psw))) { VARIANT v; V_VT(&v) = VT_I4; IDispatch* pdisp; for(V_I4(&v) = 0; psw->Item(v, &pdisp) == S_OK; V_I4(&v)++) { IWebBrowserApp *pwba; if(SUCCEEDED(pdisp->QueryInterface(IID_IWebBrowserApp, (void**)&pwba))) { PairHwndPath pair; if(SUCCEEDED(pwba->get_HWND((LONG_PTR*)&pair.hwnd))) { IServiceProvider *psp; if(needPaths && SUCCEEDED(pwba->QueryInterface(IID_IServiceProvider, (void**)&psp))) { IShellBrowser *psb; if(SUCCEEDED(psp->QueryService(SID_STopLevelBrowser, IID_IShellBrowser, (void**)&psb))) { IShellView *psv; if(SUCCEEDED(psb->QueryActiveShellView(&psv))) { IFolderView *pfv; if(SUCCEEDED(psv->QueryInterface(IID_IFolderView, (void**)&pfv))) { IPersistFolder2 *ppf2; if(SUCCEEDED(pfv->GetFolder(IID_IPersistFolder2, (void**)&ppf2))) { LPITEMIDLIST pidlFolder; if(SUCCEEDED(ppf2->GetCurFolder(&pidlFolder))) { if(!SHGetPathFromIDList(pidlFolder, pair.path)) { IShellFolder* psf; LPCITEMIDLIST pidlLast; if(SUCCEEDED(SHBindToParent(pidlFolder, IID_IShellFolder, (void**)&psf, &pidlLast))) { STRRET strret; if(SUCCEEDED(psf->GetDisplayNameOf(pidlLast, 0x8000, &strret))) { StrRetToBuf(&strret, pidlLast, pair.path, MAX_PATH); } else { pair.path[0] = 0; } psf->Release(); } } CoTaskMemFree(pidlFolder); } ppf2->Release(); } pfv->Release(); } psv->Release(); } psb->Release(); } psp->Release(); } windows.push_back(pair); } pwba->Release(); } pdisp->Release(); } psw->Release(); } }
//----------------------------------------------------------------------------- // Name: AddHtmlContentToBody // Object: // Parameters : // in : // out : // return : //----------------------------------------------------------------------------- BOOL CHtmlViewer::AddHtmlContentToBody(TCHAR* Content) { HRESULT hr; BOOL bRet; IDispatch* pHtmlDocDispatch = NULL; IHTMLDocument2* pHtmlDoc = NULL; IHTMLElement* pElem = NULL; if (this->pIWebBrowser==NULL) return FALSE; if (!this->IsPageCompleted()) return FALSE; // get IDispatch document interface hr = pIWebBrowser->get_Document(&pHtmlDocDispatch); if (FAILED (hr) || (pHtmlDocDispatch == NULL)) return FALSE; // get IHTMLDocument2 document interface hr = pHtmlDocDispatch->QueryInterface(IID_IHTMLDocument2,(void**)&pHtmlDoc); if (FAILED (hr) || (pHtmlDoc == NULL)) { pHtmlDocDispatch->Release(); return FALSE; } // get body hr = pHtmlDoc->get_body(&pElem); if (FAILED (hr) || (pElem == NULL)) { pHtmlDoc->Release(); pHtmlDocDispatch->Release(); return FALSE; } bRet=this->AddHtmlContentToElement(pElem,Content); pElem->Release(); pHtmlDoc->Release(); pHtmlDocDispatch->Release(); return bRet; }
void IEView::clear() { #ifdef GECKO pWebBrowser->Navigate(L"www.onet.pl", NULL, NULL, NULL, NULL); return; #endif IHTMLDocument2 *document = getDocument(); if (document == NULL) { pWebBrowser->Navigate(L"about:blank", NULL, NULL, NULL, NULL); HRESULT hr = S_OK; IHTMLDocument2 *document = NULL; while ((document == NULL) && (hr == S_OK)) { Sleep(0); IDispatch *dispatch = NULL; if (SUCCEEDED(pWebBrowser->get_Document(&dispatch)) && (dispatch != NULL)) { hr = dispatch->QueryInterface(IID_IHTMLDocument2, (void **)&document); dispatch->Release(); } } if (document != NULL) { document->Release(); } } else { document->close(); VARIANT open_name; VARIANT open_features; VARIANT open_replace; IDispatch *open_window = NULL; VariantInit(&open_name); open_name.vt = VT_BSTR; open_name.bstrVal = SysAllocString(L"_self"); VariantInit(&open_features); VariantInit(&open_replace); HRESULT hr = document->open(SysAllocString(L"text/html"), open_name, open_features, open_replace, &open_window); if (hr == S_OK) { // pWebBrowser->Refresh(); } if (open_window != NULL) { open_window->Release(); } document->Release(); } hDbEventFirst = NULL; if (builder!=NULL) { IEVIEWEVENT event; event.cbSize = sizeof(IEVIEWEVENT); event.hContact = hContact; event.dwFlags = dwLogFlags; event.codepage = iLogCodepage; builder->buildHead(this, &event); } }
IHTMLDocument2 *IEView::getDocument() { HRESULT hr = S_OK; IHTMLDocument2 *document = NULL; IDispatch *dispatch = NULL; if (SUCCEEDED(pWebBrowser->get_Document(&dispatch)) && (dispatch != NULL)) { hr = dispatch->QueryInterface(IID_IHTMLDocument2, (void **)&document); dispatch->Release(); } return document; }
static cgMSXML::IXMLElement* XML_GetNextElement(cgMSXML::IXMLElementCollection* pChildren, long* pNum) { bool bOk; long typeId; VARIANT var1; VARIANT var2; IDispatch* pDisp; long length; cgMSXML::IXMLElement* pChild; pChildren->get_length(&length); var1.vt = VT_I4; var2.vt = VT_EMPTY; var1.lVal= *pNum; nextChild: if(var1.lVal>= length) return NULL; if(FAILED(pChildren->item(var1, var2, &pDisp)) || !pDisp) { assert(!"pChildren->item failed"); return NULL; } bOk = SUCCEEDED(pDisp->QueryInterface(cgMSXML::IID_IXMLElement, (void **)&pChild)); pDisp->Release(); if(!bOk) { assert(!"pDisp->QueryInterface failed"); return NULL; } if(FAILED(pChild->get_type(&typeId))) { assert(!"pChild->get_type failed"); pChild->Release(); return NULL; } if(typeId!=cgMSXML::XMLELEMTYPE_ELEMENT || XML_GetFlag(pChild, XML_TAGS.ATTR_COMMENT)) { pChild->Release(); var1.lVal++; goto nextChild; } *pNum = ++var1.lVal; return pChild; }
// 清空日志 void CLog::Clear() { if (m_logDocument.p == NULL) return; IDispatch* tmp; m_logDocument->open(_T("about:blank"), variant_t(), variant_t(), variant_t(), &tmp); tmp->Release(); WriteDocument(LOG_FRAME); GetSystemTime(&m_logStartTime); }
void HostTimerDispatcher::kill(unsigned timerID) { timeKillEvent(timerID); if (m_timerDispatchMap.exists(timerID)) { IDispatch* pDisp = m_timerDispatchMap[timerID]; if (pDisp) pDisp->Release(); m_timerDispatchMap.remove(timerID); } }
void HostTimerDispatcher::reset() { for (auto iter = m_timerDispatchMap.first(); iter.is_valid(); iter++) { timeKillEvent(iter->m_key); IDispatch* pDisp = iter->m_value; if (pDisp) pDisp->Release(); } m_timerDispatchMap.remove_all(); }
void CIncrementSystemBFDlg::OnDocumentCompleteExplorer1(LPDISPATCH pDisp, VARIANT FAR* URL) { DocumentCompleteExplorerSelectItem(pDisp, URL); // TODO: Add your control notification handler code here IDispatch * pDocDisp = NULL; // get the DOM IHTMLDocument2 *pDoc=NULL; pDocDisp = m_MyIE.GetDocument(); if (pDocDisp != NULL) { // Obtained the document object by specifying the IHTMLDocument2 Interface. HRESULT hr= pDocDisp->QueryInterface( IID_IHTMLDocument2, (void**)&pDoc ); IHTMLElement* pBody = NULL; BSTR bstrBody; pDoc->get_body(&pBody); pBody->get_innerHTML(&bstrBody); if ( SUCCEEDED(hr) ) { // Obtained the IHTMLDocument2 interface for the document object IHTMLElementCollection* pElemColl = NULL; hr = pDoc->get_all( &pElemColl ); if ( SUCCEEDED(hr) )//ec { CComDispatchDriver spScript; pDoc->get_Script(&spScript); CComVariant var(static_cast<IDispatch*>(new CMyEventSink)); //spScript.Invoke1(L"SaveCppObject", &var); // Obtained element collection. /* #define LOGON_HTML_ID _T("Logon") #define HTTP1_HTML_ID _T("Http1") #define AUTH_HTML_ID _T("Authentication") #define QUERYPT_HTML_ID _T("QueryPhoneType") #define QUERYPOP_HTML_ID _T("QueryPopup") #define QUERYPHONE_HTML_ID _T("QueryPhone") #define HB_HTML_ID _T("Heartbeat") #define RESETPWD_HTML_ID _T("ResetPassword") #define LOGOFF_HTML_ID _T("Logoff") */ // buttonChangePassword querySerialNumber ProcessElementCollection( pElemColl, "querySerialNumber"); } } //ProcessDocument( pDocDisp ); } pDocDisp->Release(); }
//taken from http://www.wischik.com/lu/programmer/webform.html IHTMLElement* TextRenderBrain::GetElementFromId(string id_str, const GUID *iid) { const char* id = NULL; IHTMLElement *ret=0; IHTMLElementCollection* doc_all = NULL; IHTMLDocument2 *doc = NULL; HRESULT hr; if (id_str.size() == 0) return 0; id = id_str.c_str(); doc = GetDoc(); if (doc==0) return 0; hr = doc->get_all(&doc_all); // this is like doing document.all if (hr == S_OK) { IDispatch* disp = NULL; VARIANT vid; VARIANT v0; unsigned int len; wchar_t* ws = NULL; VariantInit(&v0); len=strlen(id); vid.vt=VT_BSTR; ws = new wchar_t[len+1]; MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED, id, -1, ws, len+1); vid.bstrVal=ws; hr = doc_all->item(vid,v0,&disp); // this is like doing document.all["messages"] delete[] ws; //We may be leaking a small amount of memory here because this crashes: //SysFreeString(vid.bstrVal); if (hr == S_OK && disp != 0) { IHTMLElement* element = NULL; if (iid == 0) hr = disp->QueryInterface(IID_IHTMLElement,(void **)&element); else hr = disp->QueryInterface(*iid,(void**)&element); if (hr == S_OK) ret = element; // it's the caller's responsibility to release it disp->Release(); } doc_all->Release(); } doc->Release(); return ret; }
void IEView::clear(IEVIEWEVENT *event) { #ifdef GECKO // pWebBrowser->Navigate(L"www.onet.pl", NULL, NULL, NULL, NULL); // return; #endif IHTMLDocument2 *document = getDocument(); if (document == NULL) { pWebBrowser->Navigate(L"about:blank", NULL, NULL, NULL, NULL); HRESULT hr = S_OK; IHTMLDocument2 *document = NULL; while ((document == NULL) && (hr == S_OK)) { Sleep(0); IDispatch *dispatch = NULL; if (SUCCEEDED(pWebBrowser->get_Document(&dispatch)) && (dispatch != NULL)) { hr = dispatch->QueryInterface(IID_IHTMLDocument2, (void **)&document); dispatch->Release(); } } if (document != NULL) { document->Release(); } } else { document->close(); VARIANT open_name; VARIANT open_features; VARIANT open_replace; IDispatch *open_window = NULL; VariantInit(&open_name); open_name.vt = VT_BSTR; open_name.bstrVal = SysAllocString(L"_self"); VariantInit(&open_features); VariantInit(&open_replace); HRESULT hr = document->open(SysAllocString(L"text/html"), open_name, open_features, open_replace, &open_window); if (hr == S_OK) { // pWebBrowser->Refresh(); } if (open_window != NULL) { open_window->Release(); } document->Release(); } if (builder!=NULL) { builder->clear(this, event); } clearRequired = false; getFocus = false; }
//taken and modified slightly from http://www.wischik.com/lu/programmer/webform.html IHTMLDocument2* TextRenderBrain::GetDoc() { IDispatch *dispatch = NULL; dispatch = MainWndParts::Instance()->mpHtmlView->GetHtmlDocument(); IHTMLDocument2 *doc = NULL; if (dispatch) { dispatch->QueryInterface(IID_IHTMLDocument2,(void**)&doc); dispatch->Release(); } return doc; }
HRESULT AccessibleObject::BuildChildren(std::vector<AccessibleChild>& children, IAccessible* acc, LPARAM param) { if (acc == nullptr) acc = acc_; if (acc == nullptr) return E_INVALIDARG; long child_count = 0; HRESULT hr = acc->get_accChildCount(&child_count); if (FAILED(hr)) return hr; if (child_count == 0) return S_FALSE; long obtained_count = 0; std::vector<VARIANT> var_array(child_count); hr = AccessibleChildren(acc, 0L, child_count, var_array.data(), &obtained_count); if (FAILED(hr)) return hr; children.resize(obtained_count); for (int i = 0; i < obtained_count; i++) { VARIANT var_child = var_array[i]; if (var_child.vt == VT_DISPATCH) { IDispatch* dispatch = var_child.pdispVal; IAccessible* child = nullptr; hr = dispatch->QueryInterface(IID_IAccessible, (void**)&child); if (hr == S_OK) { GetName(children.at(i).name, CHILDID_SELF, child); GetRole(children.at(i).role, CHILDID_SELF, child); GetValue(children.at(i).value, CHILDID_SELF, child); if (AllowChildTraverse(children.at(i), param)) BuildChildren(children.at(i).children, child, param); child->Release(); } dispatch->Release(); } else { GetName(children.at(i).name, var_child.lVal, acc); GetRole(children.at(i).role, var_child.lVal, acc); GetValue(children.at(i).value, var_child.lVal, acc); } } return S_OK; }
QT_BEGIN_NAMESPACE QAxBase *qax_create_object_wrapper(QObject *object) { IDispatch *dispatch = 0; QAxObject *wrapper = 0; qAxFactory()->createObjectWrapper(object, &dispatch); if (dispatch) { wrapper = new QAxObject(dispatch, object); wrapper->setObjectName(object->objectName()); dispatch->Release(); } return wrapper; }