本文整理汇总了C++中IDispatchPtr::QueryInterface方法的典型用法代码示例。如果您正苦于以下问题:C++ IDispatchPtr::QueryInterface方法的具体用法?C++ IDispatchPtr::QueryInterface怎么用?C++ IDispatchPtr::QueryInterface使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDispatchPtr
的用法示例。
在下文中一共展示了IDispatchPtr::QueryInterface方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateCOMObject
HRESULT GenericCLRLoader::CreateCOMObject(const ATL::CString& sAssemblyFile, const ATL::CString& sAssemblyName, const ATL::CString& sTypeName,
IUnknown** ppIUnk, const ATL::CString& sConfigFile , const ATL::CString& sDomainName , int LocaleID )
{
mscorlib::_ObjectHandlePtr spObjectHandle;
HRESULT hr = GenericCLRLoader::TheInstance()->CreateObject(sAssemblyFile, sAssemblyName, sTypeName, &spObjectHandle, sConfigFile, sDomainName, LocaleID);
if (SUCCEEDED(hr) && (spObjectHandle != NULL))
{
CComVariant vUnwrapped;
spObjectHandle->Unwrap(&vUnwrapped);
if(vUnwrapped.vt == VT_DISPATCH)
{
IDispatchPtr pDisp = vUnwrapped.pdispVal;
return pDisp->QueryInterface(IID_IUnknown, (void**)ppIUnk);
}
if (vUnwrapped.vt == VT_UNKNOWN)
{
*ppIUnk = vUnwrapped.punkVal;
(*ppIUnk)->AddRef();
return S_OK;
}
return E_NOINTERFACE;
}
if (SUCCEEDED(hr) && spObjectHandle == NULL)
return E_POINTER;
return hr;
}
示例2: GetWindowDocument
HRESULT vmsDomHelper::GetWindowDocument(IHTMLWindow2* pWnd, IHTMLDocument2** ppDoc)
{
assert (pWnd != NULL && ppDoc != NULL);
if (!ppDoc)
return E_INVALIDARG;
*ppDoc = NULL;
if (!pWnd)
return E_INVALIDARG;
HRESULT hr = pWnd->get_document (ppDoc);
if (*ppDoc)
return hr;
IWebBrowser2Ptr spWB;
GetWebBrowser (pWnd, &spWB);
if (spWB != NULL)
{
IDispatchPtr spdDoc;
spWB->get_Document (&spdDoc);
if (spdDoc != NULL)
{
spdDoc->QueryInterface (IID_IHTMLDocument2, (void**)ppDoc);
if (*ppDoc)
hr = S_OK;
}
}
return hr;
}
示例3: SetCustomDocUIHandler
HRESULT WebBrowserEventSinker::SetCustomDocUIHandler(LPDISPATCH lpDisp)
{
if(lpDisp == NULL)
return E_INVALIDARG;
IWebBrowser2Ptr pWebBrowser2;
HRESULT hr = lpDisp->QueryInterface(IID_IWebBrowser2, (void**)&pWebBrowser2);
if(SUCCEEDED(hr) && pWebBrowser2)
{
IDispatchPtr pDoc;
hr = pWebBrowser2->get_Document(&pDoc);
if(SUCCEEDED(hr) && pDoc)
{
ICustomDocPtr pCustDoc;
hr = pDoc->QueryInterface(IID_ICustomDoc, (void**)&pCustDoc);
if(SUCCEEDED(hr) && pCustDoc != NULL)
{
IDocHostUIHandler* pUIHandler;
CreateObjectInterface<CDocHostUIHandler, IDocHostUIHandler>(NULL, &pUIHandler);
if (pUIHandler)
pCustDoc->SetUIHandler(pUIHandler);
pUIHandler->Release();
}
}
}
return hr;
}
示例4:
STDMETHODIMP_(void) CPdnWnd::NavigateComplete2(IDispatch *pDisp, VARIANT *URL)
{
IDispatchPtr pDocDisp;
ICustomDoc* pCustomDoc;
m_pBrowser->get_Document(&pDocDisp);
pDocDisp->QueryInterface(IID_ICustomDoc, (LPVOID*) &pCustomDoc);
HRESULT hr =
pCustomDoc->SetUIHandler(dynamic_cast<IDocHostUIHandler*>(this));
pCustomDoc->Release();
}
示例5: OnBnClickedTest
void CNetRadioDlg::OnBnClickedTest()
{
CString strValue;
IHTMLDocument2* pDoc = (IHTMLDocument2*)m_Browser.GetHtmlDocument();
HRESULT hr = S_FALSE;
IHTMLElementCollection* pAllElem = NULL;
IHTMLElementCollection* pAllScript = NULL;
IHTMLElement* pElem = NULL;
hr = pDoc->get_scripts(&pAllScript);
if(SUCCEEDED(hr) && pAllScript != NULL)
{
IDispatchPtr pElemDisp = NULL;
_variant_t varID(1);
_variant_t varIdx(0);
hr = pAllScript->item(varID, varIdx, &pElemDisp);
if(SUCCEEDED(hr) && pElemDisp != NULL)
{
hr = pElemDisp->QueryInterface(IID_IHTMLElement,(void**)&pElem);
if(SUCCEEDED(hr) && pElem != NULL)
{
BSTR bstrTagName;
hr = pElem->get_outerHTML(&bstrTagName);
hr = pElem->get_outerHTML(&bstrTagName);
if(SUCCEEDED(hr))
{
CString strTagName(bstrTagName);
SysFreeString(bstrTagName);
MessageBox(strTagName);
}
}
}
}
hr = pDoc->get_all(&pAllElem);
if(SUCCEEDED(hr) && pAllElem != NULL)
{
IDispatchPtr pElemDisp = NULL;
_variant_t varID(_T("body"));
_variant_t varIdx(0);
hr = pAllElem->item(varID, varIdx, &pElemDisp);
if(SUCCEEDED(hr) && pElemDisp != NULL)
{
MessageBox(_T("OK"));
}
}
}
示例6: GetUser
CardVideoObjects::_UserPtr CCardVideoSystem::GetUser(LPCTSTR strCardNumber)
{
ASSERT(0 != m_pSystem);
CardVideoObjects::_UserPtr pUser;
IDispatchPtr pDispatch;
pDispatch = m_pSystem->GetUserByCardNumber(_bstr_t(strCardNumber));
if (pDispatch)
{
pDispatch.QueryInterface(CardVideoObjects::IID__User,&pUser);
pDispatch.Release();
if (0 != pUser)
{
return pUser;
}
}
return (CardVideoObjects::_UserPtr)0;
}
示例7: GetParentDocument
HRESULT vmsDomHelper::GetParentDocument(IHTMLDocument2 *pDoc, IHTMLDocument2 **ppParentDoc)
{
*ppParentDoc = NULL;
ATLASSERT (pDoc != NULL);
if (!pDoc)
return E_INVALIDARG;
IHTMLWindow2Ptr spWnd;
HRESULT hr = pDoc->get_parentWindow (&spWnd);
if (FAILED (hr))
return hr;
IHTMLWindow2Ptr spWndParent;
hr = spWnd->get_parent (&spWndParent);
if (FAILED (hr))
return hr;
hr = spWndParent->get_document (ppParentDoc);
if (hr == E_ACCESSDENIED)
{
IWebBrowser2Ptr spWB;
hr = GetWebBrowser (spWndParent, &spWB);
if (FAILED (hr))
return E_ACCESSDENIED;
IDispatchPtr spdDoc;
hr = spWB->get_Document (&spdDoc);
if (FAILED (hr))
return hr;
hr = spdDoc->QueryInterface (IID_IHTMLDocument2, (void**)ppParentDoc);
}
if (FAILED (hr))
return hr;
IUnknownPtr spUnk1 (pDoc);
IUnknownPtr spUnk2 (*ppParentDoc);
if (pDoc == *ppParentDoc || spUnk1 == spUnk2)
{
(*ppParentDoc)->Release ();
*ppParentDoc = NULL;
}
return S_OK;
}
示例8: RunMatlab
_bstr_t RunMatlab( char* strMFile )
{
CoInitialize(NULL);
_bstr_t ret;
//ensure the smarter pointer is destroyed before CoUninitialize
{
IDispatchPtr spDisp;
spDisp.CreateInstance( "Matlab.Application.Single" );
DIMLAppPtr spMatlabApp;
spDisp.QueryInterface( __uuidof(spDisp), &spMatlabApp );
spDisp = NULL;
spMatlabApp->Execute( _bstr_t("rand(seed, 999)") );
ret = spMatlabApp->Execute( _bstr_t(strMFile) );
}
CoUninitialize();
return ret;
}
示例9: CheckVersionUpdate
BOOL CAutoUpdateDlg::CheckVersionUpdate(CString& strUpdateURL)
{
BOOL bHasUpdate = FALSE;
HRESULT hr = S_OK;
IXMLHTTPRequestPtr pHttpRequest;
IDispatchPtr pDispatch;
MSXML2::IXMLDOMDocumentPtr pXmlDoc;
MSXML2::IXMLDOMNodeListPtr pList;
MSXML2::IXMLDOMElementPtr pChild;
UINT nFileSize;
CString strFileName, strFileVer, strMD5String;
LONG lElementCount = 0L;
try
{
hr = pHttpRequest.CreateInstance(TEXT("Msxml2.XMLHTTP.3.0"));
if( FAILED(hr) )
_com_issue_error(hr);
hr = pHttpRequest->open(TEXT("GET"), (_bstr_t)strUpdateURL, false);
if( FAILED(hr) )
_com_issue_error(hr);
hr = pHttpRequest->send();
if( FAILED(hr) )
_com_issue_error(hr);
if (pHttpRequest->Getstatus() != 200)
throw (0);
pDispatch = pHttpRequest->GetresponseXML();
hr = pDispatch->QueryInterface(pXmlDoc.GetIID(), (void**)&pXmlDoc);
if( FAILED(hr) )
_com_issue_error(hr);
pList = pXmlDoc->selectNodes("/manifest/filelist/file");
lElementCount = pList->Getlength();
for( LONG i = 0; i < lElementCount; i++ )
{
pChild = pList->Getitem(i);
strFileName = pChild->getAttribute("filename");
nFileSize = pChild->getAttribute("filesize");
strFileVer = pChild->getAttribute("fileversion");
strMD5String = pChild->getAttribute("md5");
//如果本地文件存在则效验文件,不存在就下载这个文件
if (PathFileExists(m_strCurrentDir+strFileName))
{
//效验文件,如果MD5码不相同则重新下载
if (CMD5Checksum::GetMD5(m_strCurrentDir+strFileName) != strMD5String)
{
m_ulTotalLength += nFileSize;
m_DownloadMgr.AddTask(strFileName);
bHasUpdate = TRUE;
}
}
else
{
m_ulTotalLength += nFileSize;
m_DownloadMgr.AddTask(strFileName);
bHasUpdate = TRUE;
}
}
return bHasUpdate;
}
#ifdef _DEBUG
catch(_com_error& e)
{
CString strError;
strError.Format(_T("Error code:%d\nMessage:%s\nDescrption:%s"), (int)e.WCode(), e.ErrorMessage(), (TCHAR*)e.Description());
MessageBox(strError, _T("提示"), MB_OK|MB_ICONWARNING);
return FALSE;
}
#endif
catch(...)
{
return FALSE;
}
}
示例10: Invoke
STDMETHODIMP COutlookButton::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
{
if (IID_NULL != riid)
return DISP_E_UNKNOWNINTERFACE;
// The only dispID supported is 1, which triggers when the "button" is clicked
if (dispIdMember != 0x00000001)
return DISP_E_MEMBERNOTFOUND;
if (NULL == pDispParams)
return E_POINTER;
if (pDispParams->cArgs != 2)
return DISP_E_BADPARAMCOUNT;
/*CMAPIEx mapi;
if(!CMAPIEx::Init() || !mapi.Login("Outlook") || !mapi.OpenMessageStore("")) {
MessageBox(NULL, "Failed to initialize MAPI", "Error", MB_OK);
return S_OK;
}
MessageBox(NULL, mapi.GetProfileName(), "Test", MB_OK);*/
// you can use this profile name as an argument for Login() when no MAPI provider is open (ie Outlook)
//printf("Profile Name: %s\n",mapi.GetProfileName());
try {
if( pDispParams->rgvarg[1].vt == VT_DISPATCH )
{
//OutlookSecurity::SecurityManager
//OutlookSecurity::SecurityManager sec;
Outlook::_ExplorerPtr spExplorer = m_OLAppPtr->ActiveExplorer();
_ContactItemPtr pContactItem = NULL;
CString fullName="";
if (spExplorer!=NULL) {
Outlook::_NameSpacePtr nameSpace = m_OLAppPtr->GetNamespace("MAPI");
Outlook::MAPIFolderPtr currFolder = spExplorer->CurrentFolder;
HRESULT hr;
enum Outlook::OlItemType olt;
hr = currFolder->get_DefaultItemType(&olt);
if (!FAILED(hr)) {
if (olt==(Outlook::OlItemType)2) {
IDispatchPtr pContact = GetSelectedItem(spExplorer);
if (pContact!=NULL) {
pContactItem = (Outlook::_ContactItemPtr)pContact;
fullName = (LPCTSTR)pContactItem->GetFullName();
}
} else if (olt==(Outlook::OlItemType)0) {
Outlook::MAPIFolderPtr pParentFolder = (Outlook::MAPIFolderPtr)currFolder->GetParent();
if (pParentFolder!=NULL) {
IDispatchPtr pSelectedItem = GetSelectedItem(spExplorer);
Outlook::_MailItemPtr pMailItem;
//Outlook::_ContactItemPtr pContactItem;
Outlook::MAPIFolderPtr pTemp, pTemp2;
BOOL itemType = 0; // 0-other, 1-mail, 2-contact
if (pSelectedItem!=NULL) {
HRESULT hr = pSelectedItem->QueryInterface(&pMailItem);
if (FAILED(hr)) {
hr = pSelectedItem->QueryInterface(&pContactItem);
if (!FAILED(hr))
itemType = 2;
} else {
itemType = 1;
}
if (itemType==1) { //mail item
if ((pTemp=pParentFolder->GetParent())==NULL) {
pParentFolder = currFolder;
} else {
while (1) {
pTemp=(Outlook::MAPIFolderPtr)pParentFolder->GetParent();
if ((pTemp2=pTemp->GetParent())!=NULL)
pParentFolder=pTemp;
else
break;
}
}
if ((pParentFolder->GetName()==nameSpace->GetDefaultFolder(Outlook::olFolderOutbox)->GetName()) ||
(pParentFolder->GetName()==nameSpace->GetDefaultFolder(Outlook::olFolderSentMail)->GetName()) ||
(pParentFolder->GetName()==nameSpace->GetDefaultFolder(Outlook::olFolderDrafts)->GetName())) {
fullName = (LPCTSTR)pMailItem->GetTo();
} else if (pParentFolder->GetName()==nameSpace->GetDefaultFolder(Outlook::olFolderInbox)->GetName()) {
fullName = (LPCTSTR)pMailItem->GetSenderName();
} else {
fullName = (LPCTSTR)pMailItem->GetSenderName();
/*fullName += "#####";
fullName += (LPCTSTR)pMailItem->GetTo();*/
}
pContactItem = FindContact(CString(CString("[FullName] = '") + fullName + "'").AllocSysString());
} else if (itemType==2) { //contact item
//.........这里部分代码省略.........
示例11: FindUsingTitle
bool CMyInternetExplorer::FindUsingTitle (const CString & sTitleToSearch)
{
if (m_pWebBrowser != NULL)
{
m_pWebBrowser->Release ();
m_pWebBrowser = NULL;
}
HRESULT hr;
SHDocVw::IShellWindowsPtr spSHWinds;
hr = spSHWinds.CreateInstance (__uuidof(SHDocVw::ShellWindows));
if (FAILED (hr))
return false;
ASSERT (spSHWinds != NULL);
long nCount = spSHWinds->GetCount ();
IDispatchPtr spDisp;
for (long i = 0; i < nCount; i++)
{
_variant_t va (i, VT_I4);
spDisp = spSHWinds->Item (va);
IWebBrowser2 * pWebBrowser = NULL;
hr = spDisp.QueryInterface (IID_IWebBrowser2, & pWebBrowser);
if (pWebBrowser != NULL)
{
HRESULT hr;
IDispatch* pHtmlDocDispatch = NULL;
IHTMLDocument2 * pHtmlDoc = NULL;
// Retrieve the document object.
hr = pWebBrowser->get_Document (&pHtmlDocDispatch);
if (SUCCEEDED (hr) && (pHtmlDocDispatch != NULL))
{
// Query for IPersistStreamInit.
hr = pHtmlDocDispatch->QueryInterface (IID_IHTMLDocument2, (void**)&pHtmlDoc);
if (SUCCEEDED (hr) && (pHtmlDoc != NULL))
{
CString sTitle;
HWND hWnd = NULL;
pWebBrowser->get_HWND ((long*)(&hWnd));
if (::IsWindow (hWnd))
{
int nLen = ::GetWindowTextLength (hWnd);
::GetWindowText (hWnd, sTitle.GetBufferSetLength (nLen), nLen + 1);
sTitle.ReleaseBuffer ();
}
// If I cannot get the window title (should never happen though)
// So, lets just use the title of the document
if (sTitle.IsEmpty ())
{
BSTR bstrTitle;
hr = pHtmlDoc->get_title (&bstrTitle);
if (!FAILED (hr))
{
sTitle = bstrTitle;
SysFreeString (bstrTitle);
}
}
if (StringHelper::WildcardCompareNoCase (sTitleToSearch, sTitle))
{
m_pWebBrowser = pWebBrowser;
pHtmlDoc->Release ();
pHtmlDocDispatch->Release ();
// Exit the method safely!
return true;
}
pHtmlDoc->Release();
}
pHtmlDocDispatch->Release ();
}
pWebBrowser->Release ();
}
}
return false;
}