How to use third party DLL in your project

Let me use my published DLL as third party dll first then another one from Microsoft Outlook. My Active Directory Managing Utility DLL can be downloaded from the Downloads section free.

After you downloaded my .zip file, unpack it and you’ll have 3 files: the DLL and the info files. Keep in mind: you should have a folder containing all your 3rd party DLL files. After importing them as reference they still should be in that folder, so Visual Studio can work from there.

Right click on References under your project and select Add Reference…

In the upcoming window select Browse on the left and browse for the previously unpacked dll file. After selecting it the DLL name should appear under References:

Before you start working with the newly imported DLL, you can browse its methods by right clicking on the reference and selecting View in Object Browser. Opening the namespace you’ll see the classes on the left side. Selecting a class you’ll see all the available methods and selecting one of them you’ll get all the descriptions (if you didn’t delete the info files placed next to the DLL).

Click on the following image to see it in greater size:

Object Browser

If the DLL file you want to use is well-descriptioned, the usage will be easy. In this case add the namespace (ActiveDirectory) to your form:

using ActiveDirectory;

Then you can start using it. Let’s check an active directory user’s email address. As you start using the methods, every description will arrive in time for every property:

As this method has a return type of string, the complete WhatIsTheEmailAddress() method should look something like this:

private void WhatIsTheEmailAddress()
            string email = UserInformation.GetEmailForUser("DC=office,DC=csharp-tutorial,DC=hu", "first.user");

…and so on.

Let’s see the Microsoft’s Outlook DLL file and let’s create a new Outlook mail window.

This DLL can be accessed natively from Visual Studio if you have installed Office. If you don’t have installed Office, no problem: get this very DLL from the Internet and browse for that as reference.

Add a new reference and now select the COM tab:

Select Microsoft Outlook 15.0 Object Library (or 14.0, 16.0: depending on your installed Office version). Then you’ll have 2 new references: Microsoft.Office.Core and Microsoft.Office.Interop.Outlook. Add both references as a new namespace to your project:

using Microsoft.Office.Core;
using Microsoft.Office.Interop.Outlook;

Now create a new method that opens an Outlook window:

private void NewMail()
            Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook._MailItem oMailItem = (Microsoft.Office.Interop.Outlook._MailItem) oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
            oMailItem.To = "";
            //from, subject, body, etc...

Not that difficult?! 🙂