我目前正在使用 MS HTML 将 JavaScript 代码插入网站。
我参考了 Microsoft HTML 对象库并键入了此代码。
IHTMLDocument2 doc = BrowserHost.Document as HTMLDocumentClass;
IHTMLElement head = (IHTMLElement)
((IHTMLElementCollection)doc.all.tags("head")).item(null, 0);
IHTMLScriptElement scriptObject =
(IHTMLScriptElement)doc.createElement("script");
scriptObject.type = @"text/javascript";
scriptObject.text = TTS.TTSWebFactory.GetJavascript();
((HTMLHeadElementClass)head).appendChild((IHTMLDOMNode)scriptObject);
我在脚本的最后一行收到错误消息,这是消息。
Unable to cast COM object of type 'System._ComObject' to class type
'mshtml.HTMLHeadElementClass'. COM components that enter the CLR and do not
support IProvideClassInfo or that do not havae any iterop assembly registered
will be wrapped in the _ComObject type. Instances of this type cannot be cast
to any other class; however they can be cast to interfaces as long as the
underlying COM component supports QueryInterface calls for the IID of the
interface
我对 COM 没有太多经验,将最后一行保留在他的代码中很重要,任何人都可以帮助我理解这意味着什么以及我如何解决它?