5,696,038 members and growing! (18,937 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » COM / COM+ » COM Interop     Intermediate License: The Code Project Open License (CPOL)

Registering COM DLL with VS 2005 Walk-Through

By VB Rocks

This article demonstrates how to Register a COM DLL with Visual Studio 2005
VB (VB 8.0, VB 9.0, VB), COM

Posted: 18 Aug 2008
Updated: 18 Aug 2008
Views: 4,982
Bookmarked: 9 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
8 votes for this Article.
Popularity: 3.01 Rating: 3.33 out of 5
1 vote, 12.5%
1
2 votes, 25.0%
2
0 votes, 0.0%
3
0 votes, 0.0%
4
5 votes, 62.5%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Download MyComDll.zip - 391.71 KB

Introduction

In my previous article "Creating COM DLL with VS 2005 Walk-Through", we walked-through creating a COM DLL with Visual Studio 2005, using Visual Basic.NET.

In this article, we are going to walk-through registering our COM DLL.

Background

If your an experienced developer, and you've worked with DLL's before, you've probably already tried using RegSvr32, and have experienced some difficulties. If you're an experienced .NET developer, you may have tried using RegAsm, and have encountered some challenges there as well.

In this article, we are not going to look at the more complex approaches of registering a COM DLL. Instead, we are going to walk-through creating a VS 2005 Installer, which will both install and register our COM DLL for us, while providing a simple, professional tool to accomplish this task.

As a professional software developer, and an experienced COM DLL developer, I personally prefer using an Installer. Additionally, my clients appreciate it, because whenever they need to install a COM DLL, they are able to.

Creating the Setup Project

If you followed along with my previous article "Creating COM DLL with VS 2005 Walk-Through", then open that project now. If you did not follow my previous article, but have your own COM DLL that you have created, then open the project that contains that COM DLL now.

To begin with, let's add a new "Setup and Deployment" project to our solution:

  • Click on the File menu | Add | New Project...
  • In the Add New Project window, make the following selections:
    • Under "Project types":
      • Click the plus (+) sign next to "Other Project Types" to expand it.
      • Click on "Setup and Deployment" to select it.
    • Under "Templates"
      • Click "Setup Project" to select it
    • Change the Name to "Library Installer"
    • Click the OK button when finished.

The Add New Project window:
AddNewProject.jpg

Now that the new "Library Installer" setup project has been added to the Solution, your Solution Explorer should look like the picture below. If Solution Explorer is not open, then open it by clicking on View menu | Solution Explorer.
SolutionExplorer.jpg

Configure Installer Properties

Now that we have the installer added to the solution, let's configure it's properties.

  • In Solution Explorer, left-click on the installer ("Library Installer") to select it.
  • Now go to the Properties Window (F4 or View menu | Properties Window)
  • Set the following properties in the Properties window:
    • Author: set this to your name.
    • InstallAllUsers: set this to True.
    • Manufacturer: set this to "Common Files".
    • ProductName: set this to "My Libraries".
    • Title: set this to "Library Installer".

Here's the Properties Window:
LibraryInstallerProperties4.jpg

Add Project Output to Installer

The next thing we need to do is add the files that we want to the installer to install, which in this case is our COM DLL. The installer will not only install our COM DLL, but it will take care of registering it for us as well!

First, make sure your "File System" tab is visible. If it's not, follow these steps:

  • Go to Solution Explorer (View menu | Solution Explorer)
  • Right-Click on the installer project ("Library Installer") menu | View | File System

Next, Configure the File System:

  • Add the "Program Files Folder": In the pane on the left, right-click on "File System on Target Machine" | Add Special Folder | Program Files Folder

AddProgramFilesFolder.gif

  • Add a "Common Files" folder: Right-Click on the "Program Files Folder" that we just added, select Add | Folder from the popup menu.
    • Rename the folder to "Common Files"

AddFolder.jpg

  • Add a "My Libraries" folder: Right-Click on the "Common Files" folder we just created, select Add | Folder from the popup menu.
    • Rename the folder "My Libraries".

When you've added all of the folders, the File System should look like this:
MyLibrariesFolder.gif

Just a brief explanation: What we are doing is, we are telling the installer to install our COM DLL in the following location: C:\Program Files\Common Files\My Libraries.

  • Add our COM DLL:
    • Click on the "My Libraries" folder to select it.
    • In the pane on the right, Right-Click to bring up the popup menu, select Add | Project Output.

AddProjectOutputMenu.jpg

      • The "Add Project Output Group" window will open.
      • Select Project: "MyComDll"
      • Select "Primary Output"
      • Select Configuration: "(Active)"
      • Click the OK button when you are finished.

AddProjectOutputGroup.jpg

When you're finished, it should look like this:
MyLibrariesFolderWithTlb.jpg

Finally Save and Build both projects.

  • View Solution Explorer (View menu | Solution Explorer)
  • Right-Click on the installer ("Library Installer")
    • Select Build from the popup menu.

BuildInstaller.jpg

Run the Installer from within Visual Studio

We have finished our installer! Now we are ready to test it out!

  • In Solution Explorer, Right-Click on the installer ("Library Installer")
    • Select "Install" from the popup menu.

InstallInstaller.jpg

When you run the Installer, observe the following:

  • On the "Select Installation Folder" window:
    • The installation path is: C:\Program Files\Common Files\My Libraries\
    • "Everyone" is selected.

installer.jpg

Using our registered COM DLL in VB6

We now have a registered COM DLL ready to be used in VB6. Let's go into VB6 and see how to use it.

Create a new VB6 Project:

  • Start VB6
  • When the "New Project" window opens, select "Standard Exe".
  • Click the "Open" button.
  • Add a Button to the Form, and double-click it to create the Click() event, and open the code window.

Add a reference to our COM DLL:

  • Click the Project menu | References.
  • Click the "Browse" button to open the "Add Reference" window.
  • Navigate to the "My Libraries" folder ("C:\Program Files\Common Files\My Libraries").
  • Select the "MyComDll.tlb" file (Notice the ".tlb" - not ".dll")
  • Click the "Open" button to close the "Add Reference" window.
  • Click the "OK" button to close the "References" window and add our COM DLL as a reference.

Finally, in the Click() event for our Command Button, add code to utilize our COM DLL:

Private Sub Command1_Click()

    Dim mcc As New MyComClass
    mcc.DisplayMessage
        
End Sub
  • Run the VB6 application (F8, or Debug menu | Step Into)
  • Click the button on the form.

Here's the results of our test:

VB6Test.jpg

Conclusion

As you can see, creating a Setup project to install and register your COM DLL is very easy with VS 2005! Additionally, it is very easy for anyone to use, and looks very professional!

I hope this article is helpful to you!

VBRocks
2008 MS Visual Basic MVP

http://www.visualbasicrocks.com/

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

VB Rocks



Occupation: Software Developer
Company: VisualBasicRocks.com
Location: United States United States

Other popular COM / COM+ articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 2 of 2 (Total in Forum: 2) (Refresh)FirstPrevNext
GeneralKnow bug in VS2005 & VS2008 [modified]memberJamie Clayton14:22 25 Aug '08  
GeneralVery Nicememberianhunt0120:52 18 Aug '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 18 Aug 2008
Editor:
Copyright 2008 by VB Rocks
Everything else Copyright © CodeProject, 1999-2008
Web15 | Advertise on the Code Project