title: InternetExplorer being set up as __ComObject instead of SHDocVw.InternetExplorer
body: <p>I'm having a problem with the InternetExplorer in SHDocVw.dll. I also have mshtml.tlb referenced (while googling, I did read 1 comment that said I should have mshtml.dll referenced, but that this couldn't be done in <i>Microsoft Visual Studio Express</i>, I don't know how true this is though). Here's one small function in its most basic form that won't work for me:</p>
  
  <pre><code>public static HtmlElement GetDocumentControlByID(
      ref SHDocVw.InternetExplorer IEObj, 
      string ControlID)
  {
      HtmlElement ReturnElement = IEObj.Document.GetElementById(ControlID);
      return ReturnElement;
  }
  </code></pre>
  
  <p>The problem is that when I create the IEObj instance, it is considered type <code>System.__ComObject</code> instead of <code>SHDocVw.InternetExplorer</code>, and all subparts are also of type <code>System.__ComObject</code>. When I try any of the following statements...</p>
  
  <pre><code>Document WebDoc = IEObj.Document;
  HtmlElement ReturnElement = IEObj.Document.GetElementById(ControlID);
  </code></pre>
  
  <p>...I keep getting the same error message:</p>
  
  <blockquote>
    <p>Cannot implicitly convert type 'System.__ComObject' to 'System.Windows.Forms.HtmlElement'
    (obviously the convert-to type is different for the <code>IEObj.Document</code>).</p>
  </blockquote>
  
  <p>I am new to c# (coming from VBA, so I am familiar with programming), but in VBA, the equivelant works perfectly without needing to convert it in any way.</p>
  
  <p>Is it something I'm doing wrong? In case it's my creation of the object, the following is (roughly) the code I used to test the function:</p>
  
  <pre><code>public static void Main(String [] args)
  {
      SHDocVw.InternetExplorer IEObj = new SHDocVw.InternetExplorer();
      IEObj.Navigate("http://sports.ladbrokes.com/");
      while (IEObj.ReadyState != 4)
      {
  
      }
  
      // There is a textbox that definitely exists
  
      HtmlElement NetControl = GetDocumentControlByID(ref IEObj, "username");
  
      // I was goint to manipulate it after this, but it crashes in the above function.
  
  }
  </code></pre>
  
  <p>All I really want to do is latch onto various elements so that I can enter text into textboxes, click buttons etc. I would also need to be able to use the Document variables as well (like <i>Document.Body.InnerHtml</i>, etc). The whole project is to be a bunch of functions to be contained in a DLL to be referenced by other projects.</p>