本文整理汇总了C++中IDispatch::QueryInterface方法的典型用法代码示例。如果您正苦于以下问题:C++ IDispatch::QueryInterface方法的具体用法?C++ IDispatch::QueryInterface怎么用?C++ IDispatch::QueryInterface使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDispatch
的用法示例。
在下文中一共展示了IDispatch::QueryInterface方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MyShellDispatch_ShellDispatchProc
static int MyShellDispatch_ShellDispatchProc(const shell_dispatch_handler_t handler, void *const data)
{
int iSuccess = SHELL_DISPATCH_FAILED;
IShellWindows *psw = NULL;
HRESULT hr = CoCreateInstance(CLSID_ShellWindows, NULL, CLSCTX_LOCAL_SERVER, IID_PPV_ARGS(&psw));
if(SUCCEEDED(hr))
{
HWND desktopHwnd = 0;
IDispatch* pdisp = NULL;
variant_t vEmpty;
if(S_OK == psw->FindWindowSW(vEmpty, vEmpty, SWC_DESKTOP, (long*)&desktopHwnd, SWFO_NEEDDISPATCH, &pdisp))
{
if(VALID_HANDLE(desktopHwnd))
{
IShellBrowser *psb;
hr = IUnknown_QueryService(pdisp, SID_STopLevelBrowser, IID_PPV_ARGS(&psb));
if(SUCCEEDED(hr))
{
IShellView *psv = NULL;
hr = psb->QueryActiveShellView(&psv);
if(SUCCEEDED(hr))
{
IDispatch *pdispBackground = NULL;
HRESULT hr = psv->GetItemObject(SVGIO_BACKGROUND, IID_PPV_ARGS(&pdispBackground));
if(SUCCEEDED(hr))
{
MyShellDispatch_AllowSetForegroundWindow(desktopHwnd);
IShellFolderViewDual *psfvd = NULL;
HRESULT hr = pdispBackground->QueryInterface(IID_PPV_ARGS(&psfvd));
if(SUCCEEDED(hr))
{
IDispatch *pdisp = NULL;
hr = psfvd->get_Application(&pdisp);
if(SUCCEEDED(hr))
{
IShellDispatch2 *pShellDispatch;
hr = pdisp->QueryInterface(IID_PPV_ARGS(&pShellDispatch));
if(SUCCEEDED(hr))
{
iSuccess = handler(pShellDispatch, data);
}
RELEASE_OBJ(pdisp);
}
RELEASE_OBJ(psfvd);
}
RELEASE_OBJ(pdispBackground);
}
RELEASE_OBJ(psv);
}
RELEASE_OBJ(psb);
}
}
RELEASE_OBJ(pdisp);
}
RELEASE_OBJ(psw);
}
return iSuccess;
}
示例2: GetShellDispatchFromView
static HRESULT GetShellDispatchFromView(
__in IShellView *psv,
__in REFIID riid,
__out void **ppv
)
{
HRESULT hr = S_OK;
IDispatch *pdispBackground = NULL;
IShellFolderViewDual *psfvd = NULL;
IDispatch *pdisp = NULL;
// From a shell view object, gets its automation interface and from that get the shell
// application object that implements IShellDispatch2 and related interfaces.
hr = psv->GetItemObject(SVGIO_BACKGROUND, IID_PPV_ARGS(&pdispBackground));
ExitOnFailure(hr, "Failed to get the automation interface for shell.");
hr = pdispBackground->QueryInterface(IID_PPV_ARGS(&psfvd));
ExitOnFailure(hr, "Failed to get shell folder view dual.");
hr = psfvd->get_Application(&pdisp);
ExitOnFailure(hr, "Failed to application object.");
hr = pdisp->QueryInterface(riid, ppv);
ExitOnFailure(hr, "Failed to get IShellDispatch2.");
LExit:
ReleaseObject(pdisp);
ReleaseObject(psfvd);
ReleaseObject(pdispBackground);
return hr;
}
示例3: GetShellDispatchFromView
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;
}
示例4: GetElementFromId
//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;
}
示例5: RunMessageLoop
void CIEBrowserEngine::RunMessageLoop(CMainWindow& mainWnd)
{
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
if (RHODESAPP().getExtManager().onWndMsg(msg) )
continue;
IDispatch* pDisp;
SendMessage(m_hwndTabHTML, DTM_BROWSERDISPATCH, 0, (LPARAM) &pDisp); // New HTMLVIEW message
if (pDisp != NULL) {
// If the Key is back we do not want to translate it causing the browser
// to navigate back.
if ( ((msg.message != WM_KEYUP) && (msg.message != WM_KEYDOWN)) || (msg.wParam != VK_BACK) )
{
IOleInPlaceActiveObject* pInPlaceObject;
pDisp->QueryInterface( IID_IOleInPlaceActiveObject, (void**)&pInPlaceObject );
HRESULT handleKey = pInPlaceObject->TranslateAccelerator(&msg);
}
}
if (!mainWnd.TranslateAccelerator(&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if(msg.message == WM_PAINT)
RHODESAPP().getExtManager().onHTMLWndMsg(msg);
}
}
示例6:
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;
}
示例7: GetElementById
HRESULT GetElementById(IHTMLDocument2 *pDoc, CString szId, IHTMLElement** pElem)
{
*pElem = NULL;
HRESULT hr = S_OK;
BSTR bstrID = szId.AllocSysString();
VARIANT varName, varIndex;
varName.vt = VT_BSTR;
varName.bstrVal = bstrID;
varIndex.vt = VT_I4;
varIndex.intVal = 0;
IHTMLElementCollection *pColl;
hr = pDoc->get_all(&pColl);
if (hr == S_OK && pColl)
{
IDispatch* pDisp;
hr = pColl->item(varName, varIndex, &pDisp);
if (hr == S_OK && pDisp)
{
hr = pDisp->QueryInterface(IID_IHTMLElement, (void**)pElem);
}
}
::SysFreeString(bstrID);
return hr;
}
示例8: LoadWebBrowserFromStream
HRESULT LoadWebBrowserFromStream(IWebBrowser* pWebBrowser, IStream* pStream)
{
HRESULT hr;
IDispatch* pHtmlDoc = NULL;
IPersistStreamInit* pPersistStreamInit = NULL;
// Retrieve the document object.
hr = pWebBrowser->get_Document( &pHtmlDoc );
if ( SUCCEEDED(hr) )
{
// Query for IPersistStreamInit.
hr = pHtmlDoc->QueryInterface( IID_IPersistStreamInit, (void**)&pPersistStreamInit );
if ( SUCCEEDED(hr) )
{
// Initialize the document.
hr = pPersistStreamInit->InitNew();
if ( SUCCEEDED(hr) )
{
// Load the contents of the stream.
hr = pPersistStreamInit->Load( pStream );
}
pPersistStreamInit->Release();
}
}
return S_OK;
}
示例9: HideScrollBar
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();
}
}
示例10: ProcessElementCollection
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();
}
示例11: GetExplorerWindows
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();
}
}
示例12: AddHtmlContentToElement
//-----------------------------------------------------------------------------
// 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;
}
示例13: clear
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);
}
}
示例14: GetGC
HRESULT GetGC(IDirectorySearch **ppDS)
{
HRESULT hr;
IEnumVARIANT *pEnum = NULL;
IADsContainer *pCont = NULL;
VARIANT var;
IDispatch *pDisp = NULL;
ULONG lFetch;
// Set IDirectorySearch pointer to NULL.
*ppDS = NULL;
// First, bind to the GC: namespace container object.
hr = ADsOpenObject(TEXT("GC:"),
NULL,
NULL,
ADS_SECURE_AUTHENTICATION, // Use Secure Authentication.
IID_IADsContainer,
(void**)&pCont);
if (FAILED(hr)) {
_tprintf(TEXT("ADsOpenObject failed: 0x%x\n"), hr);
goto cleanup;
}
// Get an enumeration interface for the GC container to enumerate the
// contents. The actual GC is the only child of the GC container.
hr = ADsBuildEnumerator(pCont, &pEnum);
if (FAILED(hr)) {
_tprintf(TEXT("ADsBuildEnumerator failed: 0x%x\n"), hr);
goto cleanup;
}
// Now enumerate. There is only one child of the GC: object.
hr = pEnum->Next(1, &var, &lFetch);
if (FAILED(hr)) {
_tprintf(TEXT("ADsEnumerateNext failed: 0x%x\n"), hr);
goto cleanup;
}
// Get the IDirectorySearch pointer.
if ((hr == S_OK) && (lFetch == 1))
{
pDisp = V_DISPATCH(&var);
hr = pDisp->QueryInterface(IID_IDirectorySearch, (void**)ppDS);
}
cleanup:
if (pEnum)
ADsFreeEnumerator(pEnum);
if (pCont)
pCont->Release();
if (pDisp)
(pDisp)->Release();
return hr;
}
示例15:
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;
}