WebBrowser: How to cast the document object

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • zdp

    WebBrowser: How to cast the document object

    Hi, all,

    My project is based on wxPython, and I need an IE control (i.e.
    WebBrowser ActiveX control). Although the wxPython implements a
    wrapped version (wx.lib.iewin.I EHtmlWindow), but it doesn't meet all
    my demands, because I need to custom many behaviors of the control.
    So I thought I should use it through ActiveXWrapper directly.

    So I use makepy to make the typelib of "Microsoft Internet Controls"
    and "Microsoft HTML Object Library". Now I can get the document object
    of the WebBrowser, and I can cast it into any interface I need like
    IHtmlDocument2, IHtmlDocument3. .. So far, so good.

    The document object also implements a COM interface
    IPersistStreamI nit, which has a *Load* method. Calling this method can
    load any stream into the browser control. Here is the a example using
    this method in visual c++:

    IPersistStreamI nit* spPSI = NULL;
    CStreamOnCStrin g stream(szHTML);
    if (m_pHtmlDoc) {
    m_hResult = m_pHtmlDoc->QueryInterface (IID_IPersistSt reamInit,
    (void**)&spPSI) ;
    if( SUCCEEDED(m_hRe sult) && spPSI ) {
    m_hResult = spPSI->Load(static_ca st<IStream*>(&s tream));
    spPSI->Release();
    }
    }

    Now I need to call this method on my document object, my code is just
    like

    stream = win32com.client .CastTo(doc, "IPersistStream Init")
    stream.Load(som estr)

    But I got an error:

    ValueError: The interface name 'IPersistStream Init' does not appear in
    the same
    library as object '<win32com.gen_ py.Microsoft HTML Object
    Library.DispHTM LDocume
    nt instance at 0x46359096>'

    I googled and someones says only interfaces inherit from IDispatch can
    be used by pythoncom. But IPersistStreamI nit interface inherits from
    IUnknown. But I just need to use
    this interface.

    However, I also noted that the class wx.lib.iewin.IE HtmlWindow has a
    *LoadStream* method, I thought it's a wrapper of IPersistStreamI nit's
    Load method. So I trace the source code, but only found the implement
    is in the c++ base class.

    Could anybody tell me how to do it? Any clues is helpful.

    Dapu

  • Roger Upole

    #2
    Re: WebBrowser: How to cast the document object


    "zdp" <zhaodapu@gmail .comwrote in message news:1178482264 .678509.58730@p 77g2000hsh.goog legroups.com...
    Hi, all,
    >
    My project is based on wxPython, and I need an IE control (i.e.
    WebBrowser ActiveX control). Although the wxPython implements a
    wrapped version (wx.lib.iewin.I EHtmlWindow), but it doesn't meet all
    my demands, because I need to custom many behaviors of the control.
    So I thought I should use it through ActiveXWrapper directly.
    >
    So I use makepy to make the typelib of "Microsoft Internet Controls"
    and "Microsoft HTML Object Library". Now I can get the document object
    of the WebBrowser, and I can cast it into any interface I need like
    IHtmlDocument2, IHtmlDocument3. .. So far, so good.
    >
    The document object also implements a COM interface
    IPersistStreamI nit, which has a *Load* method. Calling this method can
    load any stream into the browser control. Here is the a example using
    this method in visual c++:
    >
    IPersistStreamI nit* spPSI = NULL;
    CStreamOnCStrin g stream(szHTML);
    if (m_pHtmlDoc) {
    m_hResult = m_pHtmlDoc->QueryInterface (IID_IPersistSt reamInit,
    (void**)&spPSI) ;
    if( SUCCEEDED(m_hRe sult) && spPSI ) {
    m_hResult = spPSI->Load(static_ca st<IStream*>(&s tream));
    spPSI->Release();
    }
    }
    >
    Now I need to call this method on my document object, my code is just
    like
    >
    stream = win32com.client .CastTo(doc, "IPersistStream Init")
    stream.Load(som estr)
    >
    But I got an error:
    >
    ValueError: The interface name 'IPersistStream Init' does not appear in
    the same
    library as object '<win32com.gen_ py.Microsoft HTML Object
    Library.DispHTM LDocume
    nt instance at 0x46359096>'
    >
    I googled and someones says only interfaces inherit from IDispatch can
    be used by pythoncom. But IPersistStreamI nit interface inherits from
    IUnknown. But I just need to use
    this interface.
    Many non-IDispatch interfaces are supported by pythoncom, IPersistStreamI nit among them.
    You should be able to use QueryInterface just as the c++ code does.
    Try something like

    stream=doc._ole obj_.QueryInter face(pythoncom. IID_IPersistStr eamInit)

    hth
    Roger




    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----

    Comment

    Working...