473,386 Members | 2,129 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,386 software developers and data experts.

IPersistStreamInitInterface

Hi,
After reading and applying the following sample/example from Charles Law,
who responded Vibhu Bansal's "createDocumentFromUrl usage in VB.NET /
loading a url using mshtml.createDocumentFromUrl " questions, I have
encountered a problem which I was fail to overcome. The problem is when I
multithreaded the example even though I
set all the variables and the threads to nothing, applications threads are
incresing over and over and at a point the whole screen is bloating with all
empty Internet Explorer Windows. I think I was not able to properly release
/ destroy or dispose these objects after I have finished my job with them.
If anyone has any idea about this situation I would really appreciate for
your help.

Thanks in advance,
Onur Buyukcaglar

PS: I feel that I have to implement IUnknown -> Release on
IPersistStreamInit, but I do not know how to do it in VB.NET.
Sample provided by Charles Law about usage of "CreateDocumentFromUrl in
Vb.Net" as follows.
Imports System.Runtime.InteropServices

<ComVisible(True), ComImport(),
Guid("7FD52380-4E07-101B-AE2D-08002B2EC713"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceI sIUnknown)> _
Public Interface IPersistStreamInit
' IPersist interface
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
ByValfClearDirty 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
#Region " Imports "

Imports System
Imports System.Windows.Forms
Imports System.Runtime.InteropServices

#End Region

Module Module1

Dim IID_IHTMLElementRender As Guid = New
Guid("3050f669-98b5-11cf-bb82-00aa00bdce0b")

<MTAThread()> _
Sub Main()

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

objMSHTML = New mshtml.HTMLDocument

ips = DirectCast(objMSHTML, IPersistStreamInit)
ips.InitNew()

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

Do Until objDocument.readyState = "complete"
Threading.Thread.Sleep(1)
Loop

MessageBox.Show(objDocument.body.outerHTML)

End Sub

End Module

Nov 21 '05 #1
1 2181
Yes, release is performed with Marshal.ReleaseComObject.

You would be well advised to wrap all of this inside a try/catch block also,
otherwise if your objects throw an exception, the exception will be handled
outside of the local space where they were created. Doing this enables you
to release COM objects even if an exception occurs, ie:

Dim myComObject as SomeCOMObjectReference

Try

myComObject = DoSomethingToGetReferenceToComObject()
.....

Catch Ex as Exception
....
Finally

if not MyObject is nothing then
Marshal.ReleaseCOMObject(MyObject)
end if

End Try

Also, its worth remembering that out of process COM objects will not be
destroyed purely by releasing your references to them. This is a particular
problem with Word Interop, because you must explicitly call "Quit" to remove
the application (Word) from memory. I'm not sure about the browser however.

"Onur Buyukcaglar" <bu*********@yahoo.com> wrote in message
news:%2*****************@TK2MSFTNGP12.phx.gbl...
Hi,
After reading and applying the following sample/example from Charles Law,
who responded Vibhu Bansal's "createDocumentFromUrl usage in VB.NET /
loading a url using mshtml.createDocumentFromUrl " questions, I have
encountered a problem which I was fail to overcome. The problem is when I
multithreaded the example even though I
set all the variables and the threads to nothing, applications threads are
incresing over and over and at a point the whole screen is bloating with
all
empty Internet Explorer Windows. I think I was not able to properly
release
/ destroy or dispose these objects after I have finished my job with them.
If anyone has any idea about this situation I would really appreciate for
your help.

Thanks in advance,
Onur Buyukcaglar

PS: I feel that I have to implement IUnknown -> Release on
IPersistStreamInit, but I do not know how to do it in VB.NET.
Sample provided by Charles Law about usage of "CreateDocumentFromUrl in
Vb.Net" as follows.
Imports System.Runtime.InteropServices

<ComVisible(True), ComImport(),
Guid("7FD52380-4E07-101B-AE2D-08002B2EC713"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceI sIUnknown)> _
Public Interface IPersistStreamInit
' IPersist interface
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
ByValfClearDirty 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
#Region " Imports "

Imports System
Imports System.Windows.Forms
Imports System.Runtime.InteropServices

#End Region

Module Module1

Dim IID_IHTMLElementRender As Guid = New
Guid("3050f669-98b5-11cf-bb82-00aa00bdce0b")

<MTAThread()> _
Sub Main()

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

objMSHTML = New mshtml.HTMLDocument

ips = DirectCast(objMSHTML, IPersistStreamInit)
ips.InitNew()

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

Do Until objDocument.readyState = "complete"
Threading.Thread.Sleep(1)
Loop

MessageBox.Show(objDocument.body.outerHTML)

End Sub

End Module

Nov 21 '05 #2

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

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.