コード例 #1
0
ファイル: IEHtmlWin.cpp プロジェクト: Aegisub/traydict
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;
}
コード例 #2
0
ファイル: play.cpp プロジェクト: adoggie/netbar_2006
void    TFormPlay::ShowHtml(char * html){
    IPersistStreamInit *psi;
    wb->Navigate(WideString("about:blank"));
    wb->Document->QueryInterface(IID_IPersistStreamInit,(void**)&psi);
    HGLOBAL  gdata;
    IStream *istream;
    gdata = GlobalAlloc(GPTR,strlen( html)+1);
    strcpy( (char*)gdata,html);
    CreateStreamOnHGlobal(gdata,TRUE,&istream);
    psi->InitNew();
    psi->Load(istream);
    //GlobalFree(gdata);
}
コード例 #3
0
ファイル: SOAPUtil.cpp プロジェクト: HK323232/EDCB
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;
    }
}
コード例 #4
0
//
// 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;

}
コード例 #5
0
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);
        }
    }
}
コード例 #6
0
//--------------------------------------------------------------------------------------
HRESULT CRatingsDB::LoadDB()
{
    // Find resource will pick the right ID_GDF_XML_STR based on the current language
    HRSRC hrsrc = FindResource( nullptr, MAKEINTRESOURCE(ID_RATINGS_XML), L"DATA" ); 
    if( hrsrc ) 
    { 
        HGLOBAL hgResource = LoadResource( nullptr, hrsrc ); 
        if( hgResource ) 
        { 
            BYTE* pResourceBuffer = (BYTE*)LockResource( hgResource ); 
            if( pResourceBuffer ) 
            { 
                DWORD dwGDFXMLSize = SizeofResource( nullptr, hrsrc );
                if( dwGDFXMLSize )
                {
                    // HGLOBAL from LoadResource() needs to be copied for CreateStreamOnHGlobal() to work
                    HGLOBAL hgResourceCopy = GlobalAlloc( GMEM_MOVEABLE, dwGDFXMLSize );
                    if( hgResourceCopy )
                    {
                        LPVOID pCopy = GlobalLock( hgResourceCopy );
                        if( pCopy )
                        {
                            CopyMemory( pCopy, pResourceBuffer, dwGDFXMLSize );
                            GlobalUnlock( hgResource );

                            IStream* piStream = nullptr;
                            HRESULT hr = CreateStreamOnHGlobal( hgResourceCopy, TRUE, &piStream ); 
                            if( SUCCEEDED(hr) && piStream )
                            {
                                IXMLDOMDocument *pDoc = nullptr;

                                // Load the XML into a IXMLDOMDocument object
                                hr = CoCreateInstance( CLSID_DOMDocument, nullptr, CLSCTX_INPROC_SERVER, 
                                                       IID_IXMLDOMDocument, (void**)&pDoc );
                                if( SUCCEEDED(hr) ) 
                                {
                                    IPersistStreamInit* pPersistStreamInit = nullptr;
                                    hr = pDoc->QueryInterface( IID_IPersistStreamInit, (void**) &pPersistStreamInit );
                                    if( SUCCEEDED(hr) ) 
                                    {
                                        hr = pPersistStreamInit->Load( piStream );
                                        if( SUCCEEDED(hr) ) 
                                        {
                                            // Get the root node to the XML doc and store it 
                                            pDoc->QueryInterface( IID_IXMLDOMNode, (void**)&m_pRootNode );
                                        }
                                        SAFE_RELEASE( pPersistStreamInit );
                                    }
                                    SAFE_RELEASE( pDoc );
                                }
                                SAFE_RELEASE( piStream );
                            }
                        }
                        GlobalFree( hgResourceCopy );
                    }
                }
            } 
        } 
    } 

    if( m_pRootNode )
        return S_OK;
    else
        return E_FAIL;
}
コード例 #7
0
ファイル: SITE.CPP プロジェクト: 0anion0/IBN
/*
 * CSite::Load
 *
 * Purpose:
 *  Loads the path provided using IPersistMoniker or IPersistFile. If no path
 *	was provided it simply does an InitNew
 *
 * Parameters:
 *  pchPath - The path
 *
 * Return Value:
 */
HRESULT CSite::Load(LPCTSTR pchPath)
{
    HRESULT   hr = S_OK;

    if ( pchPath != NULL && *pchPath != 0)
    {
        USES_CONVERSION;
        LPWSTR szwName = T2W(const_cast<LPTSTR>(pchPath));

        // Path has been provided so check should we use IPersistMoniker or IPersistFile?
        if (memcmp(pchPath, _T("file:"), 5 * sizeof(TCHAR)) == 0 ||
                memcmp(pchPath, _T("http:"), 5 * sizeof(TCHAR)) == 0 ||
                memcmp(pchPath, _T("https:"), 5 * sizeof(TCHAR)) == 0)
        {
//		    OLECHAR  szwName[256];
//			MultiByteToWideChar(CP_ACP, 0, pchPath, -1, szwName, 256);

            // Ask the system for a URL Moniker
            IMoniker* pIMoniker;
            hr = CreateURLMoniker(NULL, (LPWSTR)szwName, &pIMoniker);
            if ( SUCCEEDED(hr) )
            {
                // Get the IPersistMoniker interface
                IPersistMoniker* pPMk;
                hr = m_pObj->QueryInterface(
                         IID_IPersistMoniker,
                         (void **)&pPMk);
                if ( SUCCEEDED(hr) )
                {

                    // note: do not register our BSC when calling IPM::Load directly
                    IBindCtx *pBCtx;
                    hr = CreateBindCtx(0, &pBCtx);
                    if ( SUCCEEDED(hr) )
                    {
                        // Call Load on the IPersistMoniker
                        hr = pPMk->Load(FALSE, pIMoniker, pBCtx, STGM_READ);

                        pBCtx->Release();
                    }
                    ReleaseInterface(pPMk);
                }
                ReleaseInterface( pIMoniker );
            }
        }
        else if ( m_pFR->IsFilterIn() )
        {
            IPersistStreamInit* pPStm = NULL;
            LPSTREAM pFilteredStream = NULL;
            DWORD dwFlags = 0;

//			dwFlags = ((CCEditApp*) AfxGetApp())->GetOptions().GetFilterFlags();
//			dwFlags |= dwFilterMultiByteStream; // loading an ANSI Stream

            hr = m_pObj->QueryInterface(
                     IID_IPersistStreamInit,
                     (void **)&pPStm);

            if ( SUCCEEDED(hr) )
            {
                if (SUCCEEDED(hr = HrFilterIn(pchPath, &pFilteredStream, dwFlags)))
                {
                    hr = pPStm->Load(pFilteredStream);

                    ReleaseInterface(pFilteredStream);
                    ReleaseInterface(pPStm);
                }
            }
        }
        else
        {
//		    OLECHAR  szwName[256];
//			MultiByteToWideChar(CP_ACP, 0, pchPath, -1, szwName, 256);
            IPersistFile*  pPFile;
            hr = m_pObj->QueryInterface(
                     IID_IPersistFile,
                     (void **) &pPFile);
            if ( SUCCEEDED(hr) )
            {
                // Call Load on the IPersistFile
                hr = pPFile->Load((LPWSTR)szwName, 0);
                ReleaseInterface(pPFile);
            }
        }
    }
    else
    {
        // No path provided so just do an InitNew on the Stream
        IPersistStreamInit* pPStm;
        hr = m_pObj->QueryInterface(
                 IID_IPersistStreamInit,
                 (void **)&pPStm);
        if ( SUCCEEDED(hr) )
        {
            hr = pPStm->InitNew();
            ReleaseInterface(pPStm);
        }
    }

    return hr;
}
コード例 #8
0
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;

}
コード例 #9
0
ファイル: About.cpp プロジェクト: elazzi/winscp
//---------------------------------------------------------------------------
void __fastcall TAboutDialog::LoadThirdParty()
{
  TWebBrowserEx * ThirdPartyWebBrowser =
    CreateBrowserViewer(ThirdPartyPanel, L"");

  reinterpret_cast<TLabel *>(ThirdPartyWebBrowser)->Color = clBtnFace;

  ThirdPartyWebBrowser->Navigate(L"about:blank");
  while (ThirdPartyWebBrowser->ReadyState < ::READYSTATE_INTERACTIVE)
  {
    Application->ProcessMessages();
  }

  std::unique_ptr<TFont> DefaultFont(new TFont());

  UnicodeString ThirdParty;

  ThirdParty +=
    L"<!DOCTYPE html>\n"
    L"<meta charset=\"utf-8\">\n"
    L"<html>\n"
    L"<head>\n"
    L"<style>\n"
    L"\n"
    L"body\n"
    L"{\n"
    L"  font-family: '" + DefaultFont->Name + L"';\n"
    L"  margin: 0.5em;\n"
    L"  background-color: " + ColorToWebColorStr(Color) + L";\n"
    L"}\n"
    L"\n"
    L"body\n"
    L"{\n"
    L"    font-size: " + IntToStr(DefaultFont->Size) + L"pt;\n"
    L"}\n"
    L"\n"
    L"p\n"
    L"{\n"
    L"    margin-top: 0;\n"
    L"    margin-bottom: 1em;\n"
    L"}\n"
    L"\n"
    L"a, a:visited, a:hover, a:visited, a:current\n"
    L"{\n"
    L"    color: " + ColorToWebColorStr(LinkColor) + L";\n"
    L"}\n"
    L"</style>\n"
    L"</head>\n"
    L"<body>\n";

  UnicodeString Br = "<br/>\n";
  AddPara(ThirdParty, LoadStr(ABOUT_THIRDPARTY_HEADER));

  AddPara(ThirdParty,
    FMTLOAD(PUTTY_BASED_ON, (LoadStr(PUTTY_VERSION))) + Br +
    LoadStr(PUTTY_COPYRIGHT) + Br +
    CreateLink(LoadStr(PUTTY_LICENSE_URL), LoadStr(ABOUT_THIRDPARTY_LICENSE)) + Br +
    CreateLink(LoadStr(PUTTY_URL)));

#ifndef NO_FILEZILLA

  UnicodeString OpenSSLVersionText = GetOpenSSLVersionText();
  CutToChar(OpenSSLVersionText, L' ', true); // "OpenSSL"
  UnicodeString OpenSSLVersion = CutToChar(OpenSSLVersionText, L' ', true);
  CutToChar(OpenSSLVersionText, L' ', true); // day
  CutToChar(OpenSSLVersionText, L' ', true); // month
  UnicodeString OpenSSLYear = CutToChar(OpenSSLVersionText, L' ', true);

  AddPara(ThirdParty,
    FMTLOAD(OPENSSL_BASED_ON, (OpenSSLVersion)) + Br +
    FMTLOAD(OPENSSL_COPYRIGHT2, (OpenSSLYear)) + Br +
    CreateLink(LoadStr(OPENSSL_URL)));

  AddPara(ThirdParty,
    LoadStr(FILEZILLA_BASED_ON2) + Br +
    LoadStr(FILEZILLA_COPYRIGHT2) + Br +
    CreateLink(LoadStr(FILEZILLA_URL)));

#endif

  AddPara(ThirdParty,
    FMTLOAD(NEON_BASED_ON, (NeonVersion())) + Br +
    LoadStr(NEON_COPYRIGHT) + Br +
    CreateLink(LoadStr(NEON_URL)));

  #define EXPAT_LICENSE_URL L"license:expat"

  AddPara(ThirdParty,
    FMTLOAD(EXPAT_BASED_ON, (ExpatVersion())) + Br +
    CreateLink(EXPAT_LICENSE_URL, LoadStr(ABOUT_THIRDPARTY_LICENSE)) + Br +
    CreateLink(LoadStr(EXPAT_URL)));

  AddBrowserLinkHandler(ThirdPartyWebBrowser, EXPAT_LICENSE_URL, ExpatLicenceHandler);

#ifndef NO_COMPONENTS

  AddPara(ThirdParty,
    FMTLOAD(ABOUT_TOOLBAR2000, (Toolbar2000Version)) + Br +
    LoadStr(ABOUT_TOOLBAR2000_COPYRIGHT) + Br +
    CreateLink(LoadStr(ABOUT_TOOLBAR2000_URL)));

  AddPara(ThirdParty,
    FMTLOAD(ABOUT_TBX, (TBXVersionString)) + Br +
    LoadStr(ABOUT_TBX_COPYRIGHT) + Br +
    CreateLink(LoadStr(ABOUT_TBX_URL)));

  AddPara(ThirdParty,
    LoadStr(ABOUT_FILEMANAGER) + Br +
    LoadStr(ABOUT_FILEMANAGER_COPYRIGHT));

#endif

  UnicodeString JclVersion =
    FormatVersion(JclVersionMajor, JclVersionMinor, JclVersionRelease);
  AddPara(ThirdParty,
    FMTLOAD(ABOUT_JCL, (JclVersion)) + Br +
    CreateLink(LoadStr(ABOUT_JCL_URL)));

  AddPara(ThirdParty,
    LoadStr(ABOUT_PNG) + Br +
    LoadStr(ABOUT_PNG_COPYRIGHT) + Br +
    CreateLink(LoadStr(ABOUT_PNG_URL)));

  ThirdParty +=
    L"</body>\n"
    L"</html>\n";

  std::unique_ptr<TMemoryStream> ThirdPartyStream(new TMemoryStream());
  UTF8String ThirdPartyUTF8 = UTF8String(ThirdParty);
  ThirdPartyStream->Write(ThirdPartyUTF8.c_str(), ThirdPartyUTF8.Length());
  ThirdPartyStream->Seek(0, 0);

  // For stream-loaded document, when set only after loading from OnDocumentComplete,
  // browser stops working
  SetBrowserDesignModeOff(ThirdPartyWebBrowser);

  TStreamAdapter * ThirdPartyStreamAdapter = new TStreamAdapter(ThirdPartyStream.get(), soReference);
  IPersistStreamInit * PersistStreamInit = NULL;
  if (ALWAYS_TRUE(ThirdPartyWebBrowser->Document != NULL) &&
      SUCCEEDED(ThirdPartyWebBrowser->Document->QueryInterface(IID_IPersistStreamInit, (void **)&PersistStreamInit)) &&
      ALWAYS_TRUE(PersistStreamInit != NULL))
  {
    PersistStreamInit->Load(static_cast<_di_IStream>(*ThirdPartyStreamAdapter));
  }
}