Home » Visual Basic.NET

DLLs in Visual Basic.NET

3 June 2003 12,806 views No Comment

Visual Basic.NET is a fantastic environment for producing software quickly and easily, but as a programmer, one quickly comes across tasks that are not supported directly by the VB.NET environment.

Help is at hand however; as by calling Windows dlls directly from VB.NET, it allows you to use all those handy routines that get down into the guts of the operating system. For example, accessing the Windows shell environment within Visual Basic is impossible without calling external dll routines, but by doing so it allows you to use dialog boxes and other elements that are already familiar to the users of your software.

Unfortunately, a lack of documentation provided with VB.NET to explain how to call dlls from your project makes this a difficult task for beginners. A method known as marshalling that is occasionally needed, only adds to the confusion. I believe the best way to learn about using dlls is to learn by example, so we’ll start off with one of the most commonly needed functions.

Shell Execute

Shell Execute is a handy function that causes Windows to open files, folders, and even URLs. The great thing about it is that once you have told it what you want to open, the operating system decides which program to use based on the default settings. So for example, if you pass it a URL, it will automatically open it in your default browser.

The entry for Shell Execute in the documentation prototypes the function as follows:

   HINSTANCE ShellExecute(
       HWND hwnd, 
       LPCTSTR lpOperation,
       LPCTSTR lpFile, 
       LPCTSTR lpParameters, 
       LPCTSTR lpDirectory,
       INT nShowCmd

On the next page, I’ll show you how to write a declaration that will allow you to call this useful function.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.