Wednesday, 31 October 2012

Filled Under:
,

C# Tutorials : How to make a COM DLL in C#.net

Yesterday I was working on a C# & .net solution. The solution was quite big and so many projects inlcuded in it. Some of these projects require a COM DLL as a reference. I was working on a machine, where the solution was getting built successfully, then for some reason I moved all code to some other machine. However this time when I rebuilt the Solution on new machine, I got so many errors only related to COM DLL.

Here is the error –

"A reference to '[DLL_NAME]' could not be loaded. Please make sure that the file is accessible, and that it is a valid assembly or COM component."

Initially I struggled to understand what is the error and how to resolve it?. The interesting part is quite a long time back almost 4 years ago I created a COM dll and now I forgot the steps to make a com object.
How to create a Com DLL in C#.Net
How to create a Com DLL in C#.Net
However, it didn't take much time for me to fix the issue. But it just clicked in my mind to write up a step by step article on how to create a COM object DLL for my some those friends who are still struggling to create a COM dll in c#.

It is not a big task to make a com dll in c#. In this article we are going to discuss about the steps required to create a com object in c#.

Steps to create a COM dll in C#

Follow below steps to create a com dll -
  1. The first step is to open a command prompt. You will need to type "cmd" in run box and hit enter button.
    Command Prompt to make com dll
    Command Prompt to make com dll
  2. "TlbImp.exe" is an executable file which you need to create a com object from existing valid type library dll.
    1. If you are working on VS-2010 then follow the steps –
      1. If a machine is 32 bit where you are making your COM dll then go to following location in opened command prompt –

        %ProgramFiles%\Microsoft SDKs\Windows\v7.0A\bin
      2. If a machine is 64 bit then go to following location in command prompt –

        %ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.0A\bin
    2. VS-2005 users follow the steps –
      1. 32 bit users, go to following location -

        %ProgramFiles%\Microsoft Visual Studio 8\SDK\v2.0\Bin
      2. 64 bit users, go to following location –

        %ProgramFiles(x86)%\Microsoft Visual Studio 8\SDK\v2.0\Bin
  3. Now type following command in command prompt and hit enter as shown -

    TlbImp.exe fully_qualified_path_of_your_dll
    Tlbimp.exe - to make com DLL
    Tlbimp.exe - to make com DLL
  4. If a dll is valid type library then the above command will create a successful COM dll object in location from where you are executing "tlbimp.exe" with the same dll name.
  5. Copy this newly created valid COM object to your project reference location and build the solution. The error will not appear again..
How to make a com dll we learned from this article. If you find this article helpful, then could you please share the article on your social network?

Following articles might be of your interest...

Protected by Copyscape Plagiarism Check

Sharing is Caring...





0 comments:

Post a Comment