How to add a reference to mshtml version 9 in .NET

北城余情 提交于 2019-12-01 01:35:23

问题


I want to use some of the new features of mshtml.dll version 9.0 such as IHTMLCSSRule.

The interop version in the following folder is version 7.0.3300.1:

C:\Program Files\Microsoft.NET\Primary Interop Assemblies\Microsoft.mshtml.dll

The COM version in the following folder is version 9.0.8112.16441:

C:\Windows\System32\mshtml.dll

From what I could ascertain from the web, I should do this to create a .NET interop version 9:

d:\zTemp>tlbimp mshtml.tlb /out:Microsoft.mshtml.dll /namespace:mshtml /asmversi on:9.0

This seems to have worked but generated the following warnings:

TlbImp : warning TI3001 : Primary interop assembly 'Microsoft.mshtml, Version=7. 0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is already registere d for type library 'C:\Windows\system32\mshtml.tlb'. TlbImp

: warning TI3016 : The type library importer could not convert the signature for the member 'mshtml._userBITMAP.pBuffer'. TlbImp :

warning TI3016 : The type library importer could not convert the signature for the member 'mshtml._FLAGGED_BYTE_BLOB.abData'. TlbImp :

warning TI3015 : At least one of the arguments for 'mshtml.ICanvasPixel ArrayData.GetBufferPointer' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to m anipulate. TlbImp : Type library imported to d:\zTemp\Microsoft.mshtml.dll

  1. Can these warnings be safely ignored?
  2. Is there no precompiled version of this dll available for download from the microsoft site?
  3. Is it ok for me to distribute this dll with my app?
  4. When adding a reference to the dll to a .NET 3.5 project I was given the following warning:

'Microsoft.mshtml.dll', or one of its dependencies requires a later version of the .Net Framework than the one specified in the project ...

Since it was a warning and let me add the reference any way, can I still use certain features of the .dll in .NET 3.5?

Thanks


回答1:


These are the hazards of COM versioning, aka DLL Hell. The PIA you have installed in the GAC is the lowest common denominator, it makes your code work with any version of IE 6 and later. Your approach is otherwise sound. The warnings are real, you can't use the flagged members from a scripting language or any other client that relies on COM automation. You stay out of trouble by simply not using them, not difficult.

You got the error when you added the reference because you used the wrong version of Tlbimp.exe. Probably the .NET 4 version, judging from the error message. The 3.5 compatible version is located in c:\program files\microsoft sdks\windows\v6.0a\bin. Otherwise the one you'll get when you use the VS2008 Command Prompt. Verify by typing where tlbimp.exe at the command prompt.

Some odds that you'll get the PIA loaded instead of your custom interop assembly. Not sure, you can tell from Fuslogvw.exe, configured to log all bindings. Your /asmversion should avoid it. Best to create a completely bogus version number so it can never match a PIA version, like 1.0.0.0

And, of course, your program won't work on the user's machine when it doesn't have IE9 installed.



来源:https://stackoverflow.com/questions/9533824/how-to-add-a-reference-to-mshtml-version-9-in-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!