-
March 11th, 2012, 09:01 AM
#1
How to add reference to Microsoft HTML Object Library?
Okay normally this was easy to do, but now with IE9 Visual Studio 2010 hangs and crashes. The problem seems to be even worse because you can't build an Interop.mshtml.dll to match version 9. I've tried using the VS command prompt with no luck. Allegedly this is how it is done, but there are no known examples that actually work. If anyone has done this with success please enlighten us with explicit details!
-
March 12th, 2012, 05:50 AM
#2
Re: How to add reference to Microsoft HTML Object Library?
OK, one question... Which Interop.mshtml.dll did you add? Meaning, did you browse to the one inside
C:\Program Files\Microsoft.NET\Primary Interop Assemblies
?
-
March 12th, 2012, 07:12 PM
#3
Re: How to add reference to Microsoft HTML Object Library?
Yes, I did look there but it was not present. Even after taking the steps to make it present, the version was still 7. ie, Microsoft.mshtml.dll.
I did finally get it working and here is how.
1. Downloaded VS 2010 ultimate trial, which does not crash when adding the reference, unlike VS express products.
2. Still needed to create the interop dll, so that it actually matches as version 9, and not 7. I ended up making a bat file as follows to create the interop.mshtml.dll.
Code:
call "%VS100COMNTOOLS%\vsvars32.bat"
set SRCTLB=mshtml.tlb
set NAMESPACE=mshtml9
REM Should update this automatically:
set VERSION=9.0.8112.16434
set PREFIX=Interop
REM Only need to run once for the strong name
sn -k %NAMESPACE%.snk
REM Claim that /sysarray avoids crashes:
REM http://stackoverflow.com/questions/714952/referencing-a-com-assembly-in-visual-studio-vs-converting-a-com-assembly-via-tlbi/718714#718714
REM tlbimp (for regular COM controls)
TlbImp.exe /verbose /out:%PREFIX%.%NAMESPACE%.dll /keyfile:%NAMESPACE%.snk /namespace:%NAMESPACE% /transform:dispret /asmversion:%VERSION% /tlbreference:%SYSTEMROOT%\System32\stdole2.tlb %SYSTEMROOT%\System32\%SRCTLB%
Put the above code into a notepad text, and save as .bat.
Double click it to execute, and it will create an Interop.mshtml.dll in the same folder as the bat file is located.
This can now be referenced as version 9! Remember that there are differences that may cause any older code to crash if it were based upon an earlier version. For example obtaining the type of document, will now crash even though the exception should be caught below.
Code:
Dim SWs As New SHDocVw.ShellWindows
For Each IEx As SHDocVw.InternetExplorer In SWs
Try
If IEx.Type = "HTML Document" Then
Dim wfd As HTMLDocument
wfd = DirectCast(IEx.Document, HTMLDocument)
If wfd.hasFocus = True Then Return IEx
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Next
Hope this helps someone hours, if not days of confusion!!!
-
March 13th, 2012, 06:28 AM
#4
Re: How to add reference to Microsoft HTML Object Library?
I wish I had your brains, or even just half of it!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|