Beispiel #1
0
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;
}
Beispiel #2
0
HRESULT TestMarkupServices(BSTR bstrHtml, MarkupCallback *pCallback, BSTR &message)
{
	IHTMLDocument3 *pHtmlDocRoot = NULL;

	// Create the root document -- a "workspace" for parsing.
	HRESULT hr = CoCreateInstance(CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pHtmlDocRoot));
	if (SUCCEEDED(hr) && pHtmlDocRoot) {
		IPersistStreamInit *pPersistStreamInit = NULL;

		hr = pHtmlDocRoot->QueryInterface(IID_PPV_ARGS(&pPersistStreamInit));
		if (SUCCEEDED(hr)) {
			// Initialize the root document to a default state -- ready for parsing.
			pPersistStreamInit->InitNew();

			IMarkupServices *pMarkupServices = NULL;
			hr = pHtmlDocRoot->QueryInterface(IID_PPV_ARGS(&pMarkupServices));
			if (SUCCEEDED(hr)) {
				IMarkupPointer *pMarkupBegin = NULL;
				IMarkupPointer *pMarkupEnd = NULL;

				// These markup pointers indicate the insertion point.
				hr = pMarkupServices->CreateMarkupPointer(&pMarkupBegin);
				if (SUCCEEDED(hr))
					hr = pMarkupServices->CreateMarkupPointer(&pMarkupEnd);

				if (SUCCEEDED(hr) && pMarkupBegin && pMarkupEnd) {
					IMarkupContainer *pMarkupContainer = NULL;

					// Parse the string -- the markup container contains the parsed HTML.
					// Markup pointers are updated to point to begining and end of new container.
					hr = pMarkupServices->ParseString(bstrHtml, 0, &pMarkupContainer, pMarkupBegin, pMarkupEnd);
					if (SUCCEEDED(hr) && pMarkupContainer) {
						IHTMLDocument3 *pHtmlDoc = NULL;

						// Retrieve the document interface to the markup container.
						hr = pMarkupContainer->QueryInterface(IID_PPV_ARGS(&pHtmlDoc));
						if (SUCCEEDED(hr) && pHtmlDoc) {
							// Invoke the user-defined action for this new fragment.
							hr = pCallback(pHtmlDoc, message);

							// Clean up.
							pHtmlDoc->Release();
						}
						pMarkupContainer->Release();
					}
					pMarkupEnd->Release();
				}
				if (pMarkupBegin)
					pMarkupBegin->Release();
				pMarkupServices->Release();
			}
			pPersistStreamInit->Release();
		}
		pHtmlDocRoot->Release();
	}
	return hr;
}
Beispiel #3
0
bool CActiveXUI::DelayedControlCreation()
{
   ReleaseControl();
   // At this point we'll create the ActiveX control
   m_bCreated = true;
   IOleControl* pOleControl = NULL;
   HRESULT Hr = ::CoCreateInstance(m_clsid, NULL, CLSCTX_ALL, IID_IOleControl, (LPVOID*) &pOleControl);
   ASSERT(SUCCEEDED(Hr));
   if( FAILED(Hr) ) return false;
   pOleControl->QueryInterface(IID_IOleObject, (LPVOID*) &m_pUnk);
   pOleControl->Release();
   if( m_pUnk == NULL ) return false;
   // Create the host too
   m_pControl = new CActiveXCtrl();
   m_pControl->m_pOwner = this;
   // More control creation stuff
   DWORD dwMiscStatus = 0;
   m_pUnk->GetMiscStatus(DVASPECT_CONTENT, &dwMiscStatus);
   IOleClientSite* pOleClientSite = NULL;
   m_pControl->QueryInterface(IID_IOleClientSite, (LPVOID*) &pOleClientSite);
   CSafeRelease<IOleClientSite> RefOleClientSite = pOleClientSite;
   // Initialize control
   if( (dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST) != 0 ) m_pUnk->SetClientSite(pOleClientSite);
   IPersistStreamInit* pPersistStreamInit = NULL;
   m_pUnk->QueryInterface(IID_IPersistStreamInit, (LPVOID*) &pPersistStreamInit);
   if( pPersistStreamInit != NULL ) {
      Hr = pPersistStreamInit->InitNew();
      pPersistStreamInit->Release();
   }
   if( FAILED(Hr) ) return false;
   if( (dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST) == 0 ) m_pUnk->SetClientSite(pOleClientSite);
   // Grab the view...
   Hr = m_pUnk->QueryInterface(IID_IViewObjectEx, (LPVOID*) &m_pControl->m_pViewObject);
   if( FAILED(Hr) ) Hr = m_pUnk->QueryInterface(IID_IViewObject2, (LPVOID*) &m_pControl->m_pViewObject);
   if( FAILED(Hr) ) Hr = m_pUnk->QueryInterface(IID_IViewObject, (LPVOID*) &m_pControl->m_pViewObject);
   // Activate and done...
   m_pUnk->SetHostNames(OLESTR("UIActiveX"), NULL);
   if( (dwMiscStatus & OLEMISC_INVISIBLEATRUNTIME) == 0 ) {
      Hr = m_pUnk->DoVerb(OLEIVERB_INPLACEACTIVATE, NULL, pOleClientSite, 0, m_pManager->GetPaintWindow(), &m_rcItem);
      ::RedrawWindow(m_pManager->GetPaintWindow(), &m_rcItem, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_INTERNALPAINT | RDW_FRAME);
   }
   IObjectWithSite* pSite = NULL;
   m_pUnk->QueryInterface(IID_IObjectWithSite, (LPVOID*) &pSite);
   if( pSite != NULL ) {
      pSite->SetSite(static_cast<IOleClientSite*>(m_pControl));
      pSite->Release();
   }
   return SUCCEEDED(Hr);
}
Beispiel #4
0
int CSOAPUtil::LoadDOMDocument(char* data, int size, MSXML2::IXMLDOMDocumentPtr xmlDoc)
{
    if( data == NULL || xmlDoc == NULL ) {
        return ERR_FALSE;
    }

    IStream* pIStream = NULL;
    IPersistStreamInit* pIPStream = NULL;

    HRESULT hr = CreateStreamOnHGlobal(NULL,TRUE,&pIStream);
    if(FAILED(hr)) {
        return ERR_FALSE;
    }
    hr = pIStream->Write(data,size,NULL);
    if(FAILED(hr)) {
        pIStream->Release();
        pIStream = NULL;
        return ERR_FALSE;
    }
    pIStream->Commit(STGC_OVERWRITE);
    LARGE_INTEGER pos = {0, 0};
    pIStream->Seek(pos, STREAM_SEEK_SET, NULL);

    hr = xmlDoc->QueryInterface(IID_IPersistStreamInit, (void **)&pIPStream);
    if(FAILED(hr)) {
        pIStream->Release();
        pIStream = NULL;
        return ERR_FALSE;
    }

    hr = pIPStream->Load(pIStream);

    pIPStream->Release();
    pIPStream = NULL;
    pIStream->Release();
    pIStream = NULL;

    if(FAILED(hr)) {
        return ERR_FALSE;
    } else {
        return NO_ERR;
    }
}
//
// Function: LoadWebOCFromStream
//
// Description: Takes an IWebBrowser pointer and causes the stream to 
// be loaded into the contained HTML Document Object.
//
HRESULT LoadWebOCFromStream(IWebBrowser *pWebBrowser, IStream *pStream)
{
    HRESULT             hr;
    LPDISPATCH          pHtmlDoc = NULL;
    IPersistStreamInit *pPersistStreamInit = NULL;

    // Test for valid pointers.
    //
    if (!pWebBrowser || !pStream)
        return E_POINTER;

    // Get to the document object's IDispatch pointer.
    //
    hr = pWebBrowser->get_Document(&pHtmlDoc);
    if (hr)
        goto CleanUp;

    // Query for IPersistStreamInit
    //
    hr = pHtmlDoc->QueryInterface(IID_IPersistStreamInit, 
            (void**)&pPersistStreamInit);
    if (hr)
        goto CleanUp;

    // Tell the document we'll be reinitializing it.
    //
    hr = pPersistStreamInit->InitNew();
    if (hr)
        goto CleanUp;

    // Load the contents of the stream.
    //
    hr = pPersistStreamInit->Load(pStream);

CleanUp:
    if (pHtmlDoc)
        pHtmlDoc->Release();
    if (pPersistStreamInit)
        pPersistStreamInit->Release();
    return hr;

}
void Win32WebControl::_loadHTMLString(const std::string &html) const
{
    bool flag = false;
    HGLOBAL htmlText = globalAllocWstringFromString(html);
    if (htmlText != NULL)
    {
        IStream *stream = NULL;
        if (SUCCEEDED(CreateStreamOnHGlobal(htmlText, FALSE, &stream)))
        {
            IPersistStreamInit *persistStreamInit = NULL;
            if (SUCCEEDED(_htmlDoc->QueryInterface(IID_IPersistStreamInit, (void **)&persistStreamInit)))
            {
                if (SUCCEEDED(persistStreamInit->InitNew()) && SUCCEEDED(persistStreamInit->Load(stream)))
                {
                    flag = true;
                }
                persistStreamInit->Release();
            }
            stream->Release();
        }
        GlobalFree(htmlText);
    }
    if (flag)
    {
        if (_didFinishLoading != nullptr)
        {
            std::string str("data:text/html,");
            str.append(html);
            _didFinishLoading(str);
        }
    }
    else
    {
        if (_didFailLoading != nullptr)
        {
            std::string str("data:text/html,");
            str.append(html);
            _didFailLoading(str);
        }
    }
}
bool CActiveXUI::DoCreateControl()
{
    ReleaseControl();
    // At this point we'll create the ActiveX control
    m_bCreated = true;
    IOleControl* pOleControl = NULL;

    HRESULT Hr = -1;
    if( !m_sModuleName.IsEmpty() ) {
        HMODULE hModule = ::LoadLibrary((LPCTSTR)m_sModuleName);
        if( hModule != NULL ) {
            IClassFactory* aClassFactory = NULL;
            DllGetClassObjectFunc aDllGetClassObjectFunc = (DllGetClassObjectFunc)::GetProcAddress(hModule, "DllGetClassObject");
            Hr = aDllGetClassObjectFunc(m_clsid, IID_IClassFactory, (LPVOID*)&aClassFactory);
            if( SUCCEEDED(Hr) ) {
                Hr = aClassFactory->CreateInstance(NULL, IID_IOleObject, (LPVOID*)&pOleControl);
            }
            aClassFactory->Release();
        }
    }
    if( FAILED(Hr) ) {
        Hr = ::CoCreateInstance(m_clsid, NULL, CLSCTX_ALL, IID_IOleControl, (LPVOID*)&pOleControl);
    }
    ASSERT(SUCCEEDED(Hr));
    if( FAILED(Hr) ) return false;
    pOleControl->QueryInterface(IID_IOleObject, (LPVOID*) &m_pUnk);
    pOleControl->Release();
    if( m_pUnk == NULL ) return false;
    // Create the host too
    m_pControl = new CActiveXCtrl();
    m_pControl->m_pOwner = this;
    // More control creation stuff
    DWORD dwMiscStatus = 0;
    m_pUnk->GetMiscStatus(DVASPECT_CONTENT, &dwMiscStatus);
    IOleClientSite* pOleClientSite = NULL;
    m_pControl->QueryInterface(IID_IOleClientSite, (LPVOID*) &pOleClientSite);
    CSafeRelease<IOleClientSite> RefOleClientSite = pOleClientSite;
    // Initialize control
    if( (dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST) != 0 ) m_pUnk->SetClientSite(pOleClientSite);
    IPersistStreamInit* pPersistStreamInit = NULL;
    m_pUnk->QueryInterface(IID_IPersistStreamInit, (LPVOID*) &pPersistStreamInit);
    if( pPersistStreamInit != NULL ) {
        Hr = pPersistStreamInit->InitNew();
        pPersistStreamInit->Release();
    }
    if( FAILED(Hr) ) return false;
    if( (dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST) == 0 ) m_pUnk->SetClientSite(pOleClientSite);
    // Grab the view...
    Hr = m_pUnk->QueryInterface(IID_IViewObjectEx, (LPVOID*) &m_pControl->m_pViewObject);
    if( FAILED(Hr) ) Hr = m_pUnk->QueryInterface(IID_IViewObject2, (LPVOID*) &m_pControl->m_pViewObject);
    if( FAILED(Hr) ) Hr = m_pUnk->QueryInterface(IID_IViewObject, (LPVOID*) &m_pControl->m_pViewObject);
    // Activate and done...
    m_pUnk->SetHostNames(OLESTR("UIActiveX"), NULL);
    if( m_pManager != NULL ) m_pManager->SendNotify((CControlUI*)this, _T("showactivex"), 0, 0, false);
    if( (dwMiscStatus & OLEMISC_INVISIBLEATRUNTIME) == 0 ) {
        Hr = m_pUnk->DoVerb(OLEIVERB_INPLACEACTIVATE, NULL, pOleClientSite, 0, m_pManager->GetPaintWindow(), &m_rcItem);
        //::RedrawWindow(m_pManager->GetPaintWindow(), &m_rcItem, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_INTERNALPAINT | RDW_FRAME);
    }
    IObjectWithSite* pSite = NULL;
    m_pUnk->QueryInterface(IID_IObjectWithSite, (LPVOID*) &pSite);
    if( pSite != NULL ) {
        pSite->SetSite(static_cast<IOleClientSite*>(m_pControl));
        pSite->Release();
    }
    return SUCCEEDED(Hr);
}
Beispiel #8
0
bool AxContainer::CreateControl( const std::string &strModule, REFCLSID rclsid )
{
	IOleControl* pOleControl = NULL;

	HRESULT hr = -1;
	if( !strModule.empty() ) 
	{
		HMODULE hModule = ::LoadLibrary((LPCTSTR)strModule.c_str());
		if( hModule != NULL ) 
		{
			IClassFactory* aClassFactory = NULL;
			DllGetClassObjectFunc aDllGetClassObjectFunc = (DllGetClassObjectFunc)::GetProcAddress(hModule, "DllGetClassObject");
			hr = aDllGetClassObjectFunc(rclsid, IID_IClassFactory, (LPVOID*)&aClassFactory);
			if( SUCCEEDED(hr) ) 
			{
				hr = aClassFactory->CreateInstance(NULL, IID_IOleObject, (LPVOID*)&pOleControl);
			}
			aClassFactory->Release();
		}
	}
	if( FAILED(hr) ) 
		hr = ::CoCreateInstance(rclsid, NULL, CLSCTX_ALL, IID_IOleControl, (LPVOID*)&pOleControl);

	if( FAILED(hr) ) 
		return false;
	pOleControl->QueryInterface(IID_IOleObject, (LPVOID*) &m_pOleObject);
	pOleControl->Release();
	if( m_pOleObject == NULL ) 
		return false;

	hr = m_pOleObject->QueryInterface(IID_IOleInPlaceObjectWindowless, (LPVOID*) &m_pInPlaceObject);

	// More control creation stuff
	DWORD dwMiscStatus = 0;
	m_pOleObject->GetMiscStatus(DVASPECT_CONTENT, &dwMiscStatus);
	// Initialize control
	if( (dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST) != 0 ) 
		m_pOleObject->SetClientSite(this);
	IPersistStreamInit* pPersistStreamInit = NULL;
	m_pOleObject->QueryInterface(IID_IPersistStreamInit, (LPVOID*) &pPersistStreamInit);
	if( pPersistStreamInit != NULL )
	{
		hr = pPersistStreamInit->InitNew();
		pPersistStreamInit->Release();
	}
	if( FAILED(hr) ) 
		return false;
	if( (dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST) == 0 ) 
		m_pOleObject->SetClientSite(this);
	// Grab the view...
	hr = m_pOleObject->QueryInterface(IID_IViewObjectEx, (LPVOID*) &m_pViewObject);
	if( FAILED(hr) ) 
		hr = m_pOleObject->QueryInterface(IID_IViewObject2, (LPVOID*) &m_pViewObject);
	if( FAILED(hr) ) 
		hr = m_pOleObject->QueryInterface(IID_IViewObject, (LPVOID*) &m_pViewObject);

	// Activate and done...
	m_pOleObject->SetHostNames(OLESTR("UIActiveX"), NULL);
	if( (dwMiscStatus & OLEMISC_INVISIBLEATRUNTIME) == 0 ) 
		DoVerb(OLEIVERB_INPLACEACTIVATE);

	IObjectWithSite* pSite = NULL;
	m_pOleObject->QueryInterface(IID_IObjectWithSite, (LPVOID*) &pSite);
	if( pSite != NULL ) 
	{
		pSite->SetSite(static_cast<IOleWindow*>(this));
		pSite->Release();
	}

	return SUCCEEDED(hr);
}
static cgMSXML::IXMLDocument* XML_GetDocument(
    CGT_CDiagMsg* pdm,
    CG_CIECFront* pFront,
    const TCHAR*  pszXMLFile, 
    __int64*      pOnOpenLastWriteFileTime
)
{
    cgMSXML::IXMLDocument           *pDoc = NULL;
    IStream                *pStm = NULL;
    IPersistStreamInit     *pPSI = NULL;
    HRESULT                hr;

 
    
    // Create an empty XML document.
    hr = CoCreateInstance(cgMSXML::CLSID_XMLDocument, NULL, CLSCTX_INPROC_SERVER,
                                cgMSXML::IID_IXMLDocument, (void**)&pDoc);
    if(FAILED(hr) || !pDoc) 
        goto fatalError;

    //try to open the disk or lib file:
    if(!LoadFileToIStream(pdm, pFront, pszXMLFile, &pStm, pOnOpenLastWriteFileTime))
        return NULL;
    assert(pStm);

    
    // Get the IPersistStreamInit interface to the XML doc.
    hr = pDoc->QueryInterface(IID_IPersistStreamInit, (void **)&pPSI);
    if(FAILED(hr) || !pPSI)
        goto fatalError;

    // Init the XML doc from the stream.
    hr = pPSI->Load(pStm);
    if(FAILED(hr))
    {
        // Print error information !
        cgMSXML::IXMLError *pXMLError = NULL ;
        cgMSXML::_xml_error xmle;

        hr = pPSI->QueryInterface(cgMSXML::IID_IXMLError, (void **)&pXMLError);
        if(FAILED(hr) || !pXMLError)
            goto fatalError;

        hr = pXMLError->GetErrorInfo(&xmle);
        if(FAILED(hr))
            goto fatalError;
        pXMLError->Release();

        //different error message formats
        //if found string is ??? xmle._pszExpected seem to be a 
        //preformated message ready to dump
        if(!wcscmp(xmle._pszFound, L"???"))
        {
            pdm->msg3(CG_E_XML_PARSE_ERROR, NULL, pszXMLFile, 
                pdm->jot1()<<((int)xmle._nLine), pdm->jot2()<<xmle._pszExpected);
        }
        else
        {
            pdm->msg3(CG_E_XML_PARSE_ERROR, NULL, pszXMLFile, 
                pdm->jot1()<<((int)xmle._nLine), pdm->jot2()<<xmle._pszFound);
        }

        SysFreeString(xmle._pszFound);
        SysFreeString(xmle._pszExpected);
        SysFreeString(xmle._pchBuf);

        pDoc->Release();
        pDoc = NULL;
    }

    // Release any used interfaces.
    if(pPSI)
        pPSI->Release();
    if(pStm)
        pStm->Release();

    return pDoc;

fatalError:
    pdm->sysErr(hr, NULL, _T("CLSID_XMLDocument for file: "), pszXMLFile);
    return NULL;

}