473,398 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

WebBrowser: How to cast the document object

zdp
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.IEHtmlWindow), 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
IPersistStreamInit, 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++:

IPersistStreamInit* spPSI = NULL;
CStreamOnCString stream(szHTML);
if (m_pHtmlDoc) {
m_hResult = m_pHtmlDoc->QueryInterface(IID_IPersistStreamInit,
(void**)&spPSI);
if( SUCCEEDED(m_hResult) && spPSI ) {
m_hResult = spPSI->Load(static_cast<IStream*>(&stream));
spPSI->Release();
}
}

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

stream = win32com.client.CastTo(doc, "IPersistStreamInit")
stream.Load(somestr)

But I got an error:

ValueError: The interface name 'IPersistStreamInit' does not appear in
the same
library as object '<win32com.gen_py.Microsoft HTML Object
Library.DispHTMLDocume
nt instance at 0x46359096>'

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

However, I also noted that the class wx.lib.iewin.IEHtmlWindow has a
*LoadStream* method, I thought it's a wrapper of IPersistStreamInit'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

May 6 '07 #1
1 2812

"zdp" <zh******@gmail.comwrote in message news:11*********************@p77g2000hsh.googlegro ups.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.IEHtmlWindow), 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
IPersistStreamInit, 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++:

IPersistStreamInit* spPSI = NULL;
CStreamOnCString stream(szHTML);
if (m_pHtmlDoc) {
m_hResult = m_pHtmlDoc->QueryInterface(IID_IPersistStreamInit,
(void**)&spPSI);
if( SUCCEEDED(m_hResult) && spPSI ) {
m_hResult = spPSI->Load(static_cast<IStream*>(&stream));
spPSI->Release();
}
}

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

stream = win32com.client.CastTo(doc, "IPersistStreamInit")
stream.Load(somestr)

But I got an error:

ValueError: The interface name 'IPersistStreamInit' does not appear in
the same
library as object '<win32com.gen_py.Microsoft HTML Object
Library.DispHTMLDocume
nt instance at 0x46359096>'

I googled and someones says only interfaces inherit from IDispatch can
be used by pythoncom. But IPersistStreamInit interface inherits from
IUnknown. But I just need to use
this interface.
Many non-IDispatch interfaces are supported by pythoncom, IPersistStreamInit among them.
You should be able to use QueryInterface just as the c++ code does.
Try something like

stream=doc._oleobj_.QueryInterface(pythoncom.IID_I PersistStreamInit)

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 =----
May 6 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Noozer | last post by:
I've got a WebBrowser control (AxBrowse - VCMAXB.DLL) and I'm having a few difficulties with it. Just looking for a few pointers, not whole solutions here. I've tried looking at the MSDN help files...
4
by: Toma Marinov | last post by:
Hello ! I made some test with webbrowser control in VS.2005. When I load a word document in webbrowser through .Navigate method (from my hdd), I want to get the stream of the loaded doc file with...
7
by: Doe | last post by:
I've been trying this for months. Doesn't work. I've used the code in this article, http://support.microsoft.com/kb/311288/en-us, HOW TO: Invoke the Find, View Source, and Options Dialog Boxes...
12
by: Alex Clark | last post by:
Greetings, (.NET 2.0, WinXP Pro/Server 2003, IE6 with latest service packs). I've decided to take advantage of the layout characteristics of HTML documents to simplify my printing tasks, but...
8
by: Prosperz | last post by:
Hi, I would like to make thumbnails of web page by capture content of a WebBrowser. By example, capture http://www.google.com. I used WebBrowser control with Framework 2.0. I try this : ...
0
by: Laurent Lequenne | last post by:
Hello All, I'm currently developing a free windows Scrabble (in french :)) application that uses extensively the WebBrowser class of NET 2.0 for configuration, and data browsing. It works 100%...
15
by: Laurent Lequenne | last post by:
Hello All, I'm currently developing a free windows Scrabble (in french :)) application that uses extensively the WebBrowser class of NET 2.0 for configuration, and data browsing. It works 100%...
4
by: Robson Siqueira | last post by:
Folks, I am facing a problem. I am trying to manipulate the HTML data (thru the Document and DocumentText properties) of the WebBrowser object (System.Windows.Forms). The problem is that the...
11
by: kimiraikkonen | last post by:
Hi there, I needed to use MouseOver event on Webbrowser which is NOT provided by webbrowser control natively(what a disappointment), so i decided to go with another route to simulate this like: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.