469,926 Members | 2,301 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,926 developers. It's quick & easy.

iHTMLElementrender.drawtodc causes error in VB.net application


I am having problems with using the DrawToDC of the
MSHTML.iHTMLElementRender in a VB.net application. For some reason I am
getting a "catastrophic error". I am basing the code on c# examples, and I
am not sure what exactly I am doing wrong. From the C# posts it seems that
the drawtodc has a bug and you need to redifine it, so i followed their
advice and specified an interface as below:
Imports System
Imports System.Drawing
Imports System.Runtime.InteropServices
Imports mshtml

<ComVisible(True), ComImport(),
Guid("3050f669-98b5-11cf-bb82-00aa00bdce0b"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceI sIUnknown)> _
Interface IHTMLElementRender
Sub DrawToDC(<[In]()> ByVal hDC As IntPtr)
Sub SetDocumentPrinter(<[In](), MarshalAs(UnmanagedType.BStr)> ByVal
bstrPrinterName As String, <[In]()> ByVal hDC As IntPtr)
End Interface 'IHTMLElementRender

On the main form of the application I am doing the following:

Dim objMSHTML As HTMLDocument
Dim objDocument As IHTMLDocument2
Dim ips As IPersistStreamInit

objMSHTML = New HTMLDocument()

ips = DirectCast(objMSHTML, IPersistStreamInit)

objDocument =
objMSHTML.createDocumentFromUrl("http://www.google.com", String.Empty)

Do Until objDocument.readyState = "complete"

Dim bodyElement As IHTMLElement
Dim render As IHTMLElementRender
If objDocument.body.outerHTML <> Nothing Then
bodyElement = objDocument.body
render = bodyElement
Dim img As New Bitmap(600, 400)
Dim g As Graphics = Graphics.FromImage(img)
Dim memDC As IntPtr
memDC = g.GetHdc()

Catch ex As Exception
End Try
End If

It seems like I am getting the HTML document just fine, is just that when I
try to use DrawToDC to get the application to print/send to the DC i Created
in memory, it causes the error.Any ideas on what I am doing wrong?

Here are the links to where I got the C# examples:

Nov 21 '05 #1
0 1741

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Ari Royce Hidayat | last post: by
reply views Thread by Ari Royce Hidayat | last post: by
2 posts views Thread by Jonathan Trevor | last post: by
1 post views Thread by Philipp Schumann | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.