我目前正在使用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太多的經驗,並保持最後一行詮釋他的代碼是很重要的,任何一個可以幫助我理解這意味着什麼,我該如何解決呢?