简体   繁体   中英

How can I use IHTMLDocument6 or other IE 8 interfaces from C#?

I'm trying to access the IHTMLDocument6.documentMode property from my IE BHO, but that interface is not defined in any of the mshtml assemblies I can find on my machine.

I've tried hacking together an interface definition for the interface:

[Guid("30510417-98b5-11cf-bb82-00aa00bdce0b")]
[TypeLibType(4160)]
public interface IHTMLDocument6
{
    [DispId(1104)]
    float documentMode { get; }
}

I can successfully cast the document object to this interface, but I do not get a value that makes sense for the documentMode property.

Where can I find the version of mshtml that includes the IHTMLDocument6 interface, or a correct version of the interface definition to use? Or is there some other way I should be doing this?

Thanks.

You can always use latebinding and do a Type.Invokemember

http://msdn.microsoft.com/en-us/library/66btctbe.aspx

You can get Headers and Libs for IE9 from here . If that link becomes broken, I got it from here .

You can get interop examples from pinvoke.net . It seems pretty thin on MSHTML, but you can add to it once you get it figured out.

This is the correct code to use

[Guid("30510417-98b5-11cf-bb82-00aa00bdce0b")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
public interface IHTMLDocument6
{
    [DispId(1104)]
    object documentMode { get; }
}

A VARIANT is an object in P/Invoke. The above also uses IDispatch which minimizes fuss.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM