分配mshtml.HTMLDocument.frames时,c#指定的强制转换无效

时间:2013-10-04 11:34:14

标签: c# bho mshtml shdocvw

我正在开发一个IE BHO,在访问html文档中的帧时我遇到了这个错误

这是代码。

foreach (SHDocVw.InternetExplorer objExplorer in objShellWins)
{
   if (objExplorer.Document is HTMLDocument)
   {
      objDocument = (mshtml.HTMLDocument)objExplorer.Document;
      mshtml.HTMLDocument doc = (mshtml.HTMLDocument)objExplorer.Document;
      mshtml.FramesCollection frames = (mshtml.FramesCollection)doc.frames;  //Exception at this line
   }
}

这里有什么问题?

1 个答案:

答案 0 :(得分:2)

好的人我通过在函数调用

设置[STAThread]来解决问题