3

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.

amonroejj
  • 573
  • 4
  • 16
  • For reference, there's a build window that shows the commands the IDE runs. Add the references to a project in VS, build, and see what the command line it generates looks like. :P – cHao Feb 26 '13 at 20:58
  • Among other things, it "/link"s to Interop.SHDocVw.dll, which is some of the magic I referred to above :) I wouldn't have this dll in a bare folder with just my .vb source, in the commandline-only scenario. – amonroejj Feb 26 '13 at 21:43

1 Answers1

2

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.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Indeed, I tried this and it worked. I am morbidly curious why tlbimp.exe isn't included in C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319 alongside vbc.exe, though. I found a copy in C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin. – amonroejj Feb 27 '13 at 16:14
  • It is a build tool that's only useful to a programmer. And therefore lives in the SDK directory. – Hans Passant Feb 27 '13 at 16:16
  • One might say the same about vbc.exe itself :) – amonroejj Feb 27 '13 at 17:59
  • No, compiling vb.net code is a .NET framework feature. System.CodeDom namespace and VBCodeProvider class. Same for C#, although it gets used more often. Routinely, like in XML serialization. – Hans Passant Feb 27 '13 at 18:03