Clarification about Microsoft.mshtml component within .NET 2 frame

G

Guest

Hi all,

In the past 3 days I have done some research about Microsoft.mshtml
component within .NET 2 framework.

I need some clarification/comfermation about the Microsoft.mshtml componet
and microsoft stargey. In specific: Microsoft.mshtml within the .net 2
framework


1. mshtml.HTMLDocument is not part of the .net 2 framework.

2. it seems that microsoft suggests to use .net managed classes. E.g.
System.Windows.Forms.HtmlDocument instead than mshtml.HTMLDocument

3. Those new classes works fine with the web control (because is managed)
but they are limited in the use, specifically in interfacing with Internet
Explorer 6 and IE7 Beta 2. (e.g. I cannot access from a C# user control the
DOM of the HTML in which the control is hosted)


Can someone comment the above 3 point? Are they correct?


questions:

Why Microsoft dropped it from the .Net2 Framework?

Which are the implication redistribuiting the Microsoft.mshtml with a .NET 2
applications?

Is it only a metter of distribuiting the file (8 MB) with my application? Or
is there anything else?


Many Thanks,

FILIPPO
 
D

Dmytro Lapshyn [MVP]

Hi,
Why Microsoft dropped it from the .Net2 Framework?

I am pretty sure Microsoft.mshtml has never been a part of .NET Framework.
Do you have any references that make you think otherwise?
Which are the implication redistribuiting the Microsoft.mshtml with a .NET
2
applications?

I believe you cannot redistribute mshtml.dll alone - this is just not
permitted to do so from the licensing standpoint. As far as I remember, it
is a part of Internet Explorer, and you should require your users to have an
appropriate version of IE installed. On the other hand, .NET Framework
itself requires IE 5 or higher so unless you use something really advanced
available only in IE6 or IE7, you should be on the safe side here.
 
D

Dmytro Lapshyn [MVP]

Now that I saw your original post with the detailed description of the
problem with the hosted C# control, I believe I can finally explain what is
going wrong in your scenario!

You are using the following code snippet in your C# control:

<code>
private System.Windows.Forms.HtmlDocument DocVal;

public System.Windows.Forms.HtmlDocument Doc
{
get { return DocVal; }
set
{
DocVal = value;
}
}
</code>

This means that you expect the host (namely, IE) - to be more specific, the
JavaScript "loadDoc" function on the HTML page that contains your control,
to pass you an instance of System.Windows.Forms.HtmlDocument. But this is
plainly impossible - the JavaScript code knows nothing about the
HtmlDocument .NET wrapper! Yes, this is a wrapper - MSDN for VS 2005 reads
"HtmlDocument is a wrapper for the Internet Explorer Document Object Model
(DOM), which is written in COM.".

The "document" object you are passing is a COM object - namely
"mshtml.IHTMLDocument2", so the Doc property should be of exactly the same
type (if "mshtml.HTMLDocument" works for you too, feel free to use it).

Now, Microsoft hasn't "dropped" mshtml.HTMLDocument from the Framework.
Again, I refer to MSDN:

"To use the unmanaged interfaces, import the MSHTML library (mshtml.dll)
into your application. However, you can also execute unexposed properties
and methods using the IDispatch::Invoke method.". So feel free to use the
tlbimp.exe utility to create an interop assembly for mshtml.dll and
reference the resultant interop assembly from your project.

Well, the explanation above is indeed somewhat vague, feel free to follow up
with more requests for clarification.
 
G

Guest

Hi,

thanks for your help.

what you said is correct and as i said if i use:

private mshtml.HTMLDocument DocVal;

public mshtml.HTMLDocument Doc
{
get { return DocVal; }
set
{
DocVal = value;
}
}

it works fine!!!

About you comments:

1)
Now, Microsoft hasn't "dropped" mshtml.HTMLDocument from the Framework.
I am pretty sure Microsoft.mshtml has never been a part of .NET Framework.
Do you have any references that make you think otherwise?

Well.... when you add the reference Microsoft.mshtml the version is
7...something... typically VS 2003 instead VS 2005 is version 8 most of
the componet point to that.

But I guess you are right, saying that naver has been part of the framework.

2)
if System.Windows.Forms.HtmlDocument is just a rapper,
what is the sense to provide that rapper without the real componet?

3)
I assume that for achiving what i want without the interop is not possible
then?



many thanks for your reply,
FILIPPO
 
D

Dmytro Lapshyn [MVP]

Well.... when you add the reference Microsoft.mshtml the version is
7...something... typically VS 2003 instead VS 2005 is version 8 most of
the componet point to that.

But I guess you are right, saying that naver has been part of the
framework.

On my machine (WinXP SP2, IE 6, .NET 1.1 and .NET 2.0) the version of
mshtml.dll is 6.0.2900.2802.
You probably have 7.* because you have IE 7 beta 2.

Also note that the framework DLL versions are 1.1.* for .NET 1.1 and 2.0.*
for .NET 2.0, not to be mixed up with _Visual Studio DLLs_ which are indeed
7.1.* or even 8.0.* for VS 2005.
2)
if System.Windows.Forms.HtmlDocument is just a rapper,
what is the sense to provide that rapper without the real componet?

The real component is mshtml.dll which is a part of IE. Since .NET Framework
requires IE 5 (if not IE 5.5) to be installed, you apparently cannot run a
..NET application without having mshtml.dll on the machine.
3)
I assume that for achiving what i want without the interop is not possible
then?

Definitely not possible (unless you want to use late binding, which I
wouldn't recommend because of the complexity of coding and performance
issues).

Actually Windows.Forms.HtmlDocument does the same interop for you behind the
scenes :) so you shouldn't worry about incurring interaction with unmanaged
code - you would have it anyway, but implicitly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top