command-linecompiler-constructioncomreferencevbc

How to reference COM lib like shdocvw using vbc commandline compiler (no IDE)?


The basis of this question comes from this tutorial on support.microsoft.com: http://support.microsoft.com/kb/176792

To run the following code, it is necessary to add a reference to
"Microsoft Internet Controls" (Shdocvw.dll) and "Microsoft HTML Object
Library" (Mshtml.dll) to the Visual Basic project:
Dim SWs As New SHDocVw.ShellWindows 
Dim IE As SHDocVw.InternetExplorer

This works fine in Visual Studio 2010, but it seems to rely on some behind-the-scenes magic that I can't duplicate using the straight commandline vbc compiler.

Obviously there is no "Add Reference" dialog for the commandline compiler. I naively tried adding:

/reference:"C:\windows\system32\shdocvw.dll"

to the commandline, but that didn't help. In both cases, I get:

error BC30002: Type 'SHDocVw.ShellWindows' is not defined.

error BC30002: Type 'SHDocVw.InternetExplorer' is not defined.

I've successfully used shdocvw.dll, AKA Shell.Application, from other languages like vbscript and autohotkey, but I currently have too little understanding of VB.NET to know whether I'm just doing it wrong or it's not possible.


Solution

  • You will have to run the Tlbimp.exe utility first. That's the tool that generates the interop library from the type library embedded in shdocvw.dll, normally done automatically when you add the reference in the IDE. It produces interop.shdocvw.dll, the one you need to pass with the /reference option.