我目前正在使用MS HTML将JavaScript代码插入网站。MSHTML HTMLHeadElementClass COM错误
我提到了Microsoft HTML Object Library并输入了这段代码。
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太多的经验,并保持最后一行诠释他的代码是很重要的,任何一个可以帮助我理解这意味着什么,我该如何解决呢?