Hi
To create an HTML document in memory, I recommend the following:
<code>
Imports System.Runtime.InteropServices
' IPersistStreamInit interface
<ComVisible(True), ComImport(),
Guid("7FD52380-4E07-101B-AE2D-08002B2EC713"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IPersistStreamInit
Sub GetClassID(ByRef pClassID As Guid)
<PreserveSig()> Function IsDirty() As Integer
<PreserveSig()> Function Load(ByVal pstm As UCOMIStream) As Integer
<PreserveSig()> Function Save(ByVal pstm As UCOMIStream, ByVal fClearDirty
As Boolean) As Integer
<PreserveSig()> Function GetSizeMax(<InAttribute(), Out(),
MarshalAs(UnmanagedType.U8)> ByRef pcbSize As Long) As Integer
<PreserveSig()> Function InitNew() As Integer
End Interface
Private Function CreateDocument() As mshtml.IHTMLDocument2
Dim doc2 As mshtml.IHTMLDocument2
Dim ips As IPersistStreamInit
' Create a new document
doc2 = New mshtml.HTMLDocument
ips = DirectCast(doc2, IPersistStreamInit)
' Initialise the document
ips.InitNew()
' Wait until initialisation is complete
Do Until doc2.readyState = "complete"
Application.DoEvents()
Loop
Return doc2
End Function
</code>
This will create an initialisesd document that you can manipulate.
Include a reference to Microsoft.mshtml in your project, but as Cor
suggested, do not include an imports for mshtml, but qualify declarations
with it instead. Mshtml contains hundreds of interfaces that take a
noticeable time to load each time you type Dim x As ...
Once you have an interface to the document (doc2) you can manipulate it
through this and other interfaces.
ips.Load will load the document from a stream, but remember to wait for
doc2.readstate to be "complete" before accessing the document; docuemnts are
loaded asynchronously.
Feel free to post back further questions. You may also like to look at
microsoft.public.inetsdk.programming.mshtml_hosting
microsoft.public.inetsdk.programming.webbrowser_ctl
I tend to post answers to this type of question here as they crop up quite
frequently. When I have a moment ( ;-) ) I will try to put together a small
app that demonstrates a lot of the techniques.
HTH
Charles